From 03827a1a0c4603e5a125c2e05e3ebf6a41368967 Mon Sep 17 00:00:00 2001 From: Rafael Soares Date: Mon, 25 Nov 2024 17:03:50 -0300 Subject: [PATCH 1/2] add shutdown tolerance time to graceful stop http server listening --- mailroom.go | 2 ++ runtime/config.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/mailroom.go b/mailroom.go index 2f4d0e779..8edae2fcf 100644 --- a/mailroom.go +++ b/mailroom.go @@ -205,6 +205,8 @@ func (mr *Mailroom) Stop() error { close(mr.quit) mr.cancel() + time.Sleep(time.Second * time.Duration(mr.rt.Config.ShutdownToleranceTime)) + // 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, } } From d423ba8381df827fdd71a017d052a76fe7926a9c Mon Sep 17 00:00:00 2001 From: Rafael Soares Date: Wed, 4 Dec 2024 19:30:16 -0300 Subject: [PATCH 2/2] only stop librato after wait shutdown tolerance --- mailroom.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailroom.go b/mailroom.go index 8edae2fcf..c5ce78c51 100644 --- a/mailroom.go +++ b/mailroom.go @@ -201,12 +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()