forked from cdrx/faktory_cron
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
46 lines (37 loc) · 917 Bytes
/
main.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 main
import (
"flag"
"github.com/robfig/cron"
)
var (
version = "master"
debug bool
config_path string
config *Config
scheduler *cron.Cron
)
func init() {
flag.StringVar(&config_path, "config", "./crontab.yaml", "path to the configuration file")
flag.BoolVar(&debug, "debug", false, "enable debug logs")
flag.Parse()
}
func main() {
configureLogging()
log.Infof("Cron for Faktory (version %s)", version)
log.Debugf("Reading config from file: %v", config_path)
config = NewConfig(config_path)
err := config.Update()
if err != nil {
log.Fatalf("Error in config: %v", err)
}
scheduler = cron.New()
for _, t := range config.Jobs {
log.Infof("Will run job %v every %v", t.Name, t.Schedule)
t.AddToScheduler()
}
log.Infof("Loaded %d scheduled tasks from %v", len(config.Jobs), config_path)
scheduler.Start()
defer scheduler.Stop()
// run forever
select {}
}