Documentation
¶
Index ¶
- type AdvancedJob
- type AdvancedJobConstructor
- type Config
- type JobHandler
- type JobRecord
- type JobStatus
- type LogEvent
- type Manager
- type Operation
- type TaskFlow
- func (tf *TaskFlow) CreateJob(ctx context.Context, operation Operation, payload any, executeAt time.Time) (int64, error)
- func (tf *TaskFlow) RegisterAdvancedHandler(op Operation, constructor func() AdvancedJob)
- func (tf *TaskFlow) RegisterHandler(op Operation, handler JobHandler)
- func (tf *TaskFlow) Shutdown(timeout time.Duration)
- func (tf *TaskFlow) StartWorkers(ctx context.Context, count int)
- type Worker
- type WorkerStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdvancedJob ¶
type AdvancedJob interface { Run(jr JobRecord) (any, error) RetryCount() uint // returns how many times we allow this job to fail BackoffTime() time.Duration // how long to wait after a failure JobTimeout() time.Duration // how long this job may run before timing out }
AdvancedJob Job is the interface each job must implement.
type AdvancedJobConstructor ¶
type AdvancedJobConstructor func() (AdvancedJob, error)
type Config ¶
type Config struct { // DB is the user-provided database connection where the jobs table is stored. DB *sql.DB // DbName is name of the database. DbName string // RetryCount is how many times we allow a job to fail before ignoring it. RetryCount uint // BackoffTime is how long we wait before letting a failed job become available again. BackoffTime time.Duration // PollInterval is how frequently workers check for new jobs. PollInterval time.Duration // JobTimeout is how long we allow an individual job to run before marking it as failed. // If zero, there is no enforced timeout. JobTimeout time.Duration // InfoLog is called for informational or success logs. // If nil, defaults to printing to stdout. InfoLog func(ev LogEvent) // ErrorLog is called for error logs. // If nil, defaults to printing to stderr (or stdout). ErrorLog func(ev LogEvent) }
Config holds the settings and resources needed by the queue system.
type JobHandler ¶
JobHandler is a function that receives the payload string, constructs and runs the job, and returns an optional output string plus an error.
type JobRecord ¶
type JobRecord struct { ID uint64 Operation Operation Status JobStatus Output any LockedBy *string LockedUntil *time.Time RetryCount uint AvailableAt *time.Time CreatedAt time.Time UpdatedAt time.Time // contains filtered or unexported fields }
JobRecord corresponds to one row in the jobs table.
func (*JobRecord) GetPayload ¶
type LogEvent ¶
type LogEvent struct { // A human-readable message about the event. Message string // The ID of the worker that triggered the log (if any). WorkerID string // The Job ID, if available. JobID *uint64 // The operation name, if available. Operation *string // Any error associated with the event. Err error // How long the job or operation took, if relevant. Duration *time.Duration }
LogEvent captures information about a logging event.
type Operation ¶
type Operation string
Operation is a type for your job "name" or "action" (e.g., "ADD_CUSTOMER").
type TaskFlow ¶
type TaskFlow struct {
// contains filtered or unexported fields
}
func (*TaskFlow) CreateJob ¶
func (tf *TaskFlow) CreateJob(ctx context.Context, operation Operation, payload any, executeAt time.Time) (int64, error)
CreateJob inserts a new job into the database
func (*TaskFlow) RegisterAdvancedHandler ¶
func (tf *TaskFlow) RegisterAdvancedHandler(op Operation, constructor func() AdvancedJob)
func (*TaskFlow) RegisterHandler ¶
func (tf *TaskFlow) RegisterHandler(op Operation, handler JobHandler)
RegisterHandler allows end users to associate an Operation with a JobHandler.
type WorkerStatus ¶
type WorkerStatus int
const ( WorkerIdle WorkerStatus = iota WorkerBusy WorkerFailing WorkerExecFailed )
Click to show internal directories.
Click to hide internal directories.