1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-03-19 14:17:48 +02:00

42 lines
773 B
Go
Raw Normal View History

2024-12-22 16:05:38 +02:00
package cron
2024-12-25 22:24:24 +02:00
import "encoding/json"
2024-12-22 16:05:38 +02:00
// Job defines a single registered cron job.
type Job struct {
fn func()
schedule *Schedule
id string
}
// Id returns the cron job id.
func (j *Job) Id() string {
return j.id
}
2024-12-25 22:24:24 +02:00
// Expression returns the plain cron job schedule expression.
func (j *Job) Expression() string {
2024-12-22 16:05:38 +02:00
return j.schedule.rawExpr
}
// Run runs the cron job function.
func (j *Job) Run() {
if j.fn != nil {
j.fn()
}
}
2024-12-25 22:24:24 +02:00
// MarshalJSON implements [json.Marshaler] and export the current
// jobs data into valid JSON.
func (j Job) MarshalJSON() ([]byte, error) {
plain := struct {
Id string `json:"id"`
Expression string `json:"expression"`
}{
Id: j.Id(),
Expression: j.Expression(),
}
return json.Marshal(plain)
}