-
Notifications
You must be signed in to change notification settings - Fork 46
/
key_message.go
40 lines (33 loc) · 993 Bytes
/
key_message.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
package cronworker
import "encoding/json"
// CronJobKey model
type CronJobKey struct {
JobName string `json:"jobName"`
Args string `json:"args"`
Interval string `json:"interval"`
}
// String implement stringer
func (c CronJobKey) String() string {
b, _ := json.Marshal(c)
return string(b)
}
// CreateCronJobKey helper
/*
Allowed interval:
* standard time duration string, example: 2s, 10m
* custom start time and repeat duration, example:
- 23:00@daily, will repeated at 23:00 every day
- 23:00@weekly, will repeated at 23:00 every week
- 23:00@10s, will repeated at 23:00 and next repeat every 10 seconds
*/
func CreateCronJobKey(jobName, args, interval string) string {
return CronJobKey{
JobName: jobName, Args: args, Interval: interval,
}.String()
}
// ParseCronJobKey helper
func ParseCronJobKey(str string) (jobName, args, interval string) {
var cronKey CronJobKey
json.Unmarshal([]byte(str), &cronKey)
return cronKey.JobName, cronKey.Args, cronKey.Interval
}