On Tue, 30 Jun 2015 18:31:06 +0200, Marc Schütz wrote:
Is there a clean way to shut down a vibe.d app?
vibe.core.core.exitEventLoop() seems to simply exit the event loop,
which means that unfinished HTTP requests will be aborted, right?I also see vibe.core.core.setIdleHandler() which could be useful, but
again, how do I tell vibe.d not to accept new requests?I would like to use this for a SIGHUP handler for reopening log files
after logrotate, or reloading the configuration.
listenHTTP
now returns a HTTPListener
that has a method stopListening()
, which could be used for this purpose. Then, if everything would work correctly, as soon as all tasks have finished, the event loop should automatically exit. Unfortunately this is still not the case.
To do this manually as a workaround, something like this should work:
Router s_router;
int s_activeRequestCount = 0;
HTTPServerListener s_listener;
bool s_exit;
void countRequestsWrapper(HTTPServerRequest req, HTTPServerResponse res)
{
s_activeRequestCount++;
scope (exit) {
if (!--s_activeRequestCount && s_exit)
exitEventLoop();
}
s_router.handleRequest(req, res);
}
void exitCleanly()
{
if (!s_activeRequestCount) exitEventLoop();
else {
s_listener.stopListening();
s_exit = true;
}
}
static this()
{
s_router = new URLRouter;
// ...
s_listener = listenHTTP(settings, &countRequestsWrapper);
}