what is a good way to add a shutdownhook to ktor a...
# ktor
s
what is a good way to add a shutdownhook to ktor application? In my understanding, since Runtime.getRuntime().addShutdownHook requires you to use thread directly, it is not recommended.
z
there is a plugin for it
s
i think shutdown-url is different from what i am looking for. Shutdown url provides an endpoint which when invoked, shut downs the server. I am looking for a way to run a piece of task when server is about to shut down.
z
ah
Application.environment.monitor.subscribe()
There are a few environment lifecycle hooks exposed by ktor, but i had a bit of trouble with it
there's a page about it in the ktor docs somewhere
a
You can use the ApplicationEngine.addShutdownHook method.
287 Views