Cron Job
Introduction
The gcron module provides the implementation of scheduled tasks, supporting a configuration management style similar to crontab, and manages scheduled tasks with a minimum granularity of seconds.
Usage :
import "github.com/gogf/gf/v2/os/gcron"
API Documentation :
https://pkg.go.dev/github.com/gogf/gf/v2/os/gcron
Brief Description :
- The
Newmethod is used to create a custom scheduled task management object. - The
Addmethod is used to add scheduled tasks, where:- The
patternparameter usesCRON syntax format(for details, see the subsequent related description in this chapter). - The
jobparameter is the method (address) that needs to be executed. - The
nameis an optional parameter used to assign a unique name to the scheduled task. Note that if a task with the same name already exists, adding the scheduled task will fail.
- The
- The
AddSingletonmethod is used to add singleton scheduled tasks, meaning only one copy of the task can run simultaneously (deduplication is performed in memory). - The
AddOncemethod is used to add scheduled tasks that run only once. When run once, the task automatically destroys itself. - The
AddTimesmethod is used to add scheduled tasks that run a specified number of times. When runtimestimes, the task automatically destroys itself. - The
Entriesmethod is used to obtain information on all currently registered scheduled tasks. - The
Removemethod is used to delete scheduled tasks by name (stop and delete). - The
Searchmethod is used to search scheduled tasks by name (returns the*Entryobject pointer of the task). - The
Startmethod is used to start a scheduled task (Addautomatically starts the task). Thenameparameter can be specified to start the task. - The
Stopmethod is used to stop a scheduled task (Removestops and deletes). Thenameparameter can be specified to stop the task. - The
Closemethod is used to close the custom scheduled task management object.
Notes
- Influence of Global Timezone: Scheduled tasks strictly depend on time calculation, so the global timezone of the process greatly affects scheduled task execution. When adding scheduled tasks, pay attention to the global timezone settings of the current process. If no global timezone is set, the system timezone is used by default. For more information on timezone settings, please refer to: Time - Time Zone
