Skip to content

Conversation

@alirafiei75
Copy link
Contributor

This PR enhances the DatabaseScheduler's crontab exclusion logic to properly handle tasks with different timezone settings. The scheduler now correctly converts between timezones when determining which tasks to include in the schedule, making the scheduler more efficient by only loading tasks that might be due soon regardless of their timezone configuration.

@codecov
Copy link

codecov bot commented Apr 25, 2025

Codecov Report

Attention: Patch coverage is 91.22807% with 5 lines in your changes missing coverage. Please review.

Project coverage is 88.07%. Comparing base (cf04a7b) to head (9eae52a).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
django_celery_beat/schedulers.py 89.36% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #879      +/-   ##
==========================================
- Coverage   88.08%   88.07%   -0.02%     
==========================================
  Files          32       32              
  Lines         965     1006      +41     
  Branches      100      104       +4     
==========================================
+ Hits          850      886      +36     
- Misses         98      101       +3     
- Partials       17       19       +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.

@cclauss

This comment was marked as outdated.

This comment was marked as outdated.

@auvipy auvipy requested a review from Copilot April 26, 2025 07:44

This comment was marked as outdated.

@alirafiei75
Copy link
Contributor Author

@auvipy
@Azurency

  1. I have added a force logic to schedule property to force all_as_schedule to run if there was no change each 5 minutes
  2. The server time was also wrong and I wrote a utility function that returns timezone.now() if USE_TZ is True and else returns an aware datetime with the timezone of the django project.

@Azurency
Copy link

@auvipy @Azurency

  1. I have added a force logic to schedule property to force all_as_schedule to run if there was no change each 5 minutes
  2. The server time was also wrong and I wrote a utility function that returns timezone.now() if USE_TZ is True and else returns an aware datetime with the timezone of the django project.

Nice, this seems great 👍. Working as expected with theses changes on my end.
Just a detail for consistency I would also use SCHEDULE_SYNC_MAX_INTERVAL in next_five_minutes = now() + datetime.timedelta(minutes=5) to prevent any changes to SCHEDULE_SYNC_MAX_INTERVAL to break the query (maybe it would be nice in the future to add a way to configure this max interval).

@auvipy
Copy link
Member

auvipy commented Apr 30, 2025

Just a detail for consistency I would also use SCHEDULE_SYNC_MAX_INTERVAL in next_five_minutes = now() + datetime.timedelta(minutes=5) to prevent any changes to SCHEDULE_SYNC_MAX_INTERVAL to break the query (maybe it would be nice in the future to add a way to configure this max interval).

it would be nice to have part of this addressed, specially the check

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

      # Current hour tasks in different timezones should not be excluded
  assert task_utc_current.id not in excluded_tasks, (
          "UTC current hour task should be included"
      )

E AssertionError: UTC current hour task should be included
E assert 13 not in {8, 9, 10, 11, 12, 13, ...}
E + where 13 = <PeriodicTask: utc-current-hour: * 8 * * * (m/h/dM/MY/d) UTC>.id

t/unit/test_schedulers.py:1125: AssertionError

@alirafiei75
Copy link
Contributor Author

      # Current hour tasks in different timezones should not be excluded
  assert task_utc_current.id not in excluded_tasks, (
          "UTC current hour task should be included"
      )

E AssertionError: UTC current hour task should be included E assert 13 not in {8, 9, 10, 11, 12, 13, ...} E + where 13 = <PeriodicTask: utc-current-hour: * 8 * * * (m/h/dM/MY/d) UTC>.id

t/unit/test_schedulers.py:1125: AssertionError

The issue was with the mock aware now not being applied. I have resolved it.

@alirafiei75 alirafiei75 requested review from Azurency and auvipy April 30, 2025 07:51
Copy link

@Azurency Azurency left a comment

Choose a reason for hiding this comment

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

This looks fine 👍

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.

7 participants