Documentation ¶
Overview ¶
Package cron provides a simple yet powerful cron scheduling library. It allows users to schedule functions to be executed at specific times or intervals, following a format similar to traditional UNIX cron, but with extended support for seconds and milliseconds. Parsing of UNIX cron is done by https://pkg.go.dev/github.com/robfig/cron/v3@v3.0.1
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Job ¶
type Job struct { Schedule _cron.Schedule `json:"schedule"` Blocking bool `json:"blocking"` Timezone *time.Location `json:"timezone"` Ctx context.Context `json:"-"` Fn func(ctx context.Context) `json:"-"` // contains filtered or unexported fields }
Job represents a cron job with a specific schedule and task. It holds the schedule string, the parsed schedule, execution settings like blocking behavior, timezone, and the function to execute.
func Schedule ¶
Schedule initializes a new Job with a given cron schedule string. The function panics if the schedule string is invalid. The schedule string supports the traditional UNIX cron format with optional seconds field at the beginning.
func (*Job) Execute ¶
Execute sets the function (Fn) to be executed by the Job. The provided function should accept a context.Context parameter.
func (*Job) MarshalJSON ¶
MarshalJSON customizes the JSON output of Job.
func (*Job) SetBlocking ¶
SetBlocking configures the Job's blocking behavior. If set to true, the job will run its task synchronously. If false, the job will run asynchronously.
func (*Job) SetTimezone ¶
SetTimezone sets the timezone in which the Job's schedule will be interpreted.
func (*Job) Start ¶
func (j *Job) Start()
Start initiates the execution of the Job according to its schedule. The job runs either synchronously or asynchronously based on its Blocking setting.