-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A few fixes/changes for the graceful shutdown example (#4)
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` or `SIGTERM`. `SIGTERM` is what's used on Heroku, but `SIGINT` is the standard signal from `Ctrl+C` in a terminal, so by respecting both we can have a program that 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 issuing `SIGKILL`. 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.
- Loading branch information
Showing
1 changed file
with
58 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters