task

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Scheduler)

func WithBackoff

func WithBackoff(strategy backoff.Strategy, maxDelay time.Duration) Option

WithBackoff overrides the retry backoff strategy and maximum delay between execution attempts

func WithMaxFailedAttempts

func WithMaxFailedAttempts(maxFailedAttempts uint32) Option

WithMaxFailedAttempts overrides the number of failed execution attempts before a task is marked as failed

type Scheduler

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

Scheduler is the entry point into the guaranteed task execution system. Tasks are durably enqueued within the caller's DB transaction and executed at least once via the app's TaskExecutor, either through the best-effort fast path or the background worker.

func NewScheduler

func NewScheduler(log *zap.Logger, data ocp_data.Provider, executor integration.TaskExecutor, opts ...Option) *Scheduler

func (*Scheduler) Enqueue

func (s *Scheduler) Enqueue(ctx context.Context, records ...*task_data.Record) error

Enqueue durably persists tasks for guaranteed execution. When called within a DB transaction passed along ctx (eg. the one committing an intent), the tasks are persisted atomically with that transaction.

func (*Scheduler) ExecuteAndAdvance

func (s *Scheduler) ExecuteAndAdvance(ctx context.Context, record *task_data.Record) error

ExecuteAndAdvance executes a single pending task and advances its state based on the outcome. On success the task is confirmed. On failure the task is scheduled for a retry with backoff, or marked as failed once the maximum attempt count is reached.

Both the fast path and the background worker funnel through this method, so the two cannot disagree on semantics. Concurrent executions of the same task are resolved by the optimistic concurrency check when the task record is updated.

func (*Scheduler) TryExecuteNow

func (s *Scheduler) TryExecuteNow(ctx context.Context, records ...*task_data.Record)

TryExecuteNow makes a best-effort immediate execution attempt for the provided tasks. Failures are left for the background worker to retry.

This must only be called after the tasks have been committed to the DB.

Jump to

Keyboard shortcuts

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