Help us shape the future of Go! Take the 2026 Go Developer Survey

scheduler

package
v2.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: BSD-3-Clause Imports: 3 Imported by: 5

Documentation

Index

Constants

View Source
const WorkflowTarget = "workflow"

WorkflowTarget marks the target that records a run's workflow instance.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActivitySyncCommand added in v2.15.0

type ActivitySyncCommand struct {
	RunID     string
	UpdatedAt time.Time
}

ActivitySyncCommand acknowledges one persisted activity projection version.

type AdmissionCommand added in v2.15.0

type AdmissionCommand struct {
	Epoch string
	Token string
}

type AdmissionKey added in v2.15.0

type AdmissionKey struct {
	Scope string
	ID    string
}

type AdmissionState added in v2.15.0

type AdmissionState struct {
	Epoch      string
	Token      string
	AcquiredAt time.Time
}

type Attempt added in v2.11.0

type Attempt struct {
	Number     int        `json:"number"`
	StartedAt  time.Time  `json:"startedAt"`
	FinishedAt *time.Time `json:"finishedAt,omitempty"`
	Outcome    Outcome    `json:"outcome"`
}

type BusWatcher added in v2.5.0

type BusWatcher interface {
	Name() string
	Start(ctx context.Context) error
	RunNow(ctx context.Context) error
}

BusWatcher is a continuous event consumer owned by the application scheduler lifecycle.

type ConditionalJob

type ConditionalJob interface {
	ShouldSchedule(ctx context.Context) bool
}

ConditionalJob allows a job to opt out of cron registration when it is disabled. Jobs that do not implement this interface are always scheduled.

type CoordinatorImport added in v2.15.0

type CoordinatorImport struct {
	Record     QueueRecord
	SourceHash string
}

CoordinatorImport binds imported state to the exact inactive legacy row.

type CoordinatorState added in v2.15.0

type CoordinatorState struct {
	Revision            uint64
	Record              QueueRecord
	Imported            bool
	ImportHash          string
	Dispatches          map[string]DispatchIntent
	PendingActivitySync map[string]time.Time
}

CoordinatorState is the durable state of one environment/job actor.

type DispatchIntent added in v2.15.0

type DispatchIntent struct {
	RunID   string
	Attempt int
	JobID   string
}

type DynamicScheduler added in v2.7.0

type DynamicScheduler interface {
	Submit(ctx context.Context, request Request) (Run, error)
	AddJob(ctx context.Context, job Job) error
	RemoveJob(ctx context.Context, name string)
	HasJob(name string) bool
}

DynamicScheduler owns jobs registered and removed while the application is running.

type ExecutionClaim added in v2.15.0

type ExecutionClaim struct {
	Run       Run
	Reconcile bool
	Claimed   bool
	Deferred  bool
}

ExecutionClaim records whether a delivery acquired its persisted run.

type ExecutionCommand added in v2.15.0

type ExecutionCommand struct {
	EnvironmentID string
	JobID         string
	RunID         string
	Attempt       int
}

type GenericJob

type GenericJob struct {
	JobName     string
	ScheduleFn  func(ctx context.Context) string
	RunFn       func(ctx context.Context) (Outcome, error)
	ReconcileFn func(ctx context.Context, previous Run) (Outcome, error)
	ShouldRunFn func(ctx context.Context) bool
}

GenericJob is a reusable Job built from closures. It lets a service register a per-entity dynamic job (e.g. one per GitOps sync or one per environment) without importing the scheduler package: the service constructs a GenericJob and hands it to the scheduler through the types/scheduler.Job interface.

JobName must be unique per logical job; per-entity jobs use a "<subsystem>:<entityID>" scheme (e.g. "gitops-sync:abc123"). ShouldRunFn is optional — when nil the job is always scheduled, matching the behavior of a Job that does not implement ConditionalJob.

func (*GenericJob) Name

func (g *GenericJob) Name() string

func (*GenericJob) Reconcile added in v2.11.0

func (g *GenericJob) Reconcile(ctx context.Context, previous Run) (Outcome, error)

func (*GenericJob) Run

func (g *GenericJob) Run(ctx context.Context) (Outcome, error)

func (*GenericJob) Schedule

func (g *GenericJob) Schedule(ctx context.Context) string

func (*GenericJob) ShouldSchedule

func (g *GenericJob) ShouldSchedule(ctx context.Context) bool

ShouldSchedule satisfies ConditionalJob. A GenericJob without a ShouldRunFn is always scheduled; the scheduler treats a ConditionalJob returning false as "do not schedule", so nil must map to true rather than a nil-func panic.

type Job

type Job interface {
	Name() string
	Schedule(ctx context.Context) string
	Run(ctx context.Context) (Outcome, error)
}

type JobController added in v2.7.0

type JobController interface {
	GetJob(jobID string) (Job, bool)
	GetJobRuntimeState(jobID string) (JobRuntimeState, bool)
	RescheduleJob(ctx context.Context, job Job) error
	RunBusWatcherNow(ctx context.Context, watcherID string) error
}

JobController exposes scheduler operations used by job-management services.

type JobRuntimeState added in v2.4.0

type JobRuntimeState struct {
	Schedule  string
	NextRun   *time.Time
	Scheduled bool
}

JobRuntimeState describes the schedule currently installed in a scheduler. It intentionally exposes only read-only state needed by job-management APIs.

type JobScheduler added in v2.7.0

type JobScheduler interface {
	ListRegisteredJobs() []Job
	WorkerController
	DynamicScheduler
	JobController

	RegisterJob(job Job) error
	RegisterBusWatcher(watcher BusWatcher, canRunManually bool) error
	StartScheduler(ctx context.Context) error
	GetLocation() *time.Location
	Stop(ctx context.Context) error
}

JobScheduler is the shared public contract for the actor-owned scheduler. Concrete cron and actor state remains private to the backend implementation.

type Outcome added in v2.11.0

type Outcome struct {
	Status     RunStatus       `json:"status"`
	Message    string          `json:"message,omitempty"`
	ActivityID string          `json:"activityId,omitempty"`
	Targets    []TargetOutcome `json:"targets,omitempty"`
	Steps      []StepOutcome   `json:"steps,omitempty"`
}

type OutcomeError added in v2.11.0

type OutcomeError struct {
	Outcome Outcome
	Cause   error
}

OutcomeError carries partial results through error-only watcher contracts.

func (*OutcomeError) Error added in v2.11.0

func (e *OutcomeError) Error() string

func (*OutcomeError) Unwrap added in v2.11.0

func (e *OutcomeError) Unwrap() error

type QueueRecord added in v2.11.0

type QueueRecord struct {
	Generation     uint64         `json:"-"`
	Sequence       uint64         `json:"-"`
	JobID          string         `json:"jobId"`
	EnvironmentID  string         `json:"environmentId"`
	Schedule       string         `json:"schedule"`
	LastEnqueuedAt time.Time      `json:"lastEnqueuedAt"`
	NextRun        time.Time      `json:"nextRun"`
	Runs           []Run          `json:"runs"`
	Receipts       map[string]Run `json:"receipts,omitempty"`
}

QueueRecord holds atomic admission, claims, and checkpoints for one job and target.

type Reconciler added in v2.11.0

type Reconciler interface {
	Reconcile(ctx context.Context, previous Run) (Outcome, error)
}

Reconciler consults domain state before repeating interrupted work.

type Request added in v2.11.0

type Request struct {
	// ObservedAgentRun adopts existing agent work without another submission.
	// TODO(v3): remove legacy-agent adoption.
	ObservedAgentRun *Run   `json:"-"`
	RunID            string `json:"runId,omitempty"`
	JobID            string `json:"jobId"`
	EnvironmentID    string `json:"environmentId"`
	Trigger          string `json:"trigger"`
	RequestedWithKey string `json:"requestedWithKey,omitempty"`
	RequestedBy      string `json:"requestedBy,omitempty"`
}

type RetryValidator added in v2.11.0

type RetryValidator interface {
	ValidateRetry(ctx context.Context, run Run) error
}

RetryValidator rejects retries without safe persisted target evidence.

type Run added in v2.11.0

