Versions in this module Expand all Collapse all v0 v0.2.0 Jul 16, 2026 Changes in this version + var ErrAlreadyFinal = errors.New("taskgate: task already in final state") + var ErrAlreadyReplayed = errors.New("taskgate: execution already replayed (chain must not fork)") + var ErrCompletedNotAllowed = errors.New("taskgate: replaying a completed execution requires AllowCompleted") + var ErrLeaseLost = errors.New("taskgate: lease lost") + var ErrNoTask = errors.New("taskgate: no task associated with context") + var ErrReplayNotFinal = errors.New("taskgate: replay target not in final state") + var ErrShutdown = errors.New("taskgate: gate is shut down") + var ErrTaskCanceled = errors.New("taskgate: task canceled") + var ErrTaskExists = errors.New("taskgate: task already exists") + var ErrTaskNotFound = errors.New("taskgate: task not found") + var ErrUnknownType = errors.New("taskgate: no handler registered for task type") + func CanTransition(from, to Status) bool + func ParentFailureReason(parentID string, parentStatus Status) string + func RenewLease(ctx context.Context) error + type Broker interface + Ack func(ctx context.Context, id, leaseToken string, result []byte) error + Cancel func(ctx context.Context, id string) error + Close func() error + Counts func(ctx context.Context) (map[string]map[Status]int64, error) + Dequeue func(ctx context.Context, queues []string) (*Task, error) + Enqueue func(ctx context.Context, t *Task) error + Fail func(ctx context.Context, id, leaseToken, errMsg string, kind FailKind, ...) error + FinishCanceled func(ctx context.Context, id, leaseToken string) error + Get func(ctx context.Context, id string) (*Task, error) + Heartbeat func(ctx context.Context, id, leaseToken string) error + Init func(opts BrokerOptions) error + List func(ctx context.Context, f Filter) ([]*Task, error) + QueueLen func(ctx context.Context, queue string) (int, error) + ReapExpired func(ctx context.Context) (int, error) + Replay func(ctx context.Context, req ReplayRequest) (*Task, error) + Requeue func(ctx context.Context, id, leaseToken string) error + type BrokerOptions struct + Clock Clock + DefaultLeaseTTL time.Duration + LeaseLostMax int + LeaseTTL map[string]time.Duration + Notify func(Task) + ThrottledMax int + type ChildAction int + const ChildCancel + const ChildNone + const ChildWake + func DecideOnParentFinal(parentStatus, childStatus Status, policy ParentFailurePolicy, ...) (int, ChildAction) + type Clock interface + After func(d time.Duration) <-chan time.Time + NewTicker func(d time.Duration) Ticker + Now func() time.Time + Sleep func(ctx context.Context, d time.Duration) error + func RealClock() Clock + type Config struct + Broker Broker + DefaultQueue QueueConfig + LeaseLostMax int + OnStateChange func(Task) + Queues map[string]QueueConfig + Routes map[string]string + ThrottledMax int + type Duration time.Duration + func (d *Duration) UnmarshalText(b []byte) error + func (d Duration) MarshalText() ([]byte, error) + type ErrSkipRetry struct + Err error + func (e ErrSkipRetry) Error() string + func (e ErrSkipRetry) Unwrap() error + type ErrThrottled struct + RetryAfter time.Duration + func (e ErrThrottled) Error() string + type FailKind int + const FailBusiness + const FailSkip + const FailThrottled + type Filter struct + BusinessKey string + Limit int + Offset int + Queue string + Status Status + Type string + type Gate struct + func New(cfg Config) (*Gate, error) + func (g *Gate) Cancel(ctx context.Context, id string) error + func (g *Gate) Get(ctx context.Context, id string) (*Task, error) + func (g *Gate) Handle(taskType string, h Handler) + func (g *Gate) History(ctx context.Context, businessKey string) ([]*Task, error) + func (g *Gate) List(ctx context.Context, f Filter) ([]*Task, error) + func (g *Gate) Overview(ctx context.Context) (map[string]map[Status]int64, error) + func (g *Gate) Replay(ctx context.Context, executionID string, opts ...ReplayOption) (string, error) + func (g *Gate) ReplayByKey(ctx context.Context, businessKey string, opts ...ReplayOption) (string, error) + func (g *Gate) Run(ctx context.Context) error + func (g *Gate) Shutdown(ctx context.Context) error + func (g *Gate) Stats(ctx context.Context, queue string) (QueueStats, error) + func (g *Gate) Submit(ctx context.Context, taskType string, payload json.RawMessage, ...) (string, error) + func (g *Gate) Wait(ctx context.Context, id string) (json.RawMessage, error) + type Handler func(ctx context.Context, t *Task) ([]byte, error) + type LimiterProvider interface + QueueLimiter func(queue string, qc QueueConfig) (QueueLimiter, error) + type ParentFailurePolicy string + const FailFast + const IgnoreParentFail + type ParentState struct + ID string + Status Status + type QueueConfig struct + Burst int + LeaseTTL Duration + ManualHeartbeat bool + QuotaKey string + QuotaLimit int + QuotaPeriod Duration + RPS float64 + Workers int + type QueueLimiter interface + AcquireSlot func(ctx context.Context) error + ReleaseSlot func() + WaitToken func(ctx context.Context) error + type QueueStats struct + QueueLen int + QuotaExhausted bool + QuotaStalled bool + RPS float64 + Running int + Workers int + type QuotaGate interface + Release func(ctx context.Context, r *QuotaReservation) error + Reserve func(ctx context.Context) (*QuotaReservation, error) + type QuotaProvider interface + QueueQuota func(queue string, qc QueueConfig) (QuotaGate, error) + type QuotaReservation struct + Window int64 + type ReplayOption func(*replayOptions) + func AllowCompleted() ReplayOption + func WithPayload(p json.RawMessage) ReplayOption + type ReplayRequest struct + AllowCompleted bool + BusinessKey string + ExecutionID string + Payload json.RawMessage + type Status string + const StatusBlocked + const StatusCanceled + const StatusCompleted + const StatusFailed + const StatusPending + const StatusRetrying + const StatusRunning + func (s Status) IsFinal() bool + type SubmitDecision struct + LastError string + PendingParents int + Status Status + func DecideOnSubmit(parents []ParentState, policy ParentFailurePolicy) SubmitDecision + type SubmitOption func(*submitOptions) + func Delay(d time.Duration) SubmitOption + func DependsOn(ids ...string) SubmitOption + func IgnoreParentFailure() SubmitOption + func MaxRetry(n int) SubmitOption + func RunAt(t time.Time) SubmitOption + func WithBusinessKey(key string) SubmitOption + func WithID(id string) SubmitOption + type Task struct + Attempts int + BusinessKey string + CreatedAt time.Time + DependsOn []string + FinishedAt time.Time + ID string + LastError string + LeaseLost int + LeaseToken string + MaxRetry int + OnParentFailure ParentFailurePolicy + Payload json.RawMessage + Queue string + ReplayOf string + Result json.RawMessage + RunAt time.Time + StartedAt time.Time + Status Status + Throttled int + Type string + type TaskExistsError struct + BusinessKey string + ExecutionID string + Status Status + func (e *TaskExistsError) Error() string + func (e *TaskExistsError) Unwrap() error + type TaskFailedError struct + ID string + LastError string + Status Status + func (e *TaskFailedError) Error() string + type Ticker interface + C func() <-chan time.Time + Stop func() v0.1.0 Jul 16, 2026