From 16e86a9123c0b22b13a3f2d3ce271b78ab59e360 Mon Sep 17 00:00:00 2001 From: Azareal Date: Mon, 3 May 2021 20:50:01 +1000 Subject: [PATCH] Add before_shutdown_tick hook. Add after_shutdown_tick hook. --- common/extend.go | 2 ++ main.go | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/common/extend.go b/common/extend.go index 2316250c..787a9f59 100644 --- a/common/extend.go +++ b/common/extend.go @@ -243,6 +243,8 @@ var taskHooks = map[string][]func() error{ "after_second_tick": nil, "before_fifteen_minute_tick": nil, "after_fifteen_minute_tick": nil, + "before_shutdown_tick": nil, + "after_shutdown_tick": nil, } // Coming Soon: diff --git a/main.go b/main.go index 5f3d1385..c59560ec 100644 --- a/main.go +++ b/main.go @@ -438,12 +438,10 @@ func main() { buildTemplates := flag.Bool("build-templates", false, "build the templates") flag.Parse() if *buildTemplates { - err = c.CompileTemplates() - if err != nil { + if err = c.CompileTemplates(); err != nil { log.Fatal(err) } - err = c.CompileJSTemplates() - if err != nil { + if err = c.CompileJSTemplates(); err != nil { log.Fatal(err) } return @@ -453,7 +451,6 @@ func main() { if err != nil { log.Fatalf("%+v", err) } - err = c.VerifyConfig() if err != nil { log.Fatal(err) @@ -600,8 +597,16 @@ func main() { sig := <-sigs log.Print("Received a signal to shutdown: ", sig) // TODO: Gracefully shutdown the HTTP server + if e := runHook("before_shutdown_tick"); e != nil { + log.Print("before_shutdown_tick err:", e) + } + log.Print("Running shutdown tasks") c.Tasks.Shutdown.Run() log.Print("Ran shutdown tasks") + if e := runHook("after_shutdown_tick"); e != nil { + log.Print("after_shutdown_tick err:", e) + } + log.Print("Stopping server") c.StoppedServer("Stopped server") }()