forked from libi/dcron
/
tools.go
38 lines (32 loc) · 792 Bytes
/
tools.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
package main
import (
"context"
"flag"
examplesCommon "github.com/BugKillerPro/dcron/examples/common"
"github.com/go-redis/redis/v8"
)
var (
addr = flag.String("addr", "127.0.0.1:6379", "redis addr")
pwd = flag.String("pwd", "123456", "redis password")
key = flag.String("key", "key", "stable job key")
)
func Store(cli *redis.Client, jobName string, job *examplesCommon.ExecJob) {
b, _ := job.Serialize()
_ = cli.HSet(context.Background(), *key, jobName, b)
}
func main() {
flag.Parse()
opts := &redis.Options{
Addr: *addr,
Password: *pwd,
}
cli := redis.NewClient(opts)
Store(cli, "job1", &examplesCommon.ExecJob{
Cron: "@every 10s",
Command: "date",
})
Store(cli, "job2", &examplesCommon.ExecJob{
Cron: "15 * * * * *",
Command: "df -h",
})
}