magemojo / m2-ce-cron

Magento 2 cron project to fix bugs and common cron issues.
https://magemojo.com
MIT License
165 stars 45 forks source link

Cluster support - engine should keep running until current jobs are complete #129

Open JesKingDev opened 1 year ago

JesKingDev commented 1 year ago

Bug Description

If cluster support is enabled, and one server acquiesces in deference to the new server running crons, the currently running cron jobs could be killed if the server is stopped for some reason.

Ex. In a rolling deployment environment or in a Kubernetes CronJob, a new server/container instance may be started to take over the load. It's possible that the previous server/container running the cron will subsequently be killed by that process. If this happens, the previously running job threads could be abandoned and never observed to be completed.

Expected Behavior

When cluster support is enabled and the cron engine determines that it is no longer the leader/primary, it should not continue to start jobs, but it should also continue to monitor the jobs it has already started. Once all of that host's jobs have completed, the cron service should exit as normal.