Reputation: 339
I am running a http4s server using a blaze backend with cats-effect IO effects. I have an event logger that collects events and periodically flushes them to persistent storage. I'm wanting to ensure that any events in the queue are flushed before shutdown on SIGTERM.
I've tried
sys.ShutdownHookThread {
println("Flushing Event Reporter")
IO(flush).unsafeRunSync()
}
and this doesn't appear to run, possibly because the scaladoc for sys.ShutdownHookThread
states that it is "not guaranteed" to run.
My question is: is there a hook in cats or http4s that I can use instead?
I note that there is an open issue in blaze dating from 2018 about adding a graceful shutdown timer, but this doesn't help me insert the shutdown code into the server lifecycle.
Upvotes: 2
Views: 632