Skip to content

Commit

Permalink
Handle system termination signals (#152)
Browse files Browse the repository at this point in the history
Currently termination can only be forced (as the context that is used to determine cancellation is never actually cancelled). This PR closes the context on termination signals from the OS.

This should reduce the runtime of tests especially (as a significant amount of time is spent on waiting for workflows process to finish after a SIGTERM.
  • Loading branch information
erwinvaneyk authored Jun 9, 2018
1 parent 8e94732 commit dd6a148
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion cmd/fission-workflows-bundle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"

"github.com/fission/fission-workflows/cmd/fission-workflows-bundle/bundle"
"github.com/fission/fission-workflows/pkg/fes/backend/nats"
Expand All @@ -14,7 +17,21 @@ import (
)

func main() {
ctx := context.Background()
ctx, cancelFn := context.WithCancel(context.Background())
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGTERM)
go func() {
for sig := range c {
fmt.Println("Received signal: ", sig)
go func() {
time.Sleep(30 * time.Second)
fmt.Println("Deadline exceeded; forcing shutdown.")
os.Exit(0)
}()
cancelFn()
break
}
}()

cliApp := createCli()
cliApp.Action = func(c *cli.Context) error {
Expand Down

0 comments on commit dd6a148

Please sign in to comment.