Documentation
¶
Overview ¶
Package tasks emulates the tasks service: queues of work delivered to a function, a channel or a signed webhook (push queues), or leased by workers (pull queues), with retries, backoff, dead-letter queues and triggers from datastore writes, blob uploads and mailbox routes.
Every bound, validator and message here is the hosted service's, so a queue setting or a task accepted here is accepted there, and one refused there is refused here.
Index ¶
- Constants
- Variables
- func AddResponse(results []AddResult) (int, map[string]any)
- func DeliveryBody(task Envelope, payloadJSON string) []byte
- func IDsOf(body map[string]any) ([]string, error)
- func NewTaskID(now int64) string
- func NextAttemptAt(r RetryPolicy, attempts int, createdAt, now int64) int64
- func NormalizedTriggers(service string, cfg map[string]any) (any, bool)
- func ParseState(v string) (string, error)
- func ResultText(v any) *string
- func SignWebhook(secret string, timestamp int64, body []byte) string
- func SplitRef(s string) (instance, name string)
- func TargetLabel(t *Target) string
- func ValidateConfig(cfg map[string]any) error
- func ValidateQueueName(v any, what string) (string, error)
- func ValidateQueueRef(v any, what string) (string, error)
- func ValidateTaskName(v any, what string) (*string, error)
- func ValidateWebhookURL(v any, what string) (string, error)
- type AddResult
- type Attempt
- type BlobMatch
- type BlobTrigger
- type CancelResult
- type Claimed
- type Counts
- type DatastoreMatch
- type DatastoreTrigger
- type Envelope
- type EventTask
- type FailedTask
- type Handler
- type LeasedTask
- type ListOptions
- type MayTarget
- type Outcome
- type QueueInfo
- type QueueSettings
- type RetryPolicy
- type Service
- func (s *Service) AddTasks(in *control.Instance, queue string, body json.RawMessage, source string, ...) ([]AddResult, error)
- func (s *Service) BlobChanged(in *control.Instance, c blob.Change, writerDepth int)
- func (s *Service) BlobWatches(in *control.Instance) bool
- func (s *Service) CheckQueues(refs []string) error
- func (s *Service) DatastoreWatches(in *control.Instance, namespace, collection string) bool
- func (s *Service) DatastoreWrite(in *control.Instance, namespace string, changes []datastore.WriteChange, ...)
- func (s *Service) Drop(instanceID string)
- func (s *Service) EnqueueMail(ref, messageID string, payload, summary []byte) (status, why string, permanent bool)
- func (s *Service) Kick()
- func (s *Service) Release(in *control.Instance, id, leaseID string, delaySeconds float64, ...) (*TaskRecord, error)
- func (s *Service) Run(ctx context.Context)
- func (s *Service) RunTask(in *control.Instance, id string) (*TaskRecord, error)
- func (s *Service) SaveQueue(in *control.Instance, name string, patch any, create bool, may MayTarget) (*QueueInfo, error)
- func (s *Service) SetClock(now func() int64)
- func (s *Service) SetHTTPClient(c *http.Client)
- func (s *Service) Store() *Store
- func (s *Service) Tick()
- func (s *Service) ValidateBlobConfig(cfg map[string]any) error
- func (s *Service) ValidateDatastoreConfig(cfg map[string]any) error
- func (s *Service) ValidateMailboxConfig(cfg map[string]any) error
- func (s *Service) Wait()
- type SkippedTask
- type Store
- func (s *Store) Ack(instanceID, id, leaseID string, result *string, now int64, keepDays int) (*TaskRecord, error)
- func (s *Store) Add(instanceID, queue string, items []TaskInput, source string, depth int, ...) ([]AddResult, bool, error)
- func (s *Store) Cancel(instanceID string, ids []string, now int64, keepDays int) (*CancelResult, error)
- func (s *Store) Claim(instanceID string, running map[string]int, busy []string, now int64) ([]Claimed, error)
- func (s *Store) DeleteQueue(instanceID, name string) (map[string]any, error)
- func (s *Store) Drop(instanceID string)
- func (s *Store) Extend(instanceID, id, leaseID string, leaseSeconds float64, now int64) (*TaskRecord, error)
- func (s *Store) Get(instanceID, id string) (*TaskRecord, error)
- func (s *Store) GetQueue(instanceID, name string) (*QueueInfo, error)
- func (s *Store) Housekeep(instanceID string, inflight map[string]bool, now int64, keepDays int) ([]*FailedTask, error)
- func (s *Store) Lease(instanceID, queue string, count, leaseSeconds float64, now int64) ([]LeasedTask, error)
- func (s *Store) List(instanceID, queue string, o ListOptions) (*TaskPage, error)
- func (s *Store) ListQueues(instanceID string) ([]QueueInfo, error)
- func (s *Store) NextDue(instanceID string, running map[string]int, now int64) (int64, error)
- func (s *Store) NoteLate(instanceID, id string, attempt int, answer string, now int64) error
- func (s *Store) PurgeQueue(instanceID, name string) (map[string]any, error)
- func (s *Store) PutQueue(instanceID, name string, settings QueueSettings, create bool, now int64) (*QueueInfo, error)
- func (s *Store) QueueSettingsOf(instanceID, name string) (QueueSettings, error)
- func (s *Store) Release(instanceID, id, leaseID string, delaySeconds float64, errText *string, ...) (*TaskRecord, *FailedTask, error)
- func (s *Store) RotateWebhookSecret(instanceID string) (string, error)
- func (s *Store) Run(instanceID, id string, now int64) (*TaskRecord, bool, error)
- func (s *Store) Settle(instanceID, id string, attempts int, o Outcome, now int64, keepDays int) (*FailedTask, error)
- func (s *Store) Stats(instanceID string) (tasks int, dbBytes int64, err error)
- func (s *Store) WebhookSecret(instanceID string) (string, error)
- type Target
- type TargetControl
- type TaskInput
- type TaskPage
- type TaskRecord
- type TaskSummary
Constants ¶
const ( SignatureHeader = "x-altengine-signature" TimestampHeader = "x-altengine-timestamp" )
const ( // MaxQueues is queues per instance. MaxQueues = 50 // MaxTasksPerAdd is tasks one add call may carry. MaxTasksPerAdd = 100 // MaxPayloadBytes is a task's payload, as JSON. MaxPayloadBytes = 128 * 1024 // MaxParamsBytes is a task's params, as JSON. MaxParamsBytes = 4 * 1024 // MaxResultBytes is how much of a target's answer is kept on the task. MaxResultBytes = 16 * 1024 // MaxDelayMS is how far ahead a task may be scheduled. MaxDelayMS = 30 * 86_400_000 // MaxNameLength is a task name's length. MaxNameLength = 500 // DefaultQueue exists in every instance and cannot be deleted. DefaultQueue = "default" // MaxInflight is deliveries in flight across one instance at once. MaxInflight = 50 MaxConcurrentPerQueue = 50 MaxRatePerSecond = 100.0 MaxLeaseCount = 100 MaxLeaseSeconds = 3600 DefaultLeaseSeconds = 300 // DefaultDeadlineSeconds is how long a push delivery is waited for before the attempt counts // as failed and is retried — the queue's `deadlineSeconds`, overridable per task. The target // is not stopped when it passes; the queue stops waiting. Longer work belongs on a pull queue, // whose worker extends its lease for as long as it needs. DefaultDeadlineSeconds = 600 MinDeadlineSeconds = 15 MaxDeadlineSeconds = 840 // LeaseSlackMS is added to a running task's deadline to make its lease. Past it, the attempt // was lost (a restart mid-delivery) and the task is retried like a timeout. LeaseSlackMS = 60_000 // HoldBudget bounds how long a call that outran its deadline keeps its task's slot, counted // from when the attempt started — the same bound the hosted queue keeps. Past it the slot is // freed and the attempt records that the target was still running. HoldBudget = 14*time.Minute + 30*time.Second MaxTriggerDepth = 8 MaxListLimit = 200 CountCap = 10_000 MaxDefers = 1000 MaxWebhookURLLength = 2048 RetryHeader = "x-task-retry" RetryAfterHeader = "x-task-retry-after" MaxAttemptsHeader = "x-task-max-attempts" DefaultRetentionDays = 7 MaxRetentionDays = 30 )
const ( // MaxTriggers is rules per instance. MaxTriggers = 20 // MaxEventDocBytes is one document carried in an event; a larger one is sent as its key alone. MaxEventDocBytes = 32 * 1024 // MaxEventsPerTask is events folded into one task. MaxEventsPerTask = 100 )
const MaxAddBodyBytes = 4 * 1024 * 1024
MaxAddBodyBytes bounds one add: up to 100 tasks.
Variables ¶
var DefaultRetry = RetryPolicy{MaxAttempts: 10, MinBackoffSeconds: 10, MaxBackoffSeconds: 3600, MaxDoublings: 8, MaxAgeSeconds: 7 * 86_400}
DefaultRetry is a task's retry policy unless its queue or itself says otherwise.
var States = []string{"scheduled", "running", "leased", "done", "failed", "cancelled"}
States a task can be in.
Functions ¶
func AddResponse ¶
AddResponse is an add's answer: every task's result — and, when none was added, a 409 with the usual error envelope carrying the first refusal, so a client reading only `error` still learns why.
func DeliveryBody ¶
DeliveryBody is the JSON a function or webhook receives: the payload spliced in as stored.
func NewTaskID ¶
NewTaskID is time-ordered and fixed-width: base36 milliseconds then random, so lexicographic order is creation order and an id is a keyset cursor.
func NextAttemptAt ¶
func NextAttemptAt(r RetryPolicy, attempts int, createdAt, now int64) int64
NextAttemptAt is when the next attempt is due after `attempts` failures, or 0 when the task is spent. The wait doubles maxDoublings times from minBackoffSeconds, then grows linearly by the last doubled step, capped at maxBackoffSeconds — App Engine's rule.
func NormalizedTriggers ¶
NormalizedTriggers rewrites a saved config's `triggers` to their normalized form (trimmed, `_default` read as the default namespace, duplicate ops dropped) — what the hosted service stores and returns.
func ParseState ¶
ParseState reads a `state` filter: "" or "all" is every state.
func ResultText ¶
ResultText is an ack's result as stored: a string as is, anything else as JSON, null as none.
func SignWebhook ¶
SignWebhook is the delivery signature: `v1=` + hex HMAC-SHA256, keyed with the whole secret, over "<timestamp>.<raw body>" — the scheme every altengine webhook uses.
func SplitRef ¶
SplitRef splits `<instance>/<name>` at the FIRST slash — a channel name may contain slashes.
func ValidateConfig ¶
ValidateConfig is the tasks instance's config check on a write, with the hosted rules. Queues are NOT config: they are rows of their own, created and changed through their own routes, because a queue's settings change while tasks run through it.
func ValidateQueueName ¶
ValidateQueueName checks a queue name.
func ValidateQueueRef ¶
ValidateQueueRef checks `<tasks-instance>/<queue>` — what a trigger rule or a mailbox route names.
func ValidateTaskName ¶
ValidateTaskName checks a task name; empty is no name.
Types ¶
type Attempt ¶
type Attempt struct {
N int `json:"n"`
StartedAt int64 `json:"startedAt"`
EndedAt *int64 `json:"endedAt"`
Status *string `json:"status"`
Error *string `json:"error"`
}
Attempt is one attempt's record.
type BlobMatch ¶
type BlobMatch struct {
Prefix string `json:"prefix,omitempty"`
ContentType string `json:"contentType,omitempty"`
Ops []string `json:"ops,omitempty"`
}
BlobMatch is what a blob rule matches.
type BlobTrigger ¶
type BlobTrigger struct {
Match BlobMatch `json:"match"`
Queue string `json:"queue"`
Params json.RawMessage `json:"params,omitempty"`
}
BlobTrigger is one blob rule.
func ValidateBlobTriggers ¶
func ValidateBlobTriggers(input any, what string) ([]BlobTrigger, error)
ValidateBlobTriggers is the strict check of a blob instance's `triggers`.
type CancelResult ¶
type CancelResult struct {
Cancelled []string `json:"cancelled"`
Skipped []SkippedTask `json:"skipped"`
}
CancelResult is what a cancel reports.
type Claimed ¶
type Claimed struct {
Row *taskRow
Settings QueueSettings
}
Claimed is one task the engine has claimed for delivery.
type Counts ¶
type Counts struct {
Scheduled int `json:"scheduled"`
Running int `json:"running"`
Leased int `json:"leased"`
Done int `json:"done"`
Failed int `json:"failed"`
Cancelled int `json:"cancelled"`
}
Counts is a queue's tasks per state, each capped at CountCap.
type DatastoreMatch ¶
type DatastoreMatch struct {
Collection string `json:"collection"`
Namespace *string `json:"namespace,omitempty"`
Ops []string `json:"ops,omitempty"`
}
DatastoreMatch is what a datastore rule matches.
type DatastoreTrigger ¶
type DatastoreTrigger struct {
Match DatastoreMatch `json:"match"`
Queue string `json:"queue"`
Params json.RawMessage `json:"params,omitempty"`
Document *bool `json:"document,omitempty"`
}
DatastoreTrigger is one datastore rule.
func ValidateDatastoreTriggers ¶
func ValidateDatastoreTriggers(input any, what string) ([]DatastoreTrigger, error)
ValidateDatastoreTriggers is the strict check of a datastore instance's `triggers`.
type Envelope ¶
type Envelope struct {
ID string `json:"id"`
Queue string `json:"queue"`
Name *string `json:"name"`
Attempt int `json:"attempt"`
MaxAttempts int `json:"maxAttempts"`
RunAt int64 `json:"runAt"`
CreatedAt int64 `json:"createdAt"`
Source string `json:"source"`
Depth int `json:"depth"`
Params json.RawMessage `json:"params"`
DeadLetterOf *string `json:"deadLetterOf"`
// DeadlineAt is when the queue stops waiting for this attempt and counts it as failed, in
// epoch ms. The target is not stopped then; it can still be running when the retry starts.
DeadlineAt int64 `json:"deadlineAt"`
}
Envelope is what a target receives about the task it is handed.
type EventTask ¶
type EventTask struct {
Queue string
Payload any
Params json.RawMessage
}
EventTask is one task an event produces.
func BlobEventTasks ¶
func BlobEventTasks(rules []BlobTrigger, sourceName string, c blob.Change) []EventTask
BlobEventTasks is the tasks one blob change produces.
func DatastoreEventTasks ¶
func DatastoreEventTasks(rules []DatastoreTrigger, sourceName, namespace string, changes []datastore.WriteChange) []EventTask
DatastoreEventTasks is the tasks a datastore write produces: per matching rule, one task per collection, its events in chunks of at most MaxEventsPerTask that fit a payload.
type FailedTask ¶
FailedTask names a task that has just failed for good — for the log.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves the tasks planes.
func NewHandler ¶
NewHandler builds the handler.
type LeasedTask ¶
type LeasedTask struct {
TaskRecord
LeaseID string `json:"leaseId"`
}
LeasedTask is a leased pull task and the token that acknowledges it.
type ListOptions ¶
ListOptions narrows a listing.
type MayTarget ¶
MayTarget checks that the caller may name a target — nil for a caller acting for the whole org (the console, the engine's own triggers).
type Outcome ¶
type Outcome struct {
OK bool
Status string
Error string
Permanent bool
Result *string
Control *TargetControl
}
Outcome is one attempt's result.
type QueueInfo ¶
type QueueInfo struct {
Name string `json:"name"`
Settings QueueSettings `json:"settings"`
CreatedAt int64 `json:"createdAt"`
UpdatedAt int64 `json:"updatedAt"`
Deleting bool `json:"deleting"`
Purging bool `json:"purging"`
Counts Counts `json:"counts"`
Capped []string `json:"capped"`
}
QueueInfo is a queue as every surface returns it.
type QueueSettings ¶
type QueueSettings struct {
Mode string `json:"mode"`
Target *Target `json:"target"`
RatePerSecond float64 `json:"ratePerSecond"`
MaxConcurrent int `json:"maxConcurrent"`
Retry RetryPolicy `json:"retry"`
DeadLetterQueue *string `json:"deadLetterQueue"`
Paused bool `json:"paused"`
TargetControl bool `json:"targetControl"`
// DeadlineSeconds is how long a push delivery is waited for (15–840, default 600).
DeadlineSeconds int `json:"deadlineSeconds"`
}
QueueSettings is one queue's configuration.
func DefaultQueueSettings ¶
func DefaultQueueSettings() QueueSettings
DefaultQueueSettings is what a new queue starts with.
func ValidateQueueSettings ¶
func ValidateQueueSettings(v any, base QueueSettings, selfName string) (QueueSettings, error)
ValidateQueueSettings is the strict check of a queue's settings. `base` is what an omitted field keeps — the current settings on an update, the defaults on a create — so a caller changing the rate does not reset the target. A PATCH by design.
type RetryPolicy ¶
type RetryPolicy struct {
MaxAttempts int `json:"maxAttempts"`
MinBackoffSeconds int `json:"minBackoffSeconds"`
MaxBackoffSeconds int `json:"maxBackoffSeconds"`
MaxDoublings int `json:"maxDoublings"`
MaxAgeSeconds int `json:"maxAgeSeconds"`
}
RetryPolicy bounds a task's attempts.
func ValidateRetry ¶
func ValidateRetry(v any, base RetryPolicy, what string) (RetryPolicy, error)
ValidateRetry checks a retry policy; a field left out keeps base's.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the tasks service: the store, the engine and delivery.
func NewService ¶
NewService builds the service. mux is the emulator's router, used to call functions in process; hub is the channel hub a channel target publishes into.
func (*Service) AddTasks ¶
func (s *Service) AddTasks(in *control.Instance, queue string, body json.RawMessage, source string, depth int, may MayTarget) ([]AddResult, error)
AddTasks adds one or many tasks to a queue. body is a task, an array of tasks, or { tasks }.
func (*Service) BlobChanged ¶
BlobChanged implements blob.TriggerSink.
func (*Service) BlobWatches ¶
BlobWatches implements blob.TriggerSink.
func (*Service) CheckQueues ¶
CheckQueues: every queue a rule list names must exist — checked at save time, where the person who typed it can still fix it, and again when an event fires.
func (*Service) DatastoreWatches ¶
DatastoreWatches implements datastore.TriggerSink: whether any rule could match a write to this collection — asked before the write, so a collection nobody watches pays nothing.
func (*Service) DatastoreWrite ¶
func (s *Service) DatastoreWrite(in *control.Instance, namespace string, changes []datastore.WriteChange, writerDepth int)
DatastoreWrite implements datastore.TriggerSink: fire the tasks a committed write produces.
func (*Service) EnqueueMail ¶
func (s *Service) EnqueueMail(ref, messageID string, payload, summary []byte) (status, why string, permanent bool)
EnqueueMail implements mailbox.QueueSink: a mailbox route hands a message to a queue. The task is named per message and route, so a retried delivery is refused as a duplicate rather than added twice — and that refusal still counts as delivered.
func (*Service) Release ¶
func (s *Service) Release(in *control.Instance, id, leaseID string, delaySeconds float64, errText *string) (*TaskRecord, error)
Release gives a leased task back.
func (*Service) SaveQueue ¶
func (s *Service) SaveQueue(in *control.Instance, name string, patch any, create bool, may MayTarget) (*QueueInfo, error)
SaveQueue creates (`create`) or changes a queue. A change is a PATCH over the current settings.
func (*Service) SetHTTPClient ¶
SetHTTPClient replaces the client webhooks are delivered with (tests).
func (*Service) ValidateBlobConfig ¶
ValidateBlobConfig checks a blob config's `triggers`.
func (*Service) ValidateDatastoreConfig ¶
ValidateDatastoreConfig checks a datastore config's `triggers`.
func (*Service) ValidateMailboxConfig ¶
ValidateMailboxConfig checks that every queue a mailbox route hands mail to exists. The route list's shape is the mailbox's own check, which runs first.
type SkippedTask ¶
SkippedTask is a task a cancel left alone, and why: its state, or null when it does not exist.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store holds every tasks instance's database.
func (*Store) Ack ¶
func (s *Store) Ack(instanceID, id, leaseID string, result *string, now int64, keepDays int) (*TaskRecord, error)
Ack finishes a leased task.
func (*Store) Add ¶
func (s *Store) Add(instanceID, queue string, items []TaskInput, source string, depth int, now int64) ([]AddResult, bool, error)
Add inserts tasks into a queue. Returns the results and whether a push queue now has work.
func (*Store) Cancel ¶
func (s *Store) Cancel(instanceID string, ids []string, now int64, keepDays int) (*CancelResult, error)
Cancel cancels scheduled or leased tasks. Running ones cannot be stopped mid-delivery.
func (*Store) Claim ¶
func (s *Store) Claim(instanceID string, running map[string]int, busy []string, now int64) ([]Claimed, error)
Claim claims as much due push work as the limits allow: per-queue concurrency (`running` per queue, from the caller), a token bucket per queue, and the instance's MaxInflight. `busy` are tasks whose previous call is still running — past its deadline, retried, its target not yet returned — and they are not started again beside it: a task never overlaps itself.
func (*Store) DeleteQueue ¶
DeleteQueue deletes a queue and every task in it. The default queue stays.
func (*Store) Extend ¶
func (s *Store) Extend(instanceID, id, leaseID string, leaseSeconds float64, now int64) (*TaskRecord, error)
Extend holds a lease longer.
func (*Store) Get ¶
func (s *Store) Get(instanceID, id string) (*TaskRecord, error)
Get is one task with its payload and attempts, or nil.
func (*Store) Housekeep ¶
func (s *Store) Housekeep(instanceID string, inflight map[string]bool, now int64, keepDays int) ([]*FailedTask, error)
Housekeep drops finished tasks past their retention and recovers tasks whose lease passed with nothing delivering them (a pull worker that never answered, or a delivery lost to a restart).
func (*Store) Lease ¶
func (s *Store) Lease(instanceID, queue string, count, leaseSeconds float64, now int64) ([]LeasedTask, error)
Lease leases up to count due tasks from a pull queue for leaseSeconds. Each comes with a lease id that ack, extend and release must present.
func (*Store) List ¶
func (s *Store) List(instanceID, queue string, o ListOptions) (*TaskPage, error)
List is one page of a queue's tasks. With a state, ordered by run time — soonest first for work waiting or running, latest first for work that has finished. Without, newest first by creation.
func (*Store) ListQueues ¶
ListQueues is every queue with its counts.
func (*Store) NextDue ¶
NextDue is when the engine should next look at this instance: the soonest scheduled push task (or, when one is due but its queue is out of tokens, when the bucket refills), a lease to check, or a record to prune. 0 when nothing is waiting.
func (*Store) NoteLate ¶ added in v0.2.36
NoteLate records, on an attempt that outran its deadline, what the target finally answered and how long after the attempt started: "<error>; the target answered http:200 after 42s". An empty answer means the hold's budget ran out first: "<error>; still running when this run of the queue ended (870s)".
func (*Store) PurgeQueue ¶
PurgeQueue deletes every task in a queue, whatever its state. A running one finishes, and its outcome is dropped with its row.
func (*Store) PutQueue ¶
func (s *Store) PutQueue(instanceID, name string, settings QueueSettings, create bool, now int64) (*QueueInfo, error)
PutQueue creates (`create`) or changes a queue. settings are already validated.
func (*Store) QueueSettingsOf ¶
func (s *Store) QueueSettingsOf(instanceID, name string) (QueueSettings, error)
QueueSettingsOf is a queue's current settings — the base a PATCH validates against.
func (*Store) Release ¶
func (s *Store) Release(instanceID, id, leaseID string, delaySeconds float64, errText *string, now int64, keepDays int) (*TaskRecord, *FailedTask, error)
Release gives a leased task back: scheduled again after delaySeconds, the attempt counted as failed (with errText) — or the task fails when it was the last attempt.
func (*Store) RotateWebhookSecret ¶
RotateWebhookSecret replaces the key; the next delivery is signed with the new one.
func (*Store) Run ¶
Run runs a task now. A scheduled one is moved to now; a failed or cancelled one goes back to scheduled with its attempts reset; a finished one is run again as a NEW task (same queue, payload, params and target, no name) — its record is history and stays as it was.
func (*Store) Settle ¶
func (s *Store) Settle(instanceID, id string, attempts int, o Outcome, now int64, keepDays int) (*FailedTask, error)
Settle records a delivery's outcome, if the row is still that attempt's.
type Target ¶
type Target struct {
Function string `json:"function,omitempty"`
Channel string `json:"channel,omitempty"`
Webhook string `json:"webhook,omitempty"`
}
Target is where a push task is delivered: exactly one field is set.
type TargetControl ¶
type TargetControl struct {
Retry string // "", "never", "retry" or "defer"
RetryAt int64 // epoch ms, 0 when not given
MaxAttempts int // 0 when not given
}
TargetControl is what a target's response headers ask for.
func ReadTargetControl ¶
func ReadTargetControl(h http.Header, now int64) *TargetControl
ReadTargetControl reads a target's response headers, or nil when they ask for nothing.
type TaskInput ¶
type TaskInput struct {
Name *string
Target *Target
Payload string // JSON text, size-checked
Params *string
RunAt int64
Retry *RetryPolicy
// DeadlineSeconds overrides the queue's for this task; nil means the queue's.
DeadlineSeconds *int
}
TaskInput is one task as a caller sends it, validated and normalized.
func ValidateTaskInput ¶
ValidateTaskInput validates one task. `delay` is seconds from now; `runAt` is epoch ms or an ISO time; both is an error; neither is "now".
func ValidateTaskList ¶
func ValidateTaskList(body json.RawMessage, now int64) ([]TaskInput, error)
ValidateTaskList reads a task object, an array of tasks, or { tasks: [...] }.
type TaskPage ¶
type TaskPage struct {
Tasks []TaskSummary `json:"tasks"`
Cursor *string `json:"cursor"`
}
TaskPage is one page of a queue's tasks.
type TaskRecord ¶
type TaskRecord struct {
TaskSummary
Payload json.RawMessage `json:"payload"`
Params json.RawMessage `json:"params"`
Result *string `json:"result"`
Retry *RetryPolicy `json:"retry"`
AttemptLog []Attempt `json:"attemptLog"`
}
TaskRecord is a task with everything.
type TaskSummary ¶
type TaskSummary struct {
ID string `json:"id"`
Queue string `json:"queue"`
Name *string `json:"name"`
State string `json:"state"`
Target *Target `json:"target"`
Attempts int `json:"attempts"`
MaxAttempts int `json:"maxAttempts"`
RunAt int64 `json:"runAt"`
CreatedAt int64 `json:"createdAt"`
StartedAt *int64 `json:"startedAt"`
FinishedAt *int64 `json:"finishedAt"`
LeaseUntil *int64 `json:"leaseUntil"`
LastStatus *string `json:"lastStatus"`
LastError *string `json:"lastError"`
Source string `json:"source"`
Depth int `json:"depth"`
PayloadBytes int `json:"payloadBytes"`
DeadLetterOf *string `json:"deadLetterOf"`
Defers int `json:"defers"`
// DeadlineSeconds is this task's own deadline; null means its queue's.
DeadlineSeconds *int64 `json:"deadlineSeconds"`
}
TaskSummary is a task without its payload, params or result.