Documentation
¶
Index ¶
- Variables
- func RegisterWorker[T JobArgs](client *Client, worker Worker[T])
- type AttemptError
- type Client
- func (c *Client) GetJobDetails(id int32) (JobDetails, error)
- func (c *Client) InsertJob(db db.Handler, args JobArgs) error
- func (c *Client) InsertJobs(db db.Handler, args []JobArgs) error
- func (c *Client) ListJobs(only, exclude []JobStatus) ([]JobInfo, error)
- func (c *Client) Run(ctx context.Context) error
- func (c *Client) RunJob(ctx context.Context, id int32) error
- func (c *Client) Shutdown(ctx context.Context) error
- func (c *Client) Triage() (int, error)
- type Config
- type ErrJobBlocked
- type Job
- type JobArgs
- type JobDetails
- type JobInfo
- type JobStatus
- type Worker
- type WorkerDefaults
Constants ¶
This section is empty.
Variables ¶
var ErrJobNotFound = errors.New("job not found")
var ErrShutdown = errors.New("shutdown")
Functions ¶
func RegisterWorker ¶
RegisterWorker registers a Worker on the provided client. Each Worker must be registered so that the Client knows it should handle a specific kind of job (as returned by its `Kind()` method).
Note that RegisterWorker will panic if a worker of this kind is already registered for this Client
Types ¶
type AttemptError ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) GetJobDetails ¶
func (c *Client) GetJobDetails(id int32) (JobDetails, error)
type ErrJobBlocked ¶
type ErrJobBlocked struct {
// contains filtered or unexported fields
}
func (*ErrJobBlocked) Error ¶
func (e *ErrJobBlocked) Error() string
type JobDetails ¶
type JobDetails struct { JobInfo CreatedAt time.Time `json:"created_at"` ScheduledAt pgtype.Timestamptz `json:"scheduled_at"` Errors []AttemptError `json:"errors"` Dependents []JobInfo `json:"dependents"` Dependencies []JobInfo `json:"dependencies"` }
type Worker ¶
type Worker[T JobArgs] interface { // Timeout is the maximum amount of time the job is allowed to run before // its context is cancelled. A timeout of zero (the default) means the job // will inherit the Client-level timeout. A timeout of -1 means the job's // context will never time out. Timeout(job *Job[T]) time.Duration // Work performs the job and returns an error if the job failed. The context // will be configured with a timeout according to the worker settings and may // be cancelled for other reasons. // // If no error is returned, the job is assumed to have succeeded and will be // marked completed. // // It is important for any worker to respect context cancellation to enable // the client to respond to shutdown requests; there is no way to cancel a // running job that does not respect context cancellation, other than // terminating the process. Work(ctx context.Context, job *Job[T]) error }
Worker is an interface that can perform a job with args of type T. Workers must be registered with the client using the AddWorker function.
func WorkFunc ¶
WorkFunc wraps a function to implement the Worker interface. A job args struct implementing JobArgs will still be required to specify a Kind.
For example:
river.AddWorker(workers, river.WorkFunc(func(ctx context.Context, job *river.Job[WorkFuncArgs]) error { fmt.Printf("Message: %s", job.Args.Message) return nil }))
type WorkerDefaults ¶
type WorkerDefaults[T JobArgs] struct{}
WorkerDefaults is an empty struct that can be embedded in your worker struct to make it fulfill the Worker interface with default values.