Skip to content

Fix Cron periodic work to run at the beginning of each minute. #205

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

Merged
merged 1 commit into from
Feb 9, 2024

Conversation

dukhlov
Copy link

@dukhlov dukhlov commented Feb 8, 2024

In previous implementation, initially invocation time is aligned to the of the first minute, but eventually 1-minute period can flow because of local clock inaccuracy. This commit fixes this by dynamic calculation of delay before execution.

Details:
PeriodicWork uses java.util.concurrent.ScheduledThreadPoolExecutor.scheduleAtFixedRate, which uses java.lang.System.nanoTime() to determine time elapsed. It does not strictly correlate with wall-clock time. In case we faced with, Cron periodic work became running at 59 second of each minute (our machine's clock is late) and sometimes some jobs became skip triggering

Testing done

### Submitter checklist
- [ ] Make sure you are opening from a **topic/feature/bugfix branch** (right side) and not your main branch!
- [ ] Ensure that the pull request title represents the desired changelog entry
- [ ] Please describe what you did
- [ ] Link to relevant issues in GitHub or Jira
- [ ] Link to relevant pull requests, esp. upstream and downstream changes
- [ ] Ensure you have provided tests - that demonstrates feature works or fixes the issue

In previous implementation, initially invocation time is aligned to the of the first minute, but eventually 1-minute period can flow because of local clock inaccuracy. This commit fixes this by dynamic calculation of delay before execution.
@res0nance res0nance added the bug label Feb 9, 2024
@res0nance res0nance merged commit cd2deb2 into jenkinsci:master Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants