Adding convenience stopHandler() to reduce duplication when registering handlers for both SIGINT and SIGTERM
Updated examples to use stopHandler
Added unit tests
The motivation is easier integration with supervisor. If I start my decider like this
supervisor -- decider.js
using supervisor, and only register a handler for SIGINT, the process will get terminated immediately instead of waiting for the last long poll to complete.
Registering a handler for both SIGINT and SIGTERM fixes the issue, and seems like a good idea anyhow.
This PR just makes it a bit easier to register the handler twice and ensure that stop() is only called once. Although it doesn't matter at the moment if stop is called more than once, implementation details may change in the future. It also logs Stopping the poller after this request... only once.
In this commit:
stopHandler()
to reduce duplication when registering handlers for both SIGINT and SIGTERMThe motivation is easier integration with supervisor. If I start my decider like this
using supervisor, and only register a handler for
SIGINT
, the process will get terminated immediately instead of waiting for the last long poll to complete.Registering a handler for both
SIGINT
andSIGTERM
fixes the issue, and seems like a good idea anyhow.This PR just makes it a bit easier to register the handler twice and ensure that
stop()
is only called once. Although it doesn't matter at the moment if stop is called more than once, implementation details may change in the future. It also logsStopping the poller after this request...
only once.