From 3ab299e8f7d46fc95a22ac1a0cf823b1e7d8b009 Mon Sep 17 00:00:00 2001 From: Matthew Goss Date: Tue, 8 Oct 2024 21:16:43 +1100 Subject: [PATCH 01/19] fix for missing periodic task name in results --- django_celery_beat/admin.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/django_celery_beat/admin.py b/django_celery_beat/admin.py index 2c462656..a7db1e07 100644 --- a/django_celery_beat/admin.py +++ b/django_celery_beat/admin.py @@ -248,12 +248,13 @@ def run_tasks(self, request, queryset): ) return + headers = {'periodic_task_name':periodic_task_name} + task_ids = [ task.apply_async(args=args, kwargs=kwargs, queue=queue, - periodic_task_name=periodic_task_name) + headers=headers) if queue and len(queue) - else task.apply_async(args=args, kwargs=kwargs, - periodic_task_name=periodic_task_name) + else task.apply_async(args=args, kwargs=kwargs, headers=headers) for task, args, kwargs, queue, periodic_task_name in tasks ] tasks_run = len(task_ids) From a9a7490eb062ded3a51e75956651037883063259 Mon Sep 17 00:00:00 2001 From: Matthew Goss <30362690+ntindicator@users.noreply.github.com> Date: Fri, 11 Oct 2024 00:28:20 +1100 Subject: [PATCH 02/19] fix error in admin, add to scheduler headers,tests --- django_celery_beat/admin.py | 6 +++--- django_celery_beat/schedulers.py | 5 +++-- t/unit/test_schedulers.py | 17 +++++++++++++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/django_celery_beat/admin.py b/django_celery_beat/admin.py index a7db1e07..28ed3d67 100644 --- a/django_celery_beat/admin.py +++ b/django_celery_beat/admin.py @@ -248,13 +248,13 @@ def run_tasks(self, request, queryset): ) return - headers = {'periodic_task_name':periodic_task_name} task_ids = [ task.apply_async(args=args, kwargs=kwargs, queue=queue, - headers=headers) + headers={'periodic_task_name':periodic_task_name}) if queue and len(queue) - else task.apply_async(args=args, kwargs=kwargs, headers=headers) + else task.apply_async(args=args, kwargs=kwargs, + headers={'periodic_task_name':periodic_task_name}) for task, args, kwargs, queue, periodic_task_name in tasks ] tasks_run = len(task_ids) diff --git a/django_celery_beat/schedulers.py b/django_celery_beat/schedulers.py index 846b97a9..30b1ae76 100644 --- a/django_celery_beat/schedulers.py +++ b/django_celery_beat/schedulers.py @@ -77,8 +77,9 @@ def __init__(self, model, app=None): if getattr(model, 'expires_', None): self.options['expires'] = getattr(model, 'expires_') - self.options['headers'] = loads(model.headers or '{}') - self.options['periodic_task_name'] = model.name + headers = loads(model.headers or '{}') + headers['periodic_task_name'] = model.name + self.options['headers'] = headers self.total_run_count = model.total_run_count self.model = model diff --git a/t/unit/test_schedulers.py b/t/unit/test_schedulers.py index d070bb45..1dbc150f 100644 --- a/t/unit/test_schedulers.py +++ b/t/unit/test_schedulers.py @@ -130,8 +130,8 @@ def test_entry(self): assert e.options['exchange'] == 'foo' assert e.options['routing_key'] == 'cpu' assert e.options['priority'] == 1 - assert e.options['headers'] == {'_schema_name': 'foobar'} - assert e.options['periodic_task_name'] == m.name + assert e.options['headers']['_schema_name'] == 'foobar' + assert e.options['headers']['periodic_task_name'] == m.name right_now = self.app.now() m2 = self.create_model_interval( @@ -869,3 +869,16 @@ def test_run_tasks(self): assert len(self.request._messages._queued_messages) == 1 queued_message = self.request._messages._queued_messages[0].message assert queued_message == '2 tasks were successfully run' + + + @pytest.mark.timeout(5) + def test_run_task_headers(self, monkeypatch): + def mock_apply_async(*args, **kwargs): + self.captured_headers = kwargs.get('headers', {}) + + monkeypatch.setattr('celery.app.task.Task.apply_async', mock_apply_async) + ma = PeriodicTaskAdmin(PeriodicTask, self.site) + self.request = self.patch_request(self.request_factory.get('/')) + ma.run_tasks(self.request, PeriodicTask.objects.filter(id=self.m1.id)) + assert 'periodic_task_name' in self.captured_headers + assert self.captured_headers['periodic_task_name'] == self.m1.name From 3c2dfbbed6e60d194707c117fa3f9172e6e6fc41 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 14 Oct 2024 16:58:48 +0200 Subject: [PATCH 03/19] Add Python 3.13 to the testing (#813) * https://www.python.org/downloads/release/python-3130/ * https://pythoninsider.blogspot.com/2024/10/python-3130-final-released.html * https://devguide.python.org/versions/ * https://docs.djangoproject.com/en/stable/faq/install/#what-python-version-can-i-use-with-django --- .github/workflows/test.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 35747781..87db6bf7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,18 +13,20 @@ jobs: fail-fast: false matrix: # https://docs.djangoproject.com/en/stable/faq/install/#what-python-version-can-i-use-with-django django-version: ["3.2", "4.2", "5.0", "5.1"] - python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', 'pypy-3.10'] + python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', 'pypy-3.10'] exclude: - django-version: "3.2" python-version: "3.11" - django-version: "3.2" python-version: "3.12" - - django-version: "5.0" - python-version: "3.8" + - django-version: "3.2" + python-version: "3.13" + - django-version: "4.2" + python-version: "3.13" - django-version: "5.0" python-version: "3.9" - - django-version: "5.1" - python-version: "3.8" + - django-version: "5.0" + python-version: "3.13" - django-version: "5.1" python-version: "3.9" From ce728bd0ab3c77ceeb49f2768a9d9165cba2b1e2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 14 Oct 2024 19:34:25 +0200 Subject: [PATCH 04/19] [pre-commit.ci] pre-commit autoupdate (#814) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v3.17.0 → v3.18.0](https://github.com/asottile/pyupgrade/compare/v3.17.0...v3.18.0) - [github.com/adamchainz/django-upgrade: 1.21.0 → 1.22.1](https://github.com/adamchainz/django-upgrade/compare/1.21.0...1.22.1) - [github.com/tox-dev/pyproject-fmt: 2.2.4 → 2.3.0](https://github.com/tox-dev/pyproject-fmt/compare/2.2.4...2.3.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 66adc3df..3a6a94d4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ exclude: "migrations" repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.17.0 + rev: v3.18.0 hooks: - id: pyupgrade args: ["--py37-plus"] @@ -32,7 +32,7 @@ repos: - id: isort - repo: https://github.com/adamchainz/django-upgrade - rev: 1.21.0 + rev: 1.22.1 hooks: - id: django-upgrade args: [--target-version, "3.2"] @@ -44,7 +44,7 @@ repos: - id: ruff - repo: https://github.com/tox-dev/pyproject-fmt - rev: 2.2.4 + rev: 2.3.0 hooks: - id: pyproject-fmt From 9be2125a7360dc3c75c43ad720d1c6c3a57ccc78 Mon Sep 17 00:00:00 2001 From: Matthew Goss <30362690+ntindicator@users.noreply.github.com> Date: Tue, 15 Oct 2024 12:50:06 +1100 Subject: [PATCH 05/19] formatting changes --- django_celery_beat/admin.py | 16 +++++++++++----- t/unit/test_schedulers.py | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/django_celery_beat/admin.py b/django_celery_beat/admin.py index 28ed3d67..89db3757 100644 --- a/django_celery_beat/admin.py +++ b/django_celery_beat/admin.py @@ -248,13 +248,19 @@ def run_tasks(self, request, queryset): ) return - task_ids = [ - task.apply_async(args=args, kwargs=kwargs, queue=queue, - headers={'periodic_task_name':periodic_task_name}) + task.apply_async( + args=args, + kwargs=kwargs, + queue=queue, + headers={'periodic_task_name': periodic_task_name} + ) if queue and len(queue) - else task.apply_async(args=args, kwargs=kwargs, - headers={'periodic_task_name':periodic_task_name}) + else task.apply_async( + args=args, + kwargs=kwargs, + headers={'periodic_task_name': periodic_task_name} + ) for task, args, kwargs, queue, periodic_task_name in tasks ] tasks_run = len(task_ids) diff --git a/t/unit/test_schedulers.py b/t/unit/test_schedulers.py index 1dbc150f..109f2e31 100644 --- a/t/unit/test_schedulers.py +++ b/t/unit/test_schedulers.py @@ -870,13 +870,13 @@ def test_run_tasks(self): queued_message = self.request._messages._queued_messages[0].message assert queued_message == '2 tasks were successfully run' - @pytest.mark.timeout(5) def test_run_task_headers(self, monkeypatch): def mock_apply_async(*args, **kwargs): self.captured_headers = kwargs.get('headers', {}) - monkeypatch.setattr('celery.app.task.Task.apply_async', mock_apply_async) + monkeypatch.setattr('celery.app.task.Task.apply_async', + mock_apply_async) ma = PeriodicTaskAdmin(PeriodicTask, self.site) self.request = self.patch_request(self.request_factory.get('/')) ma.run_tasks(self.request, PeriodicTask.objects.filter(id=self.m1.id)) From e3c1ade0548ccaa49da34beb275d62a7370a1ae9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 21 Oct 2024 18:58:42 +0200 Subject: [PATCH 06/19] [pre-commit.ci] pre-commit autoupdate (#815) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.6.9 → v0.7.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.6.9...v0.7.0) - [github.com/tox-dev/pyproject-fmt: 2.3.0 → 2.4.3](https://github.com/tox-dev/pyproject-fmt/compare/2.3.0...2.4.3) - [github.com/abravalheri/validate-pyproject: v0.20.2 → v0.21](https://github.com/abravalheri/validate-pyproject/compare/v0.20.2...v0.21) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3a6a94d4..56abfd4a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,17 +38,17 @@ repos: args: [--target-version, "3.2"] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.9 + rev: v0.7.0 hooks: # Format before linting # - id: ruff-format - id: ruff - repo: https://github.com/tox-dev/pyproject-fmt - rev: 2.3.0 + rev: 2.4.3 hooks: - id: pyproject-fmt - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.20.2 + rev: v0.21 hooks: - id: validate-pyproject From 7f3ba8033ef9c553166077680a69cf859fc973b6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:30:59 +0100 Subject: [PATCH 07/19] [pre-commit.ci] pre-commit autoupdate (#817) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v3.18.0 → v3.19.0](https://github.com/asottile/pyupgrade/compare/v3.18.0...v3.19.0) - [github.com/astral-sh/ruff-pre-commit: v0.7.0 → v0.7.1](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.0...v0.7.1) - [github.com/tox-dev/pyproject-fmt: 2.4.3 → v2.4.3](https://github.com/tox-dev/pyproject-fmt/compare/2.4.3...v2.4.3) - [github.com/abravalheri/validate-pyproject: v0.21 → v0.22](https://github.com/abravalheri/validate-pyproject/compare/v0.21...v0.22) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 56abfd4a..2b7601fc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ exclude: "migrations" repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.18.0 + rev: v3.19.0 hooks: - id: pyupgrade args: ["--py37-plus"] @@ -38,17 +38,17 @@ repos: args: [--target-version, "3.2"] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.0 + rev: v0.7.1 hooks: # Format before linting # - id: ruff-format - id: ruff - repo: https://github.com/tox-dev/pyproject-fmt - rev: 2.4.3 + rev: v2.4.3 hooks: - id: pyproject-fmt - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.21 + rev: v0.22 hooks: - id: validate-pyproject From 5f0e38a7dd27eeef30134444e1d75a5b770b96cb Mon Sep 17 00:00:00 2001 From: x-7 Date: Tue, 29 Oct 2024 18:22:56 +0800 Subject: [PATCH 08/19] fix 'exipres' not working normal as expected (#816) related issuses: 240 --- django_celery_beat/schedulers.py | 9 ++++++++- t/unit/test_schedulers.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/django_celery_beat/schedulers.py b/django_celery_beat/schedulers.py index 846b97a9..a73faff3 100644 --- a/django_celery_beat/schedulers.py +++ b/django_celery_beat/schedulers.py @@ -110,7 +110,6 @@ def is_due(self): now = self._default_now() if getattr(settings, 'DJANGO_CELERY_BEAT_TZ_AWARE', True): now = maybe_make_aware(self._default_now()) - if now < self.model.start_time: # The datetime is before the start date - don't run. # send a delay to retry on start_time @@ -119,6 +118,14 @@ def is_due(self): ) return schedules.schedstate(False, delay) + # EXPIRED TASK: Disable task when expired + if self.model.expires is not None: + now = self._default_now() + if now >= self.model.expires: + self._disable(self.model) + # Don't recheck + return schedules.schedstate(False, NEVER_CHECK_TIMEOUT) + # ONE OFF TASK: Disable one off tasks after they've ran once if self.model.one_off and self.model.enabled \ and self.model.total_run_count > 0: diff --git a/t/unit/test_schedulers.py b/t/unit/test_schedulers.py index d070bb45..f7889c77 100644 --- a/t/unit/test_schedulers.py +++ b/t/unit/test_schedulers.py @@ -291,6 +291,35 @@ def test_one_off_task(self): assert not isdue assert delay == NEVER_CHECK_TIMEOUT + def test_task_with_expires(self): + interval = 10 + right_now = self.app.now() + one_second_later = right_now + timedelta(seconds=1) + m = self.create_model_interval(schedule(timedelta(seconds=interval)), + start_time=right_now, + expires=one_second_later) + e = self.Entry(m, app=self.app) + isdue, delay = e.is_due() + assert isdue + assert delay == interval + + m2 = self.create_model_interval(schedule(timedelta(seconds=interval)), + start_time=right_now, + expires=right_now) + e2 = self.Entry(m2, app=self.app) + isdue, delay = e2.is_due() + assert not isdue + assert delay == NEVER_CHECK_TIMEOUT + + one_second_ago = right_now - timedelta(seconds=1) + m2 = self.create_model_interval(schedule(timedelta(seconds=interval)), + start_time=right_now, + expires=one_second_ago) + e2 = self.Entry(m2, app=self.app) + isdue, delay = e2.is_due() + assert not isdue + assert delay == NEVER_CHECK_TIMEOUT + @pytest.mark.django_db class test_DatabaseSchedulerFromAppConf(SchedulerCase): From c2cd1192445a7d5cd84d3734da4768d03d6520c7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Nov 2024 18:17:07 +0100 Subject: [PATCH 09/19] [pre-commit.ci] pre-commit autoupdate (#820) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.7.1 → v0.7.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.1...v0.7.2) - [github.com/tox-dev/pyproject-fmt: v2.4.3 → v2.5.0](https://github.com/tox-dev/pyproject-fmt/compare/v2.4.3...v2.5.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2b7601fc..3edfd5bd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,13 +38,13 @@ repos: args: [--target-version, "3.2"] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.1 + rev: v0.7.2 hooks: # Format before linting # - id: ruff-format - id: ruff - repo: https://github.com/tox-dev/pyproject-fmt - rev: v2.4.3 + rev: v2.5.0 hooks: - id: pyproject-fmt From 476be260ab4a2545fe1adc0f260e630c6e50e8bd Mon Sep 17 00:00:00 2001 From: chentt <7448203+daydaychen@users.noreply.github.com> Date: Thu, 7 Nov 2024 20:09:52 +0800 Subject: [PATCH 10/19] fix long period task will never be triggered (#717) * fix long period task will never be triggered * fix (schedulers): when model.date_changed is None, use _default.now() * test (schedulers): add test for when model.last_run_at is None * test (scheduler): revise the comment --------- Co-authored-by: chentiantian --- django_celery_beat/schedulers.py | 2 +- t/unit/test_schedulers.py | 49 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/django_celery_beat/schedulers.py b/django_celery_beat/schedulers.py index a73faff3..ce46b661 100644 --- a/django_celery_beat/schedulers.py +++ b/django_celery_beat/schedulers.py @@ -84,7 +84,7 @@ def __init__(self, model, app=None): self.model = model if not model.last_run_at: - model.last_run_at = self._default_now() + model.last_run_at = model.date_changed or self._default_now() # if last_run_at is not set and # model.start_time last_run_at should be in way past. # This will trigger the job to run at start_time diff --git a/t/unit/test_schedulers.py b/t/unit/test_schedulers.py index f7889c77..544ac4bd 100644 --- a/t/unit/test_schedulers.py +++ b/t/unit/test_schedulers.py @@ -213,6 +213,55 @@ def test_entry_and_model_last_run_at_with_utc_no_use_tz(self, monkeypatch): if hasattr(time, "tzset"): time.tzset() + @override_settings( + USE_TZ=False, + DJANGO_CELERY_BEAT_TZ_AWARE=False + ) + @pytest.mark.usefixtures('depends_on_current_app') + @timezone.override('Europe/Berlin') + @pytest.mark.celery(timezone='Europe/Berlin') + def test_entry_and_model_last_run_at_when_model_changed(self, monkeypatch): + old_tz = os.environ.get("TZ") + os.environ["TZ"] = "Europe/Berlin" + if hasattr(time, "tzset"): + time.tzset() + assert self.app.timezone.key == 'Europe/Berlin' + # simulate last_run_at from DB - not TZ aware but localtime + right_now = datetime.utcnow() + # make sure to use fixed date time + monkeypatch.setattr(self.Entry, '_default_now', lambda o: right_now) + m = self.create_model_crontab( + crontab(minute='*/10') + ) + m.save() + e = self.Entry(m, app=self.app) + e.save() + m.refresh_from_db() + + # The just created model has no value for date_changed + # so last_run_at should be set to the Entry._default_now() + assert m.last_run_at == e.last_run_at + + # If the model has been updated and the entry.last_run_at is None, + # entry.last_run_at should be set to the value of model.date_changed. + # see #717 + m2 = self.create_model_crontab( + crontab(minute='*/10') + ) + m2.save() + m2.refresh_from_db() + assert m2.date_changed is not None + e2 = self.Entry(m2, app=self.app) + e2.save() + assert m2.last_run_at == m2.date_changed + + if old_tz is not None: + os.environ["TZ"] = old_tz + else: + del os.environ["TZ"] + if hasattr(time, "tzset"): + time.tzset() + @override_settings( USE_TZ=False, DJANGO_CELERY_BEAT_TZ_AWARE=False, From 872ce4d2f871a636c1e366ba869bb4450d5c09a2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 11 Nov 2024 18:53:34 +0200 Subject: [PATCH 11/19] [pre-commit.ci] pre-commit autoupdate (#823) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.7.2 → v0.7.3](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.2...v0.7.3) - [github.com/abravalheri/validate-pyproject: v0.22 → v0.23](https://github.com/abravalheri/validate-pyproject/compare/v0.22...v0.23) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3edfd5bd..7a83549e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,7 +38,7 @@ repos: args: [--target-version, "3.2"] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.2 + rev: v0.7.3 hooks: # Format before linting # - id: ruff-format - id: ruff @@ -49,6 +49,6 @@ repos: - id: pyproject-fmt - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.22 + rev: v0.23 hooks: - id: validate-pyproject From ac0ce20a4e97fd4c8fcc1aac5e685c3815c0adca Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Nov 2024 15:03:46 +0100 Subject: [PATCH 12/19] Bump codecov/codecov-action from 4 to 5 (#825) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 4 to 5. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v4...v5) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 87db6bf7..d7895256 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,7 +57,7 @@ jobs: DJANGO: ${{ matrix.django-version }} - name: Upload coverage reports to Codecov if: ${{ matrix.python-version != 'pypy-3.10' }} - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v5 with: fail_ci_if_error: true # optional (default = false) token: ${{ secrets.CODECOV_TOKEN }} From c7337cf9abfca52d5b806fc1445fe652957fe76a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:01:02 +0200 Subject: [PATCH 13/19] [pre-commit.ci] pre-commit autoupdate (#826) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.7.3 → v0.7.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.3...v0.7.4) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7a83549e..a63d902a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,7 +38,7 @@ repos: args: [--target-version, "3.2"] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.3 + rev: v0.7.4 hooks: # Format before linting # - id: ruff-format - id: ruff From ca609dd9f483203715edeef0f0d3de10dd278fcc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:59:41 +0100 Subject: [PATCH 14/19] [pre-commit.ci] pre-commit autoupdate (#827) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.7.4 → v0.8.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.4...v0.8.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a63d902a..68436ccf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,7 +38,7 @@ repos: args: [--target-version, "3.2"] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.4 + rev: v0.8.0 hooks: # Format before linting # - id: ruff-format - id: ruff From 3658923de7f321332d3f82d041fb12f8b52ddf2e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 17:58:11 +0100 Subject: [PATCH 15/19] [pre-commit.ci] pre-commit autoupdate (#829) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/adamchainz/django-upgrade: 1.22.1 → 1.22.2](https://github.com/adamchainz/django-upgrade/compare/1.22.1...1.22.2) - [github.com/astral-sh/ruff-pre-commit: v0.8.0 → v0.8.1](https://github.com/astral-sh/ruff-pre-commit/compare/v0.8.0...v0.8.1) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 68436ccf..d75deb41 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,13 +32,13 @@ repos: - id: isort - repo: https://github.com/adamchainz/django-upgrade - rev: 1.22.1 + rev: 1.22.2 hooks: - id: django-upgrade args: [--target-version, "3.2"] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.0 + rev: v0.8.1 hooks: # Format before linting # - id: ruff-format - id: ruff From 5ea76e8636ed0498aec0459a6de42f56e2b2664e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 9 Dec 2024 19:14:33 +0200 Subject: [PATCH 16/19] [pre-commit.ci] pre-commit autoupdate (#830) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.8.1 → v0.8.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.8.1...v0.8.2) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d75deb41..a896df80 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,7 +38,7 @@ repos: args: [--target-version, "3.2"] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.1 + rev: v0.8.2 hooks: # Format before linting # - id: ruff-format - id: ruff From ac9535f95a79a9cf7b5dd5fb9e281c58f421d415 Mon Sep 17 00:00:00 2001 From: Matthew Goss Date: Tue, 8 Oct 2024 21:16:43 +1100 Subject: [PATCH 17/19] fix for missing periodic task name in results --- django_celery_beat/admin.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/django_celery_beat/admin.py b/django_celery_beat/admin.py index 2c462656..a7db1e07 100644 --- a/django_celery_beat/admin.py +++ b/django_celery_beat/admin.py @@ -248,12 +248,13 @@ def run_tasks(self, request, queryset): ) return + headers = {'periodic_task_name':periodic_task_name} + task_ids = [ task.apply_async(args=args, kwargs=kwargs, queue=queue, - periodic_task_name=periodic_task_name) + headers=headers) if queue and len(queue) - else task.apply_async(args=args, kwargs=kwargs, - periodic_task_name=periodic_task_name) + else task.apply_async(args=args, kwargs=kwargs, headers=headers) for task, args, kwargs, queue, periodic_task_name in tasks ] tasks_run = len(task_ids) From 7167f480cd175853c2fef68c8340622e1a65c2d9 Mon Sep 17 00:00:00 2001 From: Matthew Goss <30362690+ntindicator@users.noreply.github.com> Date: Fri, 11 Oct 2024 00:28:20 +1100 Subject: [PATCH 18/19] fix error in admin, add to scheduler headers,tests --- django_celery_beat/admin.py | 6 +++--- django_celery_beat/schedulers.py | 5 +++-- t/unit/test_schedulers.py | 17 +++++++++++++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/django_celery_beat/admin.py b/django_celery_beat/admin.py index a7db1e07..28ed3d67 100644 --- a/django_celery_beat/admin.py +++ b/django_celery_beat/admin.py @@ -248,13 +248,13 @@ def run_tasks(self, request, queryset): ) return - headers = {'periodic_task_name':periodic_task_name} task_ids = [ task.apply_async(args=args, kwargs=kwargs, queue=queue, - headers=headers) + headers={'periodic_task_name':periodic_task_name}) if queue and len(queue) - else task.apply_async(args=args, kwargs=kwargs, headers=headers) + else task.apply_async(args=args, kwargs=kwargs, + headers={'periodic_task_name':periodic_task_name}) for task, args, kwargs, queue, periodic_task_name in tasks ] tasks_run = len(task_ids) diff --git a/django_celery_beat/schedulers.py b/django_celery_beat/schedulers.py index ce46b661..7574e81f 100644 --- a/django_celery_beat/schedulers.py +++ b/django_celery_beat/schedulers.py @@ -77,8 +77,9 @@ def __init__(self, model, app=None): if getattr(model, 'expires_', None): self.options['expires'] = getattr(model, 'expires_') - self.options['headers'] = loads(model.headers or '{}') - self.options['periodic_task_name'] = model.name + headers = loads(model.headers or '{}') + headers['periodic_task_name'] = model.name + self.options['headers'] = headers self.total_run_count = model.total_run_count self.model = model diff --git a/t/unit/test_schedulers.py b/t/unit/test_schedulers.py index 544ac4bd..32ed5987 100644 --- a/t/unit/test_schedulers.py +++ b/t/unit/test_schedulers.py @@ -130,8 +130,8 @@ def test_entry(self): assert e.options['exchange'] == 'foo' assert e.options['routing_key'] == 'cpu' assert e.options['priority'] == 1 - assert e.options['headers'] == {'_schema_name': 'foobar'} - assert e.options['periodic_task_name'] == m.name + assert e.options['headers']['_schema_name'] == 'foobar' + assert e.options['headers']['periodic_task_name'] == m.name right_now = self.app.now() m2 = self.create_model_interval( @@ -947,3 +947,16 @@ def test_run_tasks(self): assert len(self.request._messages._queued_messages) == 1 queued_message = self.request._messages._queued_messages[0].message assert queued_message == '2 tasks were successfully run' + + + @pytest.mark.timeout(5) + def test_run_task_headers(self, monkeypatch): + def mock_apply_async(*args, **kwargs): + self.captured_headers = kwargs.get('headers', {}) + + monkeypatch.setattr('celery.app.task.Task.apply_async', mock_apply_async) + ma = PeriodicTaskAdmin(PeriodicTask, self.site) + self.request = self.patch_request(self.request_factory.get('/')) + ma.run_tasks(self.request, PeriodicTask.objects.filter(id=self.m1.id)) + assert 'periodic_task_name' in self.captured_headers + assert self.captured_headers['periodic_task_name'] == self.m1.name From e6475e65db9c8bd2518750907592e068efaf46ec Mon Sep 17 00:00:00 2001 From: Matthew Goss <30362690+ntindicator@users.noreply.github.com> Date: Tue, 15 Oct 2024 12:50:06 +1100 Subject: [PATCH 19/19] formatting changes --- django_celery_beat/admin.py | 16 +++++++++++----- t/unit/test_schedulers.py | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/django_celery_beat/admin.py b/django_celery_beat/admin.py index 28ed3d67..89db3757 100644 --- a/django_celery_beat/admin.py +++ b/django_celery_beat/admin.py @@ -248,13 +248,19 @@ def run_tasks(self, request, queryset): ) return - task_ids = [ - task.apply_async(args=args, kwargs=kwargs, queue=queue, - headers={'periodic_task_name':periodic_task_name}) + task.apply_async( + args=args, + kwargs=kwargs, + queue=queue, + headers={'periodic_task_name': periodic_task_name} + ) if queue and len(queue) - else task.apply_async(args=args, kwargs=kwargs, - headers={'periodic_task_name':periodic_task_name}) + else task.apply_async( + args=args, + kwargs=kwargs, + headers={'periodic_task_name': periodic_task_name} + ) for task, args, kwargs, queue, periodic_task_name in tasks ] tasks_run = len(task_ids) diff --git a/t/unit/test_schedulers.py b/t/unit/test_schedulers.py index 32ed5987..439000fb 100644 --- a/t/unit/test_schedulers.py +++ b/t/unit/test_schedulers.py @@ -948,13 +948,13 @@ def test_run_tasks(self): queued_message = self.request._messages._queued_messages[0].message assert queued_message == '2 tasks were successfully run' - @pytest.mark.timeout(5) def test_run_task_headers(self, monkeypatch): def mock_apply_async(*args, **kwargs): self.captured_headers = kwargs.get('headers', {}) - monkeypatch.setattr('celery.app.task.Task.apply_async', mock_apply_async) + monkeypatch.setattr('celery.app.task.Task.apply_async', + mock_apply_async) ma = PeriodicTaskAdmin(PeriodicTask, self.site) self.request = self.patch_request(self.request_factory.get('/')) ma.run_tasks(self.request, PeriodicTask.objects.filter(id=self.m1.id))