Merge pull request #33 from wwwjfy/fix-shutdown-requested
Fix shutdown requested
This commit is contained in:
commit
23c68b42ff
2 changed files with 9 additions and 6 deletions
|
|
@ -55,6 +55,9 @@ func (srp *sampleRecordProcessor) Shutdown(reason string) error {
|
||||||
if reason == "TERMINATE" {
|
if reason == "TERMINATE" {
|
||||||
fmt.Fprintf(os.Stderr, "Was told to terminate, will attempt to checkpoint.\n")
|
fmt.Fprintf(os.Stderr, "Was told to terminate, will attempt to checkpoint.\n")
|
||||||
srp.checkpointer.Shutdown()
|
srp.checkpointer.Shutdown()
|
||||||
|
} else if reason == "SHUTDOWN_REQUESTED" {
|
||||||
|
fmt.Fprintf(os.Stderr, "Got shutdown requested, attempt to checkpoint.\n")
|
||||||
|
srp.checkpointer.Shutdown()
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(os.Stderr, "Shutting down due to failover. Will not checkpoint.\n")
|
fmt.Fprintf(os.Stderr, "Shutting down due to failover. Will not checkpoint.\n")
|
||||||
}
|
}
|
||||||
|
|
@ -62,11 +65,6 @@ func (srp *sampleRecordProcessor) Shutdown(reason string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
f, err := os.Create("/tmp/kcl_stderr")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
kclProcess := kcl.New(os.Stdin, os.Stdout, os.Stderr, newSampleRecordProcessor())
|
kclProcess := kcl.New(os.Stdin, os.Stdout, os.Stderr, newSampleRecordProcessor())
|
||||||
kclProcess.Run()
|
kclProcess.Run()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -238,8 +238,13 @@ func (kclp *KCLProcess) handleLine(line string) (string, error) {
|
||||||
case ActionShutdown:
|
case ActionShutdown:
|
||||||
kclp.ioHandler.writeError("Received shutdown action...")
|
kclp.ioHandler.writeError("Received shutdown action...")
|
||||||
|
|
||||||
|
reason := action.Reason
|
||||||
// Shutdown should block until it's safe to shutdown the process
|
// Shutdown should block until it's safe to shutdown the process
|
||||||
err = kclp.recordProcessor.Shutdown(action.Reason)
|
if action.Action == "shutdownRequested" {
|
||||||
|
reason = "SHUTDOWN_REQUESTED"
|
||||||
|
}
|
||||||
|
err = kclp.recordProcessor.Shutdown(reason)
|
||||||
|
|
||||||
if err != nil { // Log error and continue shutting down
|
if err != nil { // Log error and continue shutting down
|
||||||
kclp.ioHandler.writeError(fmt.Sprintf("ERR shutdown: %+#v", err))
|
kclp.ioHandler.writeError(fmt.Sprintf("ERR shutdown: %+#v", err))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue