File tree Expand file tree Collapse file tree 2 files changed +35
-8
lines changed Expand file tree Collapse file tree 2 files changed +35
-8
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,17 @@ def _get_crontab_exclude_query(self):
359
365
360
366
return exclude_query
361
367
362
- def _get_unique_timezone_names (self ):
363
- """Get a list of all unique timezone names used in CrontabSchedule"""
364
- return CrontabSchedule .objects .values_list (
365
- 'timezone' , flat = True
366
- ).distinct ()
368
+ def _get_unique_timezones (self ):
369
+ """Get a list of all unique timezones used in CrontabSchedule"""
370
+ return list (
371
+ CrontabSchedule .objects .order_by (
372
+ 'timezone'
373
+ ).distinct (
374
+ 'timezone'
375
+ ).values_list (
376
+ 'timezone' , flat = True
377
+ )
378
+ )
367
379
368
380
def _get_timezone_offset (self , timezone_name ):
369
381
"""
Original file line number Diff line number Diff line change @@ -1059,6 +1059,21 @@ 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_get_unique_timezones (self ):
1064
+ """
1065
+ Test that get unique timezones returns a list of unique timezones
1066
+ """
1067
+ # Create 2 crontabs with same timezone, and 1 with different timezone
1068
+ CrontabSchedule .objects .create (hour = '4' , timezone = 'UTC' )
1069
+ CrontabSchedule .objects .create (hour = '4' , timezone = 'UTC' )
1070
+ CrontabSchedule .objects .create (hour = '4' , timezone = 'America/New_York' )
1071
+
1072
+ timezones = self .s ._get_unique_timezones ()
1073
+
1074
+ assert len (timezones ) == 2
1075
+ assert set (timezones ) == {ZoneInfo ('UTC' ), ZoneInfo ('America/New_York' )}
1076
+
1062
1077
@pytest .mark .django_db
1063
1078
@patch ('django_celery_beat.schedulers.aware_now' )
1064
1079
@patch ('django.utils.timezone.get_current_timezone' )
You can’t perform that action at this time.
0 commit comments