A few fixes/changes for the graceful shutdown example #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Follows up #2 with a few fixes/changes. As I was writing documentation
for graceful shutdown I realized there were a few things that weren't
quite ideal:
The job should return an error in the event of cancellation so that it
can be persisted as errored and be worked again.
The example now respects either
SIGINT
orSIGTERM
.SIGTERM
iswhat's used on Heroku, but
SIGINT
is the standard signal fromCtrl+C
in a terminal, so by respecting both we can have a programthat works well in either development or a common hosted environment.
Add a third phase in which the program initiates an unclean stop by
not waiting on stop any longer. This is probably something that most
programs should have because it's going to be reasonably easy to write
workers that accidentally don't respect context cancellation and get
stuck.
Add a 10 second timeout to each phase. This is for Heroku's benefit.
It'll send one
SIGTERM
and wait 30 seconds before issuingSIGKILL
.So the program here waits 10 seconds for a soft stop, another 10
seconds for a hard stop, and then exits uncleanly on its own volition
before getting
SIGKILL
ed.