Documentation
¶
Index ¶
- func Init()
- func InitWithOptions(options SetupConfig)
- func PostgresBackend(url string) *postgresBackend
- func RegisterHandlers(jobType string, handlers ...handler)
- func WorkOn(job Job)
- type Backend
- type GenericJob
- type GenericTimedJob
- type Job
- type JobOptions
- type JobPool
- type Poller
- type RetryOptions
- type SetupConfig
- type TimedJob
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init()
Init sets up Jobman with default options namely - 5 workers, no poller, and no backend. TimedJob is disabled when jobman is initialized with default options. Sending timed jobs will cause a panic.
func InitWithOptions ¶
func InitWithOptions(options SetupConfig)
InitWithOptions sets up Jobman with custom options. If you provide a backend but no pooler then jobman will use the default poller, which polls the storage every minute.
func PostgresBackend ¶
func PostgresBackend(url string) *postgresBackend
func RegisterHandlers ¶ added in v0.2.0
func RegisterHandlers(jobType string, handlers ...handler)
RegisterHandlers registers a function that should be called when job of jobType needs to be processed.
Types ¶
type Backend ¶
type Backend interface { // Save job, return an error job could not be saved Save(ctx context.Context, job TimedJob) error // Find due jobs. FindDue(ctx context.Context) ([]TimedJob, error) // Mark a job as complete MarkComplete(ctx context.Context, job TimedJob) error }
Backend defines an interface for persisting jobs to an external persistent storage.
type GenericJob ¶
type GenericJob struct { JobType string `json:"job_type"` Data any `json:"data"` Opts *JobOptions `json:"opts"` }
func (GenericJob) Options ¶
func (job GenericJob) Options() JobOptions
func (GenericJob) Payload ¶
func (job GenericJob) Payload() any
func (GenericJob) Type ¶
func (job GenericJob) Type() string
type GenericTimedJob ¶
type GenericTimedJob struct { JobType string `json:"job_type"` Data any `json:"data"` // This should be JSON serializable if we intend to save this in DB Opts *JobOptions `json:"opts"` Id int `json:"id"` When time.Time `json:"when"` }
GenericTimedJob is a default job that shouldn't get handled immediately. We need to enforce persistence when dealing with Timed jobs, so It requires a way to mark it as complete.
func (GenericTimedJob) ID ¶
func (job GenericTimedJob) ID() any
func (GenericTimedJob) In ¶
func (job GenericTimedJob) In() time.Time
func (GenericTimedJob) MarkCompleted ¶
func (job GenericTimedJob) MarkCompleted() error
func (GenericTimedJob) Options ¶
func (job GenericTimedJob) Options() JobOptions
func (GenericTimedJob) Payload ¶
func (job GenericTimedJob) Payload() any
func (GenericTimedJob) Type ¶
func (job GenericTimedJob) Type() string
type Job ¶
type Job interface { // Retrieve job type Type() string // Retrieve Job data Payload() any Options() JobOptions }
Job defines a standard job interface with properties a job should have.
type JobOptions ¶
type JobOptions struct {
Retry bool `json:"retry"`
}
type Poller ¶
type Poller interface {
Poll(p JobPool)
}
Poller searches some job storage interface internal to it and forwards every job it finds to the job pool
type RetryOptions ¶
type RetryOptions struct{}
type SetupConfig ¶
type TimedJob ¶
type TimedJob interface { Job // When job should be worked on In() time.Time // Mark job as complete after it has been handled. Persistent jobs needs a way to be marked as complete MarkCompleted() error // Timed jobs require an identity. ID() any }
TimedJob is a job that shouldn't be worked on immediately. Only Timed jobs will be persisted in an external storage.