-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjob.go
46 lines (35 loc) · 1000 Bytes
/
job.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package stepper
import (
"context"
"time"
"github.com/robfig/cron/v3"
)
type Job struct {
Status string `json:"status"`
Name string `json:"name"`
Pattern string `json:"pattern"`
NextLaunchAt time.Time `json:"naxtLaunchAt"`
EngineContext context.Context `json:"-"`
}
func (j *Job) CalculateNextLaunch() error {
specParser := cron.NewParser(cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor)
schedule, err := specParser.Parse(j.Pattern)
if err != nil {
return err
}
j.NextLaunchAt = schedule.Next(time.Now())
return nil
}
type JobConfig struct {
Tags []string
Name string
Pattern string
}
func (c *JobConfig) NextLaunch() (time.Time, error) {
specParser := cron.NewParser(cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor)
schedule, err := specParser.Parse(c.Pattern)
if err != nil {
return time.Now(), err
}
return schedule.Next(time.Now()), nil
}