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
- func NextRun(expr string) time.Time
- func ValidateCron(expr string) error
- type Service
- func (s *Service) Hold(stackID string)
- func (s *Service) LoadSchedules(ctx context.Context) error
- func (s *Service) Release(stackID string)
- func (s *Service) RunApp(ctx context.Context, appID, trigger, actor string)
- func (s *Service) RunService(ctx context.Context, app *repo.Tile, runID string) string
- func (s *Service) StartApp(ctx context.Context, appID, trigger, actor string) (*repo.CronRun, error)
- func (s *Service) Stop(runID string) bool
Constants ¶
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 ValidateCron ¶
ValidateCron rejects bad expressions at save time.
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) Hold ¶
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 ¶
LoadSchedules (re)registers cron entries for all enabled jobs and all cron-kind apps (standalone CronJob-style services).
func (*Service) RunService ¶
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 ¶
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.