Add before_shutdown_tick hook.

Add after_shutdown_tick hook.
This commit is contained in:
Azareal 2021-05-03 20:50:01 +10:00
parent 7a12751e4d
commit 16e86a9123
2 changed files with 12 additions and 5 deletions

View File

@ -243,6 +243,8 @@ var taskHooks = map[string][]func() error{
"after_second_tick": nil, "after_second_tick": nil,
"before_fifteen_minute_tick": nil, "before_fifteen_minute_tick": nil,
"after_fifteen_minute_tick": nil, "after_fifteen_minute_tick": nil,
"before_shutdown_tick": nil,
"after_shutdown_tick": nil,
} }
// Coming Soon: // Coming Soon:

15
main.go
View File

@ -438,12 +438,10 @@ func main() {
buildTemplates := flag.Bool("build-templates", false, "build the templates") buildTemplates := flag.Bool("build-templates", false, "build the templates")
flag.Parse() flag.Parse()
if *buildTemplates { if *buildTemplates {
err = c.CompileTemplates() if err = c.CompileTemplates(); err != nil {
if err != nil {
log.Fatal(err) log.Fatal(err)
} }
err = c.CompileJSTemplates() if err = c.CompileJSTemplates(); err != nil {
if err != nil {
log.Fatal(err) log.Fatal(err)
} }
return return
@ -453,7 +451,6 @@ func main() {
if err != nil { if err != nil {
log.Fatalf("%+v", err) log.Fatalf("%+v", err)
} }
err = c.VerifyConfig() err = c.VerifyConfig()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -600,8 +597,16 @@ func main() {
sig := <-sigs sig := <-sigs
log.Print("Received a signal to shutdown: ", sig) log.Print("Received a signal to shutdown: ", sig)
// TODO: Gracefully shutdown the HTTP server // 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() c.Tasks.Shutdown.Run()
log.Print("Ran shutdown tasks") 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") c.StoppedServer("Stopped server")
}() }()