Documentation
¶
Overview ¶
Package task defines the core Task record and its lifecycle.
Index ¶
Constants ¶
View Source
const DefaultMaxAttempts = 3
DefaultMaxAttempts is used when New.MaxAttempts is zero.
Variables ¶
View Source
var ( // ErrNotFound is returned when a task ID does not exist. ErrNotFound = errors.New("task: not found") // ErrLeaseNotHeld is returned when completing/failing/heartbeating a task // whose lease is owned by someone else or already expired. ErrLeaseNotHeld = errors.New("task: lease not held") // ErrDuplicateID is returned when enqueueing a task whose ID already exists. ErrDuplicateID = errors.New("task: duplicate id") // ErrInvalidTransition is returned by stores that validate transitions. ErrInvalidTransition = errors.New("task: invalid status transition") )
Functions ¶
func CanTransitionTo ¶
CanTransitionTo reports whether from → to is a legal lifecycle transition.
Types ¶
type New ¶
type New struct {
Project string
Type string
Payload json.RawMessage
Deps []ID
Priority int
MaxAttempts int
NotBefore time.Time
// DedupKey, when set, makes Enqueue idempotent: if a task with the same
// key already exists, that task is returned unchanged and no duplicate is
// created. Use a stable derivation (e.g. hash of project + source + title)
// so repeated harvest runs converge instead of re-enqueueing.
DedupKey string
}
New is a task template for enqueueing. ID, Attempts, Status and timestamps are assigned by the store; everything else is caller-supplied.
type Status ¶
type Status string
Status is the task lifecycle state. Transitions are validated by CanTransitionTo.
const ( // Pending means the task is waiting to be claimed (possibly delayed via NotBefore). Pending Status = "pending" // Running means a worker holds the lease. Running Status = "running" // Completed means the task succeeded (terminal). Completed Status = "completed" // Dead means attempts were exhausted and the task is parked in the dead-letter queue (terminal). Dead Status = "dead" // Cancelled means the task was withdrawn before completion (terminal). Cancelled Status = "cancelled" )
type Task ¶
type Task struct {
ID ID `json:"id"`
Project string `json:"project,omitempty"`
Type string `json:"type"`
Payload json.RawMessage `json:"payload,omitempty"`
Deps []ID `json:"deps,omitempty"`
Priority int `json:"priority,omitempty"`
Attempts int `json:"attempts"`
MaxAttempts int `json:"maxAttempts"`
NotBefore time.Time `json:"notBefore"`
Status Status `json:"status"`
LeaseOwner string `json:"leaseOwner,omitempty"`
LeaseExpires *time.Time `json:"leaseExpires,omitempty"`
LastError string `json:"lastError,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
CompletedAt *time.Time `json:"completedAt,omitempty"`
}
Task is the unit of work: what to run, for which project, under which constraints.
Click to show internal directories.
Click to hide internal directories.