-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Terminate gracefully on SIGTERM or SIGINT
We need to make sure we write the latest resume token when we exit so that we can resume next time we run. To make this more likely we will respond gracefully to SIGTERM and SIGINT so that we'll deplete the buffers, flush everything we got to the Cloudwatch Logs API and then write the final state to the state file before we exit. Previously we might not have done this correctly if we happened to get a signal during a write to cloudwatch, since cloudwatch would return to us a new token but we'd never get a chance to write it to the state file before we exit.
- Loading branch information
1 parent
5821423
commit eda7fc7
Showing
3 changed files
with
55 additions
and
3 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
) | ||
|
||
// MakeTerminateChannel returns a channel that will become readable if | ||
// the process is interrupted or terminated via a signal. | ||
// | ||
// This is used to gracefully exit the reader loop, which in turn causes | ||
// the rest of the program to gracefully terminate, flushing any remaining | ||
// buffers and writing its persistent state to disk. | ||
func MakeTerminateChannel() <-chan os.Signal { | ||
ch := make(chan os.Signal, 1) | ||
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM) | ||
return ch | ||
} |