File tree Expand file tree Collapse file tree 2 files changed +30
-7
lines changed Expand file tree Collapse file tree 2 files changed +30
-7
lines changed Original file line number Diff line number Diff line change 23
23
from kombu .utils .json import dumps , loads
24
24
25
25
from .clockedschedule import clocked
26
- from .models import (ClockedSchedule , CrontabSchedule , IntervalSchedule ,
27
- PeriodicTask , PeriodicTasks , SolarSchedule )
26
+ from .models import (
27
+ ClockedSchedule ,
28
+ CrontabSchedule ,
29
+ IntervalSchedule ,
30
+ PeriodicTask ,
31
+ PeriodicTasks ,
32
+ SolarSchedule ,
33
+ )
28
34
from .utils import NEVER_CHECK_TIMEOUT , aware_now , now
29
35
30
36
# This scheduler must wake up more frequently than the
@@ -340,7 +346,7 @@ def _get_crontab_exclude_query(self):
340
346
+ 24
341
347
) % 24
342
348
)
343
- for timezone_name in self ._get_unique_timezone_names ()
349
+ for timezone_name in self ._get_unique_timezones ()
344
350
],
345
351
# Default case - use hour as is
346
352
default = F ('hour_int' )
@@ -359,11 +365,11 @@ def _get_crontab_exclude_query(self):
359
365
360
366
return exclude_query
361
367
362
- def _get_unique_timezone_names (self ):
368
+ def _get_unique_timezones (self ):
363
369
"""Get a list of all unique timezone names used in CrontabSchedule"""
364
- return CrontabSchedule . objects . values_list (
365
- 'timezone' , flat = True
366
- ). distinct ()
370
+ return list (
371
+ CrontabSchedule . objects . order_by ( 'timezone' ). distinct ( 'timezone' ). values_list ( 'timezone' , flat = True )
372
+ )
367
373
368
374
def _get_timezone_offset (self , timezone_name ):
369
375
"""
Original file line number Diff line number Diff line change @@ -1059,6 +1059,23 @@ def test_crontab_special_hour_four(self):
1059
1059
# The hour=4 task should never be excluded
1060
1060
assert task_hour_four .id not in excluded_tasks
1061
1061
1062
+ @pytest .mark .django_db
1063
+ def test_crontab_special_hour_four (self ):
1064
+ """
1065
+ Test that schedules with hour=4 are always included, regardless of
1066
+ the current time.
1067
+ """
1068
+ # Create 2 crontabs with same timezone, and 1 with different timezone
1069
+ CrontabSchedule .objects .create (hour = '4' , timezone = 'UTC' )
1070
+ CrontabSchedule .objects .create (hour = '4' , timezone = 'UTC' )
1071
+ CrontabSchedule .objects .create (hour = '4' , timezone = 'America/New_York' )
1072
+
1073
+ # Run the scheduler's exclusion logic
1074
+ timezones = self .s ._get_unique_timezones ()
1075
+
1076
+ assert len (timezones ) == 2
1077
+ assert set (timezones ) == {ZoneInfo ('UTC' ), ZoneInfo ('America/New_York' )}
1078
+
1062
1079
@pytest .mark .django_db
1063
1080
@patch ('django_celery_beat.schedulers.aware_now' )
1064
1081
@patch ('django.utils.timezone.get_current_timezone' )
You can’t perform that action at this time.
0 commit comments