Skip to content

Conversation

@FrederikBolding
Copy link
Member

Fixes two issues with the CronjobController. We were double scheduling events that had not run since last boot since #execute also schedules the next call. Additionally we were not correctly scheduling events that run for longer than 24 hours, since the daily timer would re-calculate the execution date every day.

@FrederikBolding FrederikBolding requested a review from a team as a code owner August 6, 2025 12:25
// immediately.
if (event.recurring && eventDate <= now) {
this.#execute(event);
return;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this we would schedule after execution AND schedule below


// If the existing event has not passed, start the timer.
if (eventDate >= now) {
this.#startTimer(event);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this we would ALWAYS reschedule cronjobs, even if their current date was valid

cronjobController.destroy();
});

it('handles scheduled event close to current time gracefully', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a good way to test this anymore since I eliminated the state update I relied on to replicate the race condition

expect(handleRequest).toHaveBeenCalledTimes(1);

secondCronjobController.init();
jest.advanceTimersByTime(inMilliseconds(26, Duration.Hour));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test did not seem to do what the title says, I re-used it to ensure that both of the fixes in this PR work

cursor[bot]

This comment was marked as outdated.

@codecov
Copy link

codecov bot commented Aug 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.28%. Comparing base (a9f5d76) to head (3f011db).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3561      +/-   ##
==========================================
- Coverage   98.29%   98.28%   -0.02%     
==========================================
  Files         417      417              
  Lines       11759    11764       +5     
  Branches     1827     1829       +2     
==========================================
+ Hits        11559    11562       +3     
- Misses        200      202       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Mrtenz
Mrtenz previously approved these changes Aug 6, 2025
@FrederikBolding FrederikBolding added this pull request to the merge queue Aug 6, 2025
Merged via the queue into main with commit 29b393e Aug 6, 2025
119 of 120 checks passed
@FrederikBolding FrederikBolding deleted the fb/fix-cronjob-bugs branch August 6, 2025 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants