scheduler

package
v2.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 Dispatcher added in v2.11.0

type Dispatcher interface {
	Submit(ctx context.Context, request Request) (Run, error)
	Checkpoint(ctx context.Context, jobID, schedule string, nextRun time.Time) error
}

Dispatcher owns durable admission and execution. Cron only submits work.

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 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 {
	SetDispatcher(dispatcher Dispatcher)
	ListRegisteredJobs() []Job
	WorkerController
	DynamicScheduler
	JobController

	RegisterJob(job Job) error
	RegisterBusWatcher(watcher BusWatcher, canRunManually bool) error
	StartScheduler() 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"`
}

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 {
	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 {
	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 must be deterministic and 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"`
}

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 RunStatus = "needs_attention"
	Canceled       RunStatus = "canceled"
)

func (RunStatus) Terminal added in v2.11.0

func (s RunStatus) Terminal() bool

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 {
	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