From 91935a4f97d22ff1b537a0483c76c6de51c2bf92 Mon Sep 17 00:00:00 2001 From: Erick Hitter <git-contrib@ethitter.com> Date: Sun, 19 Aug 2018 12:30:22 -0700 Subject: [PATCH] Handle regular checks --- config-sample.json | 3 ++- glrdomon.go | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/config-sample.json b/config-sample.json index ed3c51e..21dfd60 100644 --- a/config-sample.json +++ b/config-sample.json @@ -2,5 +2,6 @@ "debug-dest": "os.Stdout", "debug": false, "api-key": "", - "threshold": 3600 + "threshold": 3600, + "schedule": "0 10 * * * *" } diff --git a/glrdomon.go b/glrdomon.go index 6b69772..2b36ed9 100644 --- a/glrdomon.go +++ b/glrdomon.go @@ -9,6 +9,8 @@ import ( "os/signal" "path/filepath" "syscall" + + "github.com/robfig/cron" ) type config struct { @@ -16,6 +18,7 @@ type config struct { Debug bool `json:"debug"` ApiKey string `json:"api-key"` Threshold int `json:"threshold"` + Schedule string `json:"schedule"` } var ( @@ -24,6 +27,9 @@ var ( logger *log.Logger debugDest string debug bool + + threshold int + schedule string ) func init() { @@ -48,6 +54,9 @@ func init() { debugDest = cfg.DebugDest debug = cfg.Debug + threshold = cfg.Threshold + schedule = cfg.Schedule + setUpLogger() } @@ -57,16 +66,35 @@ func main() { sig := make(chan os.Signal, 1) signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM) - // TODO: something! if debug { logger.Println("Test") } + if authenticate() { + startCron() + } else { + sig <- syscall.SIGTERM + } + caughtSig := <-sig logger.Printf("Stopping, got signal %s", caughtSig) } +func authenticate() bool { + return true +} + +func startCron() { + c := cron.New() + c.AddFunc(schedule, check) + c.Start() +} + +func check() { + logger.Println("Check!") +} + func setUpLogger() { logOpts := log.Ldate | log.Ltime | log.LUTC | log.Lshortfile -- GitLab