forked from fixate/cron-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (59 loc) · 1.31 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"log"
"os"
"github.com/fixate/cron-service/cron"
mfst "github.com/fixate/cron-service/manifest"
"github.com/urfave/cli"
//"net/http"
//_ "net/http/pprof"
)
const version string = "0.2.0"
func main() {
//go func() {
//log.Println(http.ListenAndServe("localhost:6060", nil))
//}()
app := cli.NewApp()
app.Name = "Cron service"
app.Version = version
app.Usage = "Add a cron yaml file to trigger time-based events"
app.EnableBashCompletion = true
app.Action = run
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "ensure-topics-created",
Usage: "Create pubsub topics if they don't exist",
},
cli.StringFlag{
Name: "project-id",
Usage: "project id",
EnvVar: "CRON_GOOG_PROJECT_ID",
},
cli.StringFlag{
Name: "credentials-file",
Usage: "Service account or refresh token JSON credentials file",
EnvVar: "CRON_CREDENTIALS_FILE",
},
cli.StringFlag{
Name: "m, manifest-path",
Usage: "cron.yaml manifest file",
EnvVar: "CRON_MANIFEST_PATH",
},
}
if err := app.Run(os.Args); err != nil {
log.Println("Fatal Error")
log.Fatal(err)
}
}
func run(c *cli.Context) error {
manifest, err := mfst.Load(c.String("manifest-path"))
if err != nil {
return err
}
err, crn := cron.New(c, manifest)
if err != nil {
return err
}
crn.Run()
return nil
}