webdevops / go-crond

:alarm_clock: Cron daemon written in golang (for eg. usage in docker images)
GNU General Public License v2.0
123 stars 34 forks source link

Missing signal to jobs when receiving SIGTERM makes clean shutdown impossible #51

Open sztanpet opened 4 months ago

sztanpet commented 4 months ago

When trying to run cron jobs with go-crond from a container, and a new deployment happens, the container receives a SIGTERM to signal the request for termination. This causes go-crond to exit immediately, while all running jobs never receive a signal. The exit of go-crond signals openshift that the container shut down, terminating the container and all still-running jobs un-cleanly.

My expectation is: when go-crond receives SIGTERM it should send all running jobs the same SIGTERM and wait for them to exit, only then should go-crond exit. This would let the jobs exit cleanly.

sztanpet commented 4 months ago

quick/dirty/naive fix is to use the Context returned in https://github.com/webdevops/go-crond/blob/main/runner.go#L116 and wait until it finishes with <-ctx.Done()

it does not send signals to the cron jobs, but at least it waits for them to exit before go-crond exits itself