type Run struct {
	ActivityEnvironmentID   string         `json:"activityEnvironmentId,omitempty"`
	ActivityID              string         `json:"activityId,omitempty"`
	Resolution              *RunResolution `json:"resolution,omitempty"`
	RequestedWithKey        string         `json:"requestedWithKey,omitempty"`
	ID                      string         `json:"id"`
	JobID                   string         `json:"jobId"`
	EnvironmentID           string         `json:"environmentId"`
	Trigger                 string         `json:"trigger"`
	RequestedBy             string         `json:"requestedBy,omitempty"`
	Status                  RunStatus      `json:"status"`
	CreatedAt               time.Time      `json:"createdAt"`
	UpdatedAt               time.Time      `json:"updatedAt"`
	StartedAt               *time.Time     `json:"startedAt,omitempty"`
	FinishedAt              *time.Time     `json:"finishedAt,omitempty"`
	NextAttempt             *time.Time     `json:"nextAttempt,omitempty"`
	AttemptCount            int            `json:"attemptCount"`
	Owner                   string         `json:"owner,omitempty"`
	Outcome                 Outcome        `json:"outcome"`
	Attempts                []Attempt      `json:"attempts,omitempty"`
	RemoteDeliveryAttempted bool           `json:"remoteDeliveryAttempted"`
	RemoteOutcome           *Outcome       `json:"remoteOutcome,omitempty"`
	RemoteRetryRequested    bool           `json:"remoteRetryRequested,omitempty"`
	RemoteRetryAttempted    bool           `json:"remoteRetryAttempted,omitempty"`
	RemoteAttemptCount      int            `json:"remoteAttemptCount,omitempty"`
	RemoteAccepted          bool           `json:"remoteAccepted"`
	RemoteSettled           bool           `json:"remoteSettled"`
	LastConfirmedAt         *time.Time     `json:"lastConfirmedAt,omitempty"`
}

type RunList added in v2.11.0

type RunList struct {
	Runs  []Run `json:"runs"`
	Total int   `json:"total"`
	Page  int   `json:"page"`
	Limit int   `json:"limit"`
}

type RunObserver added in v2.11.0

type RunObserver interface {
	ActivityID(run Run) string
	SyncRunActivity(ctx context.Context, run Run) error
}

RunObserver projects persisted runs into operator-facing activity records. ActivityID is persisted before projection and is empty for runs that should stay quiet.

type RunResolution added in v2.11.0

type RunResolution struct {
	ResolvedBy string    `json:"resolvedBy"`
	ResolvedAt time.Time `json:"resolvedAt"`
	Reason     string    `json:"reason"`
}

RunResolution preserves legacy resolution history. TODO(v3): remove this deprecated mixed-version compatibility contract.

type RunStatus added in v2.11.0

type RunStatus string

RunStatus describes durable execution, independently of the configured schedule.

const (
	Queued    RunStatus = "queued"
	Waiting   RunStatus = "waiting"
	Running   RunStatus = "running"
	Retrying  RunStatus = "retrying"
	Succeeded RunStatus = "succeeded"
	Partial   RunStatus = "partial"
	Skipped   RunStatus = "skipped"
	Failed    RunStatus = "failed"
	// NeedsAttention preserves domain recovery evidence and legacy job outcomes.
	NeedsAttention RunStatus = "needs_attention"
	Canceled       RunStatus = "canceled"
)

func (RunStatus) Terminal added in v2.11.0

func (s RunStatus) Terminal() bool

type ScheduleOccurrence added in v2.15.0

type ScheduleOccurrence struct {
	Generation uint64
	Sequence   uint64
}

type StepOutcome added in v2.16.0

type StepOutcome struct {
	Name       string     `json:"name"`
	Status     RunStatus  `json:"status"`
	Total      int        `json:"total,omitempty"`
	Completed  int        `json:"completed,omitempty"`
	Failed     int        `json:"failed,omitempty"`
	Attempts   int        `json:"attempts,omitempty"`
	Message    string     `json:"message,omitempty"`
	StartedAt  *time.Time `json:"startedAt,omitempty"`
	FinishedAt *time.Time `json:"finishedAt,omitempty"`
}

StepOutcome is one workflow step as projected onto its run.

type StoppableBusWatcher added in v2.7.0

type StoppableBusWatcher interface {
	BusWatcher
	Stop(ctx context.Context) error
}

StoppableBusWatcher lets a continuous watcher perform explicit shutdown work before its actor runner is joined.

type TargetOutcome added in v2.11.0

type TargetOutcome struct {
	RecoveryData jsontext.Value `json:"-" msgpack:"recoveryData,omitempty"`
	ResourceType string         `json:"resourceType,omitempty"`
	ID           string         `json:"id"`
	Status       RunStatus      `json:"status"`
	Message      string         `json:"message,omitempty"`
	ActivityID   string         `json:"activityId,omitempty"`
}

type WorkerController added in v2.11.0

type WorkerController interface {
	RestartWatcher(ctx context.Context, watcherID string) error
	WatcherHealth(watcherID string) (WorkerHealth, bool)
}

WorkerController exposes continuous-worker health and recovery operations.

type WorkerHealth added in v2.11.0

type WorkerHealth struct {
	Status    string     `json:"status"`
	LastError string     `json:"lastError,omitempty"`
	NextRetry *time.Time `json:"nextRetry,omitempty"`
	UpdatedAt time.Time  `json:"updatedAt"`
}

Jump to

Keyboard shortcuts

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