Hi friends, I have a use case where I need to bring Ktor (Netty) server up with a single endpoint to expose metrics, run a long task and then bring the server down when it's done. How can I programmatically shutdown the server and exit after the task is complete?
b
Big Chungus
01/25/2023, 2:36 PM
Doesn't embeddedServer() work for you?
s
Srki Rakic
01/25/2023, 2:50 PM
It does for serving up the metrics, but it stays up after the task is complete. I need to bring the server down.
Srki Rakic
01/25/2023, 2:54 PM
oh, it looks like there's a
stop
function on the engine interface.
👍 1
Srki Rakic
01/25/2023, 2:54 PM
I'll try that.
d
Dominik Sandjaja
01/25/2023, 3:46 PM
Without having looked at the implementation: there is a shutdown endpoint feature. You could either use that to explicitly shut down the server after usage or have a look at the code to see how the server is actually shut down there.