added crons web apis and ui listing

This commit is contained in:
Gani Georgiev
2024-12-25 22:24:24 +02:00
parent ed1917b307
commit 56f951e5a2
46 changed files with 692 additions and 270 deletions

View File

@@ -1,5 +1,7 @@
package cron
import "encoding/json"
// Job defines a single registered cron job.
type Job struct {
fn func()
@@ -12,8 +14,8 @@ func (j *Job) Id() string {
return j.id
}
// Expr returns the plain cron job schedule expression.
func (j *Job) Expr() string {
// Expression returns the plain cron job schedule expression.
func (j *Job) Expression() string {
return j.schedule.rawExpr
}
@@ -23,3 +25,17 @@ func (j *Job) Run() {
j.fn()
}
}
// 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)
}