jobs

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 17 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.

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) RunApp

func (s *Service) RunApp(ctx context.Context, appID, trigger, actor string)

RunApp is the scheduler's entry point: the same work, waited on.

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 hands the work to a goroutine, 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.

ctx covers the lookup and the insert only. The work gets a background ctx: a request ctx dies when the response is written, which would cancel every manual run the instant it started.

func (*Service) Stop

func (s *Service) Stop(runID string) bool

Stop cancels a run in flight; false when it is not (or no longer) running. 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. The one exception is an exec-mode job, that kills the docker exec client, and the process inside the service's own container keeps going. The row still closes as stopped.

Jump to

Keyboard shortcuts

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