Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enforce only one instance of an in-pod cronjob running at once #192

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions legacy/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,10 @@ do

if cronScheduleMoreOftenThan30Minutes "$CRONJOB_SCHEDULE_RAW" ; then
# If this cronjob is more often than 30 minutes, we run the cronjob inside the pod itself
# Lagoon enforces that only a single instance of a cronjob can run at any one time.
# https://man7.org/linux/man-pages/man1/flock.1.html
# https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion
CRONJOB_COMMAND="flock -n '/tmp/cron.lock.$(echo "$CRONJOB_COUNTER $CRONJOB_COMMAND" | sha256sum | awk '{ print $1 }')' -c ${CRONJOB_COMMAND@Q}"
CRONJOBS_ARRAY_INSIDE_POD+=("${CRONJOB_SCHEDULE} ${CRONJOB_COMMAND}")
else
# This cronjob runs less ofen than every 30 minutes, we create a kubernetes native cronjob for it.
Expand Down