Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for missing periodic task name in results #812

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3ab299e
fix for missing periodic task name in results
ntindicator Oct 8, 2024
a9a7490
fix error in admin, add to scheduler headers,tests
ntindicator Oct 10, 2024
3c2dfbb
Add Python 3.13 to the testing (#813)
cclauss Oct 14, 2024
ce728bd
[pre-commit.ci] pre-commit autoupdate (#814)
pre-commit-ci[bot] Oct 14, 2024
9be2125
formatting changes
ntindicator Oct 15, 2024
e3c1ade
[pre-commit.ci] pre-commit autoupdate (#815)
pre-commit-ci[bot] Oct 21, 2024
7f3ba80
[pre-commit.ci] pre-commit autoupdate (#817)
pre-commit-ci[bot] Oct 28, 2024
5f0e38a
fix 'exipres' not working normal as expected (#816)
x-7 Oct 29, 2024
c2cd119
[pre-commit.ci] pre-commit autoupdate (#820)
pre-commit-ci[bot] Nov 4, 2024
476be26
fix long period task will never be triggered (#717)
daydaychen Nov 7, 2024
872ce4d
[pre-commit.ci] pre-commit autoupdate (#823)
pre-commit-ci[bot] Nov 11, 2024
ac0ce20
Bump codecov/codecov-action from 4 to 5 (#825)
dependabot[bot] Nov 15, 2024
c7337cf
[pre-commit.ci] pre-commit autoupdate (#826)
pre-commit-ci[bot] Nov 18, 2024
ca609dd
[pre-commit.ci] pre-commit autoupdate (#827)
pre-commit-ci[bot] Nov 25, 2024
3658923
[pre-commit.ci] pre-commit autoupdate (#829)
pre-commit-ci[bot] Dec 2, 2024
5ea76e8
[pre-commit.ci] pre-commit autoupdate (#830)
pre-commit-ci[bot] Dec 9, 2024
ac9535f
fix for missing periodic task name in results
ntindicator Oct 8, 2024
7167f48
fix error in admin, add to scheduler headers,tests
ntindicator Oct 10, 2024
e6475e6
formatting changes
ntindicator Oct 15, 2024
62f0529
Merge branch 'periodic-task-name-results' of github.com:ntindicator/d…
ntindicator Dec 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions django_celery_beat/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,18 @@ def run_tasks(self, request, queryset):
return

task_ids = [
task.apply_async(args=args, kwargs=kwargs, queue=queue,
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,
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)
Expand Down
5 changes: 3 additions & 2 deletions django_celery_beat/schedulers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions t/unit/test_schedulers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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