Conversation
…hash BareJob.Hash was the only Hash implementation. Every job type embeds BareJob, so the promoted method only hashed Schedule, Name and Command, and dockerLabelsUpdate never replaced a job when labels such as user, container, tty or environment changed. The job kept running with stale values until Ofelia was restarted. Give each job type and each job config its own Hash so both job fields and middleware settings (no-overlap, save-*, slack-*, mail-*) are covered, and exclude the Docker client from RunJob/RunServiceJob hashes. Refs flywp/flywp-internal-tasks#82, mcuadros#471
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes flywp/flywp-internal-tasks#82 (upstream: mcuadros#471).
Problem
A running Ofelia ignores changes to a job's
user,container,tty,environment, etc. labels and keeps running the job with the old values until it is restarted.BareJob.Hash()is the onlyHash(); every job type embedsBareJob, so the promoted method only hashesSchedule,NameandCommand.dockerLabelsUpdateonly replaces a job when that hash changes.This fork is more exposed than upstream because the
Userdefault is""(container's user), so removing theuserlabel is the natural way to switch users, and that change was never picked up.Changes
core/:ExecJob,RunJob,RunServiceJobandLocalJobeach get their ownHash().RunJob.ClientandRunServiceJob.Clientare taggedhash:"-".cli/config.go: each*JobConfiggets aHash()over the whole config.dockerLabelsUpdatehashes these config types, so without this, middleware label changes (no-overlap,save-*,slack-*,mail-*) would still be missed. The fix proposed in the issue doesn't cover that.Tests
core/jobhash_test.go: field changes change the hash; the Docker client and runtime state don't.cli/docker_handler_test.go: loads jobs throughInitializeApp, then checks that 20 updates with unchanged labels (including environment/volume lists) keep the same jobs, and that removinguserand addingno-overlapare applied.core,cliandmiddlewaressuites pass.Live verification
On two servers (amd64 and arm64), I ran a throwaway container with job
id -uevery 5 s and recreated it withdocker rm -f+docker run. I ran three Ofelia builds side by side:user=nobodylabeluserlabel,--user 1000:1000user=nobodyagainWith this PR the job was replaced in place (deregister + register in the same millisecond).
Notes
containeris part of the hash. That's a misconfiguration; FlyWPwpcron-<id>names are unique.meghsh/ofelia:latestbut never re-pull it, so they need a pull + recreate ofofeliaafter this is published.