implement graceful shutdown to webhook mode

ensures all pending tasks are finished before quit.
This commit is contained in:
Ronmi Ren 2025-01-13 16:39:06 +08:00
commit 6bae5d11c2
3 changed files with 172 additions and 133 deletions

View file

@ -70,7 +70,7 @@ is up to you, eg. Nginx, Apache, or even a simple Go server.
GitPass: token,
}
s, err := lib.UseWebhook(bind, cfg)
s, r, err := lib.UseWebhook(bind, cfg)
if err != nil {
fmt.Println("cannot create server: ", err)
return
@ -85,7 +85,11 @@ is up to you, eg. Nginx, Apache, or even a simple Go server.
defer stop()
fmt.Println("starting server")
httptask.Server(s, task.Timeout(10*time.Second)).Run(ctx)
task.Wait(
httptask.Server(s, task.Timeout(10*time.Second)),
r.Run,
).Run(ctx)
},
}