domain

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2023 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoValidHandlerFound = errors.New("no_valid_handler_found")
	ErrInvalidPayload      = errors.New("invalid_payload")

	JobDataTypes = storage.NewDiscriminatedMapper[JobData]()
)

Functions

This section is empty.

Types

type Handler

type Handler interface {
	Prepare(any) (JobData, monad.Maybe[string], error) // Try to prepare a job payload and returns the JobData needed to process it and an eventual dedupe name to use
	Process(context.Context, Job) error
}

Represents an object which can handle a specific job.

type Job

type Job struct {
	event.Emitter
	// contains filtered or unexported fields
}

func JobFrom

func JobFrom(scanner storage.Scanner) (j Job, err error)

Recreates a job from a storage scanner

func NewJob

func NewJob(data JobData, dedupeName monad.Maybe[string]) (j Job)

Creates a new job which will be processed by a worker later on. A dedupe name can be provided to avoid multiple workers to process the same kind of job at the same time, such as a deployment for the same app and environment. If no dedupe name is given, the job id will be used instead.

func (Job) Data added in v1.1.0

func (j Job) Data() JobData

func (*Job) Done

func (j *Job) Done()

Mark a job as done.

func (*Job) Failed

func (j *Job) Failed(err error)

Mark the job has failed. It will be retried later on.

func (Job) ID

func (j Job) ID() JobID

type JobData added in v1.1.0

type JobData storage.Discriminated

type JobDone

type JobDone struct {
	ID JobID
}

type JobFailed

type JobFailed struct {
	ID      JobID
	ErrCode string
	RetryAt time.Time
}

type JobID

type JobID string

type JobQueued

type JobQueued struct {
	ID         JobID
	DedupeName string
	Data       JobData
	QueuedAt   time.Time
}

type JobsReader

type JobsReader interface {
	GetRunningJobs(context.Context) ([]Job, error)
	GetNextPendingJobs(context.Context, []string) ([]Job, error)
}

type JobsWriter

type JobsWriter interface {
	Write(context.Context, ...*Job) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL