jobs

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package jobs is the scheduler behind cron tiles: it fires them on their cron expression, runs each as a one-shot container from the tile's own image, and records the outcome in cron_runs. Cron expressions support CRON_TZ= prefixes for timezone-aware schedules.

It used to also run "scheduled jobs", a second scheduler with its own table, UI and overlap rules, attached to a service tile. A cron that needs a service's image says so with the same build: or image: and its own command:, so the digest matches and it builds once (docs/plans/38-surface-parity.md).

Index

Constants

View Source
const (
	TriggerSchedule  = "schedule"
	TriggerManualWeb = "manual web"
	TriggerManualAPI = "manual api"
	TriggerDeploy    = "deploy"
)

Triggers a run can be started by; recorded on the row so the history says who asked for it, the way deployments.trigger does.

View Source
const Kind = "cron.run"

Kind is the work-queue kind every cron and function run goes through: schedule ticks, manual runs and on-deploy runs alike.

Variables

This section is empty.

Functions

func NextRun

func NextRun(expr string) time.Time

NextRun returns the next fire time for a cron expression, zero if invalid.

func ValidateCron

func ValidateCron(expr string) error

ValidateCron rejects bad expressions at save time.

Types

type Service

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

func NewService

func NewService(store repo.Store, c *cluster.Cluster, notifier *notify.Notifier) *Service

func (*Service) Hold

func (s *Service) Hold(stackID string)

Hold parks the stack's schedule ticks for the length of a config apply: a cron firing mid-apply runs against tiles that do not exist yet. Manual runs are not held, the person asked. Release undoes one Hold.

func (*Service) LoadSchedules

func (s *Service) LoadSchedules(ctx context.Context) error

LoadSchedules (re)registers cron entries for all enabled jobs and all cron-kind apps (standalone CronJob-style services).

func (*Service) Release

func (s *Service) Release(stackID string)

func (*Service) RunService

func (s *Service) RunService(ctx context.Context, app *repo.Tile, runID string) string

RunService is the swarm service a cron tile's run executes as, for anyone who wants its logs: the task may sit on a worker, where the manager's container list cannot see it, but `docker service logs` can.

func (*Service) StartApp

func (s *Service) StartApp(ctx context.Context, appID, trigger, actor string) (*repo.CronRun, error)

StartApp opens the run row and queues the work, returning as soon as the row exists. A handler can then render a panel that already says "running", RunNow used to race the insert and always drew idle. Schedule ticks, manual runs and on-deploy runs all start here.

func (*Service) Stop

func (s *Service) Stop(ctx context.Context, runID string) bool

Stop cancels a run, waiting or in flight; false when it is already over. Cancelling the ctx is enough to kill the work: RunJob removes the job service it created when its ctx goes away, which kills the task. A run still waiting never started, so its row is closed here.

func (*Service) WithWork added in v0.4.0

func (s *Service) WithWork(q *workqueue.Queue) *Service

WithWork registers the run kind. Call before the queue starts.

A restart fails a run rather than requeueing it: re-running a half-done job blind is not safe. Cleanup removes the job service the run left behind, which is what Stop would have done.

Jump to

Keyboard shortcuts

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