async

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const RunJobType = "run"

Variables

View Source
var (
	ErrJobNotFound = errors.New("async: job not found")
	ErrStaleLease  = errors.New("async: stale job lease")
	ErrInvalidJob  = errors.New("async: invalid job")
)

Functions

This section is empty.

Types

type Handler

type Handler interface {
	HandleJob(ctx context.Context, job Job) error
}

type HandlerFunc

type HandlerFunc func(ctx context.Context, job Job) error

func (HandlerFunc) HandleJob

func (fn HandlerFunc) HandleJob(ctx context.Context, job Job) error

type Job

type Job struct {
	ID             string          `json:"id"`
	Type           string          `json:"type"`
	RunID          string          `json:"run_id,omitempty"`
	Payload        json.RawMessage `json:"payload,omitempty"`
	State          JobState        `json:"state"`
	Attempts       int             `json:"attempts"`
	MaxAttempts    int             `json:"max_attempts"`
	LastError      string          `json:"last_error,omitempty"`
	CreatedAt      time.Time       `json:"created_at"`
	UpdatedAt      time.Time       `json:"updated_at"`
	AvailableAt    time.Time       `json:"available_at"`
	LeaseWorkerID  string          `json:"lease_worker_id,omitempty"`
	LeaseExpiresAt time.Time       `json:"lease_expires_at,omitempty"`
}

func CloneJob

func CloneJob(job Job) Job

func (Job) Validate

func (job Job) Validate() error

type JobState

type JobState string
const (
	JobQueued     JobState = "queued"
	JobRunning    JobState = "running"
	JobCompleted  JobState = "completed"
	JobFailed     JobState = "failed"
	JobCancelled  JobState = "cancelled"
	JobDeadLetter JobState = "dead_letter"
)

type Lease

type Lease struct {
	JobID     string
	WorkerID  string
	Attempt   int
	ExpiresAt time.Time
}

func (Lease) Validate

func (lease Lease) Validate() error

type LeaseRenewer

type LeaseRenewer interface {
	Renew(ctx context.Context, lease Lease, ttl time.Duration) (Lease, bool, error)
}

type Queue

type Queue interface {
	Enqueue(ctx context.Context, job Job) (Job, error)
	Lease(ctx context.Context, workerID string, ttl time.Duration) (Lease, bool, error)
	Load(ctx context.Context, jobID string) (Job, error)
	Complete(ctx context.Context, lease Lease) error
	Fail(ctx context.Context, lease Lease, cause error) error
	Cancel(ctx context.Context, jobID string) error
}

type RunPayload

type RunPayload struct {
	RunID       string             `json:"run_id,omitempty"`
	ScenarioID  string             `json:"scenario_id,omitempty"`
	Scenario    json.RawMessage    `json:"scenario,omitempty"`
	Agent       string             `json:"agent,omitempty"`
	Prompt      string             `json:"prompt,omitempty"`
	Context     json.RawMessage    `json:"context,omitempty"`
	MaxAttempts int                `json:"max_attempts,omitempty"`
	Metadata    map[string]string  `json:"metadata,omitempty"`
	Principal   identity.Principal `json:"principal,omitempty"`
}

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

func NewWorker

func NewWorker(queue Queue, handler Handler, config WorkerConfig) (*Worker, error)

func (*Worker) Run

func (worker *Worker) Run(ctx context.Context) error

type WorkerConfig

type WorkerConfig struct {
	WorkerID      string
	Concurrency   int
	LeaseTTL      time.Duration
	RenewInterval time.Duration
	JobTimeout    time.Duration
	PollInterval  time.Duration
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL