beforeShutdown in example should return new Promise
peterkuiper opened this issue · comments
Should be:
function beforeShutdown () {
// given your readiness probes run every 5 second
// may be worth using a bigger number so you won't
// run into any race conditions
return new Promise(resolve => {
setTimeout(resolve, 5000)
})
}
terminus(server, {
beforeShutdown
})
or ES6:
const beforeShutdown = () => new Promise(resolve => setTimeout(resolve, 15000));
I'm also trying to figure out where beforeShutdown()
fits in. I have beforeShutdown
, onSignal
and onShutdown
set. beforeShutdown
is run before onSignal. I would expect:
onSignal
-> beforeShutdown
-> onShutdown
onSignal
would allow me to the actual logging (without a delay) and pre-cleanup steps that wouldn't interfere with serving traffic. I would then do my cleanup in beforeShutdown
so onShutdown
can be safely called.
Does this make sense?
@peterkuiper can you send a PR to fix the docs?
@gergelyke I will send the PR on monday. I'll also take a look at the examples, I think those also miss the 'new Promise'.
Cool, thanks a lot @peterkuiper!