cron

package
v1.26.30 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 36 Imported by: 0

Documentation

Overview

Scheduling belongs to Hanzo Tasks, and this file is the only place that knows it.

What stood here was a second async system: gocron driving thirty jobs in process, each wrapped by hand in a global lock, a panic recover, and its own bookkeeping. Every one of those is something Tasks already does, and doing it twice is how the two versions drift.

The cost of the second system was measured rather than argued. One schedule naming a reusable workflow this instance does not host held 108 of the 116 specs below it overdue across 60 repositories — for eleven days, unnoticed, because a ticker loop has no failure surface. Under Tasks that run fails on its own, retries under its policy, and lands in `tasks_workflow_runs_failed_total` where it pages.

The declaration surface does not move. `RegisterTaskFatal(name, config, fn)` still says what a job is and when it runs; the thirty callers are untouched. Only the thing that fires them changed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GitCronJobWorkflow added in v1.26.30

func GitCronJobWorkflow(ctx workflow.Context, name string) error

GitCronJobWorkflow is what every schedule fires. It carries the job's name and nothing else — the work itself is an activity, so a panic inside it is caught, counted as an attempt, and retried by the server rather than swallowed by a recover() we maintain.

func Init

func Init(original context.Context)

Init begins cron tasks Each cron task is run within the shutdown context as a running server AtShutdown the cron server is stopped

func RegisterTask

func RegisterTask(name string, config Config, fun func(context.Context, *user_model.User, Config) error) error

RegisterTask allows a task to be registered with the cron service

func RegisterTaskFatal

func RegisterTaskFatal(name string, config Config, fun func(context.Context, *user_model.User, Config) error)

RegisterTaskFatal will register a task but if there is an error log.Fatal

func RunCronJobActivity added in v1.26.30

func RunCronJobActivity(ctx context.Context, name string) error

RunCronJobActivity executes one registered job in this process.

It calls the job function directly. The lock, the recover and the run counter that used to wrap this are gone: a schedule does not overlap itself, an activity panic is the server's to catch, and the count lives in the visibility store where it can be queried rather than in a mutex-guarded int that dies with the pod.

Types

type BaseConfig

type BaseConfig struct {
	Enabled         bool
	RunAtStart      bool
	Schedule        string
	NoticeOnSuccess bool
}

BaseConfig represents the basic config for a Cron task

func (*BaseConfig) DoNoticeOnSuccess

func (b *BaseConfig) DoNoticeOnSuccess() bool

DoNoticeOnSuccess returns whether a success notice should be posted

func (*BaseConfig) DoRunAtStart

func (b *BaseConfig) DoRunAtStart() bool

DoRunAtStart returns whether the task should be run at the start

func (*BaseConfig) FormatMessage

func (b *BaseConfig) FormatMessage(locale translation.Locale, name, status, doer string, args ...any) string

FormatMessage returns a message for the task Please note the `status` string will be concatenated with `admin.dashboard.cron.` and `admin.dashboard.task.` to provide locale messages. Similarly `name` will be composed with `admin.dashboard.` to provide the locale name for the task.

func (*BaseConfig) GetSchedule

func (b *BaseConfig) GetSchedule() string

GetSchedule returns the schedule for the base config

func (*BaseConfig) IsEnabled

func (b *BaseConfig) IsEnabled() bool

IsEnabled returns the enabled status for the config

type CleanupHookTaskConfig

type CleanupHookTaskConfig struct {
	BaseConfig
	CleanupType  string
	OlderThan    time.Duration
	NumberToKeep int
}

CleanupHookTaskConfig represents a cron task with settings to cleanup hook_task

type Config

type Config interface {
	IsEnabled() bool
	DoRunAtStart() bool
	GetSchedule() string
	FormatMessage(locale translation.Locale, name, status, doer string, args ...any) string
	DoNoticeOnSuccess() bool
}

Config represents a basic configuration interface that cron task

type GCLFSConfig

type GCLFSConfig struct {
	BaseConfig
	OlderThan                time.Duration
	LastUpdatedMoreThanAgo   time.Duration
	NumberToCheckPerRepo     int64
	ProportionToCheckPerRepo float64
}

type OlderThanConfig

type OlderThanConfig struct {
	BaseConfig
	OlderThan time.Duration
}

OlderThanConfig represents a cron task with OlderThan setting

type Task

type Task struct {
	Name string

	Status      string
	LastMessage string
	LastDoer    string
	ExecTimes   int64
	// This stores the time of the last manual run of this task.
	LastRun time.Time
	// contains filtered or unexported fields
}

Task represents a Cron task

func GetTask

func GetTask(name string) *Task

GetTask gets the named task

func (*Task) DoRunAtStart

func (t *Task) DoRunAtStart() bool

DoRunAtStart returns if this task should run at the start

func (*Task) GetConfig

func (t *Task) GetConfig() Config

GetConfig will return a copy of the task's config

func (*Task) IsEnabled

func (t *Task) IsEnabled() bool

IsEnabled returns if this task is enabled as cron task

func (*Task) Run

func (t *Task) Run()

Run will run the task incrementing the cron counter with no user defined

func (*Task) RunWithUser

func (t *Task) RunWithUser(doer *user_model.User, config Config)

RunWithUser will run the task incrementing the cron counter at the time with User

type TaskTable

type TaskTable []*TaskTableRow

TaskTable represents a table of tasks

func ListTasks

func ListTasks() TaskTable

ListTasks returns every registered cron task for the admin table.

The schedule of record is Hanzo Tasks; this reads the DECLARATION, which is the same string that was handed to CreateSchedule, and computes the next occurrence from it. That is arithmetic on a cron expression, not a second scheduler — nothing here decides when anything runs, and a describe call per row would put thirty round trips behind a page load to learn what the spec already says.

type TaskTableRow

type TaskTableRow struct {
	Name        string
	Spec        string
	Next        time.Time
	Prev        time.Time
	Status      string
	LastMessage string
	LastDoer    string
	ExecTimes   int64
	// contains filtered or unexported fields
}

TaskTableRow represents a task row in the tasks table

func (*TaskTableRow) FormatLastMessage

func (t *TaskTableRow) FormatLastMessage(locale translation.Locale) string

type UpdateExistingConfig

type UpdateExistingConfig struct {
	BaseConfig
	UpdateExisting bool
}

UpdateExistingConfig represents a cron task with UpdateExisting setting

Jump to

Keyboard shortcuts

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