Skip to content
Snippets Groups Projects
Commit 91935a4f authored by Erick Hitter's avatar Erick Hitter
Browse files

Handle regular checks

parent 9b68510e
No related branches found
No related tags found
1 merge request!1Initial release
...@@ -2,5 +2,6 @@ ...@@ -2,5 +2,6 @@
"debug-dest": "os.Stdout", "debug-dest": "os.Stdout",
"debug": false, "debug": false,
"api-key": "", "api-key": "",
"threshold": 3600 "threshold": 3600,
"schedule": "0 10 * * * *"
} }
...@@ -9,6 +9,8 @@ import ( ...@@ -9,6 +9,8 @@ import (
"os/signal" "os/signal"
"path/filepath" "path/filepath"
"syscall" "syscall"
"github.com/robfig/cron"
) )
type config struct { type config struct {
...@@ -16,6 +18,7 @@ type config struct { ...@@ -16,6 +18,7 @@ type config struct {
Debug bool `json:"debug"` Debug bool `json:"debug"`
ApiKey string `json:"api-key"` ApiKey string `json:"api-key"`
Threshold int `json:"threshold"` Threshold int `json:"threshold"`
Schedule string `json:"schedule"`
} }
var ( var (
...@@ -24,6 +27,9 @@ var ( ...@@ -24,6 +27,9 @@ var (
logger *log.Logger logger *log.Logger
debugDest string debugDest string
debug bool debug bool
threshold int
schedule string
) )
func init() { func init() {
...@@ -48,6 +54,9 @@ func init() { ...@@ -48,6 +54,9 @@ func init() {
debugDest = cfg.DebugDest debugDest = cfg.DebugDest
debug = cfg.Debug debug = cfg.Debug
threshold = cfg.Threshold
schedule = cfg.Schedule
setUpLogger() setUpLogger()
} }
...@@ -57,16 +66,35 @@ func main() { ...@@ -57,16 +66,35 @@ func main() {
sig := make(chan os.Signal, 1) sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM) signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
// TODO: something!
if debug { if debug {
logger.Println("Test") logger.Println("Test")
} }
if authenticate() {
startCron()
} else {
sig <- syscall.SIGTERM
}
caughtSig := <-sig caughtSig := <-sig
logger.Printf("Stopping, got signal %s", caughtSig) 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() { func setUpLogger() {
logOpts := log.Ldate | log.Ltime | log.LUTC | log.Lshortfile logOpts := log.Ldate | log.Ltime | log.LUTC | log.Lshortfile
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment