diff --git a/mailroom.go b/mailroom.go index 2f4d0e779..c5ce78c51 100644 --- a/mailroom.go +++ b/mailroom.go @@ -201,10 +201,12 @@ func (mr *Mailroom) Stop() error { mr.batchForeman.Stop() mr.handlerForeman.Stop() mr.flowBatchForeman.Stop() - librato.Stop() close(mr.quit) mr.cancel() + time.Sleep(time.Second * time.Duration(mr.rt.Config.ShutdownToleranceTime)) + + librato.Stop() // stop our web server mr.webserver.Stop() diff --git a/runtime/config.go b/runtime/config.go index 67c65c430..d26f620f9 100644 --- a/runtime/config.go +++ b/runtime/config.go @@ -96,6 +96,8 @@ type Config struct { WhatsappSystemUserToken string `help:"WhatsApp system user token"` MetaWebhookURL string `help:"Meta webhook URL"` + + ShutdownToleranceTime int `help:"Shutdown tolerance time(in seconds)"` } // NewDefaultConfig returns a new default configuration object @@ -163,6 +165,8 @@ func NewDefaultConfig() *Config { WhatsappSystemUserToken: "", MetaWebhookURL: "https://graph.facebook.com/v21.0", + + ShutdownToleranceTime: 10, } }