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

Ensure only one copy of a cronjob can run at a time #172

Open
smlx opened this issue May 5, 2021 · 2 comments · May be fixed by uselagoon/build-deploy-tool#192
Open

Ensure only one copy of a cronjob can run at a time #172

smlx opened this issue May 5, 2021 · 2 comments · May be fixed by uselagoon/build-deploy-tool#192
Labels
enhancement New feature or request

Comments

@smlx
Copy link
Member

smlx commented May 5, 2021

/lagoon/entrypoints.sh sh -c "$@"

To avoid issues with cronjobs piling up we should use flock here. Something like this (untested):

/lagoon/entrypoints.sh flock -n "/tmp/cron.lock.$(echo "$@" | sha256sum | awk '{ print $1 }')" sh -c "$@"
@smlx smlx added the enhancement New feature or request label May 5, 2021
@seanhamlin
Copy link
Contributor

seanhamlin commented May 6, 2021

I like this idea a lot. It gets Lagoon to address the concurrency issue, rather than requiring all codebases do it. Additional thoughts:

  • A sha256 looks like e4206b8e5676ba55d13203d06fe9004ff1e2bb848d74d0c7daac1ea0cafdf30b (for example), this is far too long, likely you can just pick the first 8 chars and be happy
$ echo "$command" | sha256sum | awk '{ print $1 }'
e4206b8e5676ba55d13203d06fe9004ff1e2bb848d74d0c7daac1ea0cafdf30b

$ echo "$command" | sha256sum | awk '{ print $1 }' | cut -c 1-8
e4206b8e
  • the lock file should end in .lock, so it is more obvious what it is
  • run flock with the argument --verbose so lock failures are obvious

So perhaps:

/lagoon/entrypoints.sh flock --verbose -n /tmp/cron-$(echo "$@" | sha256sum | awk '{ print $1 }' | cut -c 1-8).lock sh -c "$@"

@smlx
Copy link
Member Author

smlx commented May 10, 2021

thanks for the feedback 😄

A sha256 looks like e4206b8e5676ba55d13203d06fe9004ff1e2bb848d74d0c7daac1ea0cafdf30b (for example), this is far too long, likely you can just pick the first 8 chars and be happy

I'm not sure about this. it's only every meant to be machine readable and there doesn't seem to be much point in adding another command to the pipeline for aesthetics.

the lock file should end in .lock, so it is more obvious what it is

I'm not sure I understand this. The file already is named cron.lock.*?

run flock with the argument --verbose so lock failures are obvious

Unfortunately this is GNU specific. Busybox flock (that alpine uses) doesn't have this flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants