package lazyjobs

import "golazy.dev/lazyjobs"

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.

Constants

Variables

Functions

Types

type Definition

type Definition struct {
	Kind		string	`json:"kind"`
	Type		string	`json:"type"`
	Queue		string	`json:"queue"`
	MaxAttempts	int	`json:"max_attempts"`
}

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 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 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.