Skip to content
Scheduler Management

Scheduler Management

Scheduler Management runs background jobs: once after startup, repeatedly, daily at a fixed time or only on demand. Each job is declared in code. Administrators see its state, statistics, the last runs with their logs, start or stop it and change its schedule.

Scheduler

Enable

import cfgscheduler "go.wdy.de/nago/application/scheduler/cfg"

schedulers := std.Must(cfgscheduler.Enable(cfg)) // cfgscheduler.SchedulerManagement

cfgscheduler.SchedulerManagement has the fields UseCases scheduler.UseCases and Pages uischeduler.Pages with the path SchedulerDashboard.

Declare a job

option.MustZero(schedulers.UseCases.Configure(user.SU(), scheduler.Options{
	ID:          "my.app.cleanup",
	Name:        "Cleanup",
	Description: "Removes expired entries.",
	Kind:        scheduler.Schedule,
	Defaults:    scheduler.Settings{PauseTime: time.Hour},
	Runner: func(ctx context.Context) error {
		scheduler.LoggerFrom(ctx).Info("cleaning up")
		return nil
	},
}))
KindRuns
OneShotonce, StartDelay after startup
Schedulerepeatedly, with PauseTime between runs
Crondaily at CronHour:CronMinute server time; with PauseTime, repeatedly from then on
Manualonly when started by hand or with ExecuteNow

Defaults are the initial settings; administrators can override them, and the overrides are persisted. Actions adds custom buttons to the job page. Log with the logger from the context: each run keeps its own log, the logs of the last 5 runs and statistics of 30 days are kept.

Use cases

Use caseDescription
ConfigureDeclares a job.
ReconfigureReplaces the options of a job and keeps its settings.
RemoveStops a job and removes it with its settings.
ListSchedulersLists all jobs.
StatusState, last and next run, last error and statistics of a job.
ExecuteNowRuns a job immediately.
Start, StopStart or stop a job until the next restart.
FindSettingsByID, UpdateSettings, DeleteSettingsByIDRead, change or reset the settings of a job.
ListRunsLists the runs of a job, newest first.
ViewLogsShows the log of the current run.
ViewRunLogShows the log of a past run.

Permissions

PermissionAllows to
nago.scheduler.configuredeclare and reconfigure jobs
nago.scheduler.removeremove jobs
nago.scheduler.listalllist jobs
nago.scheduler.statusview state and runs
nago.scheduler.viewlogsview logs
nago.scheduler.executenowrun jobs immediately
nago.scheduler.startstart jobs
nago.scheduler.stopstop jobs
nago.scheduler.settings.find_by_idview settings
nago.scheduler.settings_updatechange settings
nago.scheduler.settings.delete_by_idreset settings

UI

The admin center shows a card per job in the group Hintergrundprozesse. It opens admin/scheduler/overview?id=<job id>.

Related