mirror of
https://github.com/django-q2/django-q2.git
synced 2026-09-29 06:48:12 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31e82ad028 | ||
|
|
b66dfbd3af | ||
|
|
08baaab125 | ||
|
|
ce81059da8 |
@@ -2,6 +2,18 @@
|
|||||||
|
|
||||||
## [Unreleased](https://github.com/GDay/django-q2/tree/HEAD)
|
## [Unreleased](https://github.com/GDay/django-q2/tree/HEAD)
|
||||||
|
|
||||||
|
## [v1.4.9](https://github.com/GDay/django-q2/tree/v1.4.9) (2022-12-22)
|
||||||
|
|
||||||
|
**Merged pull requests:**
|
||||||
|
|
||||||
|
- Fix DST timezone change (move from DST to normal jump) https://github.com/GDay/django-q2/pull/56
|
||||||
|
|
||||||
|
## [v1.4.8](https://github.com/GDay/django-q2/tree/v1.4.8) (2022-12-21)
|
||||||
|
|
||||||
|
**Merged pull requests:**
|
||||||
|
|
||||||
|
- Fix: allow both ZoneInfo and Pytz depending on django version https://github.com/GDay/django-q2/pull/55
|
||||||
|
|
||||||
## [v1.4.7](https://github.com/GDay/django-q2/tree/v1.4.7) (2022-12-21)
|
## [v1.4.7](https://github.com/GDay/django-q2/tree/v1.4.7) (2022-12-21)
|
||||||
|
|
||||||
**Merged pull requests:**
|
**Merged pull requests:**
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import django
|
import django
|
||||||
|
|
||||||
VERSION = (1, 4, 7)
|
VERSION = (1, 4, 9)
|
||||||
|
|
||||||
if django.VERSION < (3, 2):
|
if django.VERSION < (3, 2):
|
||||||
default_app_config = "django_q.apps.DjangoQConfig"
|
default_app_config = "django_q.apps.DjangoQConfig"
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import socket
|
|||||||
import traceback
|
import traceback
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from pytz import timezone as pytz_timezone
|
|
||||||
from multiprocessing import Event, Process, Value, current_process
|
from multiprocessing import Event, Process, Value, current_process
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
|||||||
+2
-7
@@ -255,13 +255,8 @@ class Schedule(models.Model):
|
|||||||
# based on DST active or not
|
# based on DST active or not
|
||||||
extra_diff = (new_next_run - current_next_run) - add
|
extra_diff = (new_next_run - current_next_run) - add
|
||||||
|
|
||||||
# if we have one positive hour difference, then subtract it, so we are even
|
# subtract difference
|
||||||
# and vice versa. In most cases, this will be 0, as there won't be a
|
next_run -= extra_diff
|
||||||
# timezone diff
|
|
||||||
if extra_diff > timedelta(hours=0):
|
|
||||||
next_run -= extra_diff
|
|
||||||
else:
|
|
||||||
next_run += extra_diff
|
|
||||||
|
|
||||||
return next_run
|
return next_run
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import os
|
import os
|
||||||
import pytz
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from multiprocessing import Event, Value
|
from multiprocessing import Event, Value
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import django
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
@@ -24,6 +24,15 @@ from django_q.tests.testing_utilities.multiple_database_routers import (
|
|||||||
)
|
)
|
||||||
from django_q.utils import add_months
|
from django_q.utils import add_months
|
||||||
|
|
||||||
|
if django.VERSION < (4, 0):
|
||||||
|
# pytz is the default in django 3.2. Remove when no support for 3.2
|
||||||
|
from pytz import timezone as ZoneInfo
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
|
except ImportError:
|
||||||
|
from backports.zoneinfo import ZoneInfo
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def broker(monkeypatch) -> Broker:
|
def broker(monkeypatch) -> Broker:
|
||||||
@@ -90,7 +99,7 @@ def test_scheduler_daylight_saving_time_daily(broker, monkeypatch):
|
|||||||
# 28th of March 2021 is the day when sunlight saving starts (at 2 am)
|
# 28th of March 2021 is the day when sunlight saving starts (at 2 am)
|
||||||
|
|
||||||
monkeypatch.setattr(Conf, "TIME_ZONE", "Europe/Amsterdam")
|
monkeypatch.setattr(Conf, "TIME_ZONE", "Europe/Amsterdam")
|
||||||
tz = pytz.timezone('Europe/Amsterdam')
|
tz = ZoneInfo('Europe/Amsterdam')
|
||||||
broker.list_key = "scheduler_test:q"
|
broker.list_key = "scheduler_test:q"
|
||||||
# Let's start a schedule at 1 am on the 27th of March. This is in AMS timezone.
|
# Let's start a schedule at 1 am on the 27th of March. This is in AMS timezone.
|
||||||
# So, 2021-03-27 00:00:00 when saved (due to TZ being Amsterdam and saved in UTC)
|
# So, 2021-03-27 00:00:00 when saved (due to TZ being Amsterdam and saved in UTC)
|
||||||
@@ -140,6 +149,52 @@ def test_scheduler_daylight_saving_time_daily(broker, monkeypatch):
|
|||||||
next_run = next_run.astimezone(tz)
|
next_run = next_run.astimezone(tz)
|
||||||
assert str(next_run) == "2021-03-30 01:00:00+02:00"
|
assert str(next_run) == "2021-03-30 01:00:00+02:00"
|
||||||
|
|
||||||
|
# Create second schedule with the next run date on the start date. It will move
|
||||||
|
# one day forward when we run the scheduler
|
||||||
|
start_date = datetime(2021, 10, 29, 1, 0, 0)
|
||||||
|
schedule = create_schedule(
|
||||||
|
"django_q.tests.tasks.word_multiply",
|
||||||
|
2,
|
||||||
|
name="multiply",
|
||||||
|
schedule_type=Schedule.DAILY,
|
||||||
|
next_run=start_date,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run scheduler so we get the next run date
|
||||||
|
scheduler(broker=broker)
|
||||||
|
schedule.refresh_from_db()
|
||||||
|
|
||||||
|
next_run = schedule.next_run
|
||||||
|
|
||||||
|
assert str(next_run) == "2021-10-29 23:00:00+00:00"
|
||||||
|
# In the Amsterdam timezone, it's 1 hour over midnight (+02)
|
||||||
|
next_run = next_run.astimezone(tz)
|
||||||
|
assert str(next_run) == "2021-10-30 01:00:00+02:00"
|
||||||
|
|
||||||
|
# Run scheduler so we get the next run date
|
||||||
|
scheduler(broker=broker)
|
||||||
|
schedule.refresh_from_db()
|
||||||
|
|
||||||
|
next_run = schedule.next_run
|
||||||
|
|
||||||
|
assert str(next_run) == "2021-10-30 23:00:00+00:00"
|
||||||
|
# In the Amsterdam timezone, it's 1 hour over midnight (+02)
|
||||||
|
next_run = next_run.astimezone(tz)
|
||||||
|
assert str(next_run) == "2021-10-31 01:00:00+02:00"
|
||||||
|
|
||||||
|
# Run scheduler so we get the next run date
|
||||||
|
scheduler(broker=broker)
|
||||||
|
schedule.refresh_from_db()
|
||||||
|
|
||||||
|
next_run = schedule.next_run
|
||||||
|
|
||||||
|
assert str(next_run) == "2021-11-01 00:00:00+00:00"
|
||||||
|
# In the Amsterdam timezone, it's 1 hour over midnight (+01)
|
||||||
|
# Switch of DST
|
||||||
|
next_run = next_run.astimezone(tz)
|
||||||
|
assert str(next_run) == "2021-11-01 01:00:00+01:00"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_scheduler(broker, monkeypatch):
|
def test_scheduler(broker, monkeypatch):
|
||||||
|
|||||||
+19
-2
@@ -1,14 +1,24 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import pytz
|
|
||||||
import calendar
|
import calendar
|
||||||
import inspect
|
import inspect
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
|
import django
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from django_q.conf import Conf
|
from django_q.conf import Conf
|
||||||
|
|
||||||
|
if django.VERSION < (4, 0):
|
||||||
|
# pytz is the default in django 3.2. Remove when no support for 3.2
|
||||||
|
from pytz import timezone as ZoneInfo
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
|
except ImportError:
|
||||||
|
from backports.zoneinfo import ZoneInfo
|
||||||
|
|
||||||
|
|
||||||
# credits: https://stackoverflow.com/a/4131114
|
# credits: https://stackoverflow.com/a/4131114
|
||||||
# Made them aware of timezone
|
# Made them aware of timezone
|
||||||
def add_months(d, months):
|
def add_months(d, months):
|
||||||
@@ -50,7 +60,14 @@ def get_func_repr(func):
|
|||||||
def localtime(value=None) -> datetime:
|
def localtime(value=None) -> datetime:
|
||||||
"""Override for timezone.localtime to deal with naive times and local times"""
|
"""Override for timezone.localtime to deal with naive times and local times"""
|
||||||
if settings.USE_TZ:
|
if settings.USE_TZ:
|
||||||
return timezone.localtime(value=value, timezone=pytz.timezone(Conf.TIME_ZONE))
|
if django.VERSION >= (4, 0) and settings.USE_DEPRECATED_PYTZ:
|
||||||
|
import pytz
|
||||||
|
|
||||||
|
convert_to_tz = pytz.timezone(Conf.TIME_ZONE)
|
||||||
|
else:
|
||||||
|
convert_to_tz = ZoneInfo(Conf.TIME_ZONE)
|
||||||
|
|
||||||
|
return timezone.localtime(value=value, timezone=convert_to_tz)
|
||||||
if value is None:
|
if value is None:
|
||||||
return datetime.now()
|
return datetime.now()
|
||||||
else:
|
else:
|
||||||
|
|||||||
+1
-1
@@ -75,7 +75,7 @@ author = "Ilan Steemers, Stan Triepels"
|
|||||||
# The short X.Y version.
|
# The short X.Y version.
|
||||||
version = "1.4"
|
version = "1.4"
|
||||||
# The full version, including alpha/beta/rc tags.
|
# The full version, including alpha/beta/rc tags.
|
||||||
release = "1.4.7"
|
release = "1.4.9"
|
||||||
|
|
||||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||||
# for a list of supported languages.
|
# for a list of supported languages.
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "django-q2"
|
name = "django-q2"
|
||||||
version = "1.4.7"
|
version = "1.4.9"
|
||||||
packages = [
|
packages = [
|
||||||
{ include = "django_q" },
|
{ include = "django_q" },
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user