Documentation
¶
Overview ¶
Package jobs provides in-process scheduling for periodic and trigger-aligned background jobs.
It supports both instance-based scheduling through NewJobs and a process-wide scheduler exposed by package-level helpers.
Main entry points:
- Job to register fixed-interval work
- CronJob to register jobs aligned to a daily trigger
- StartJobs to start registered global jobs
- RestartJobs to restart them without clearing definitions
- StopAllJobs to stop global jobs, optionally clearing them
Jobs are not started when they are registered. They begin running only after StartJobs is called, and jobs added after startup begin executing immediately.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckStatusJobs ¶
func CheckStatusJobs() bool
CheckStatusJobs reports whether the package-level scheduler is currently marked as active.
It returns true after jobs have started and false after they have been fully stopped.
func CronJob ¶
CronJob registers a trigger-aligned job in the package-level scheduler.
If interval <= 0, the job runs once per day at the time defined by trigger. If interval > 0, the first execution waits until the next matching trigger, and the job then repeats every interval.
The job is only registered here; execution begins when StartJobs runs.
func Job ¶
Job registers a fixed-interval job in the package-level scheduler.
The job runs once immediately when the scheduler starts, and then repeats every interval. If timeout is nil, the job keeps running until it is stopped by StopAllJobs or process shutdown. If timeout is non-nil and greater than zero, the job stops automatically when that duration expires.
The job is only registered here; execution begins when StartJobs runs.
func RestartJobs ¶
func RestartJobs()
RestartJobs requests a restart of the package-level scheduler.
The restart flow stops currently running jobs without clearing their registered definitions and starts them again from the current process state.
func StartJobs ¶
func StartJobs()
StartJobs starts the package-level jobs scheduler.
Internally it waits for restart signals and starts the global job registry when requested. This is the entry point used by higher-level server packages such as `server/gin.Start(...)`.
When `server.modeTest=true`, registered jobs are not started.
func StopAllJobs ¶
func StopAllJobs(clearJobs bool)
StopAllJobs stops and clears all globally registered instances created with NewJobs. It is useful for coordinated shutdowns, tests, or global resets.
Example:
jobs.StopAllJobs(true) // stops and clears all registered jobs in the process
StopAllJobs stops every globally registered jobs instance.
If clearJobs is false, the jobs stop but remain registered and can be started again later. If clearJobs is true, the jobs stop and their stored definitions are removed from each registered instance.
Types ¶
This section is empty.