golazy.dev
–
golazy.dev
/
lazyjobs
Index
|
Files
|
Directories
package lazyjobs ¶
import "golazy.dev/lazyjobs"
Constants ¶
const ControlJobsPath ¶
const ControlJobsPath = "/jobs"
const DefaultQueue ¶
const DefaultQueue = "default"
Variables ¶
var ErrNoWork ¶
var ErrNoWork = errors.New("lazyjobs: no work")
Functions ¶
func RegisterControlPlaneHandlers ¶
func RegisterControlPlaneHandlers(controlPlane *lazycontrolplane.ControlPlane, runner *JobRunner)
func RegisterLazyDevHandlers ¶
func RegisterLazyDevHandlers(controlPlane *lazycontrolplane.ControlPlane, runner *JobRunner)
func WithRunner ¶
func WithRunner(ctx context.Context, runner *JobRunner) context.Context
Types ¶
type Backend ¶
type Backend interface {
Insert(context.Context, InsertParams) (Record, error)
Claim(context.Context, ClaimParams) (Record, bool, error)
Complete(context.Context, int64) error
Retry(context.Context, RetryParams) error
Discard(context.Context, DiscardParams) error
List(context.Context, ListOptions) ([]Record, error)
Stats(context.Context) (Stats, error)
}
type BaseJob ¶
type BaseJob struct{}
func (BaseJob) JobMaxAttempts ¶
func (BaseJob) JobMaxAttempts() int
func (BaseJob) JobQueue ¶
func (BaseJob) JobQueue() string
func (BaseJob) JobRetryDelay ¶
func (BaseJob) JobRetryDelay(attempt int, _ error) time.Duration
type ClaimParams ¶
type ClaimParams struct {
Queues []string
Now time.Time
}
type Config ¶
type Config struct {
Backend Backend
Define func(*JobRunner)
Workers int
PollInterval time.Duration
Queues []string
}
type Definition ¶
type Definition struct {
Kind string `json:"kind"`
Type string `json:"type"`
Queue string `json:"queue"`
MaxAttempts int `json:"max_attempts"`
}
type DiscardParams ¶
type DiscardParams struct {
ID int64
LastError string
}
type InsertParams ¶
type InsertParams struct {
Kind string
Queue string
Payload json.RawMessage
MaxAttempts int
RunAt time.Time
}
type Job ¶
type Job interface {
Kind() string
Work(context.Context) error
}
type JobRunner ¶
type JobRunner struct {
// contains filtered or unexported fields
}
func New ¶
func New(config Config) (*JobRunner, error)
func RunnerFromContext ¶
func RunnerFromContext(ctx context.Context) (*JobRunner, bool)
func (r *JobRunner) Definitions ¶
func (r *JobRunner) Definitions() []Definition
func (r *JobRunner) Enqueue ¶
func (r *JobRunner) Enqueue(ctx context.Context, job Job) (Record, error)
func (r *JobRunner) EnqueueAt ¶
func (r *JobRunner) EnqueueAt(ctx context.Context, job Job, runAt time.Time) (Record, error)
func (r *JobRunner) EnqueueIn ¶
func (r *JobRunner) EnqueueIn(ctx context.Context, job Job, delay time.Duration) (Record, error)
func (r *JobRunner) MustRegister ¶
func (r *JobRunner) MustRegister(prototype Job)
func (r *JobRunner) Register ¶
func (r *JobRunner) Register(prototype Job) error
func (r *JobRunner) Running ¶
func (r *JobRunner) Running() bool
func (r *JobRunner) Snapshot ¶
func (r *JobRunner) Snapshot(ctx context.Context) (Snapshot, error)
func (r *JobRunner) Start ¶
func (r *JobRunner) Start(ctx context.Context)
func (r *JobRunner) Stop ¶
func (r *JobRunner) Stop(ctx context.Context) error
type ListOptions ¶
type ListOptions struct {
Limit int
}
type QueueNamer ¶
type QueueNamer interface {
JobQueue() string
}
type Record ¶
type Record struct {
ID int64 `json:"id"`
Kind string `json:"kind"`
Queue string `json:"queue"`
Payload json.RawMessage `json:"-"`
State State `json:"state"`
Attempt int `json:"attempt"`
MaxAttempts int `json:"max_attempts"`
RunAt time.Time `json:"run_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
LastError string `json:"last_error,omitempty"`
}
type RetryParams ¶
type RetryParams struct {
ID int64
RunAt time.Time
LastError string
}
type RetryPolicy ¶
type RetryPolicy interface {
JobMaxAttempts() int
JobRetryDelay(attempt int, err error) time.Duration
}
type Snapshot ¶
type Snapshot struct {
Running bool `json:"running"`
Definitions []Definition `json:"definitions"`
Stats Stats `json:"stats"`
Recent []Record `json:"recent"`
}
type State ¶
type State string
type Stats ¶
type Stats struct {
Total int `json:"total"`
ByState map[State]int `json:"by_state"`
ByKind map[string]int `json:"by_kind"`
ByQueue map[string]int `json:"by_queue"`
}
Directories ¶
| Path | Synopsis |
|---|---|
| lazyjobs/inmemoryjobs | Package inmemoryjobs provides an in-memory lazyjobs backend. |
Package lazyjobs provides a small background job runner contract.
Applications define typed jobs, register them with a JobRunner, and enqueue JSON-backed payloads. The runner owns worker lifecycle, retries, state transitions, and read-only inspection. Storage is delegated to a Backend so applications can choose in-memory, PostgreSQL, or another durable backend.