Skip to content

Commit 18dc6ce

Browse files
committed
run celery with redis backend and fix serialization issues
1 parent 54a25d8 commit 18dc6ce

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

.github/workflows/tests.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,27 @@ on:
88
jobs:
99
python-tests:
1010
runs-on: ubuntu-latest
11+
services:
12+
redis:
13+
image: redis
14+
options: >-
15+
--health-cmd "redis-cli ping"
16+
--health-interval 10s
17+
--health-timeout 5s
18+
--health-retries 5
19+
ports:
20+
- 6379:6379
1121
strategy:
1222
max-parallel: 4
1323
matrix:
1424
python-version:
1525
- "3.9"
1626
- "3.10"
27+
- "3.11"
28+
- "3.12"
29+
celery-version:
30+
- ">=5.3,<5.4"
31+
- ">=5.4"
1732
steps:
1833
- uses: actions/checkout@v3
1934
- name: Set up Python ${{ matrix.python-version }}
@@ -31,6 +46,8 @@ jobs:
3146
poetry --version
3247
poetry check --no-interaction
3348
- name: Install project
34-
run: poetry install --no-interaction
49+
run: |
50+
poetry install --no-interaction
51+
pip install celery"${{ matrix.celery-version }}"
3552
- name: Run tests
3653
run: poetry run pytest -v

taskbadger/celery.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def task_publish_handler(sender=None, headers=None, body=None, **kwargs):
156156
celery_system = Badger.current.settings.get_system_by_id("celery")
157157
auto_track = celery_system and celery_system.track_task(sender)
158158
manual_track = headers.get("taskbadger_track")
159+
header_kwargs = headers.pop(TB_KWARGS_ARG, {})
159160
if not manual_track and not auto_track:
160161
return
161162

@@ -168,7 +169,7 @@ def task_publish_handler(sender=None, headers=None, body=None, **kwargs):
168169
kwargs[attr.removeprefix(KWARG_PREFIX)] = getattr(ctask, attr)
169170

170171
# get kwargs from the task headers (set via apply_async)
171-
kwargs.update(headers.get(TB_KWARGS_ARG, {}))
172+
kwargs.update(header_kwargs)
172173
kwargs["status"] = StatusEnum.PENDING
173174
name = kwargs.pop("name", headers["task"])
174175

tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,12 @@ def bind_settings():
88
Badger.current.bind(Settings("https://taskbadger.net", "token", "org", "proj"))
99
yield
1010
Badger.current.bind(None)
11+
12+
13+
@pytest.fixture(scope="session", autouse=True)
14+
def celery_config():
15+
"""Test against Redis to ensure serialization works"""
16+
return {
17+
"broker_url": "redis://localhost:6379",
18+
"result_backend": "redis://localhost:6379",
19+
}

tests/test_celery_error.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def add_error(self, a, b):
2121
"taskbadger.celery.update_task_safe"
2222
) as update, mock.patch("taskbadger.celery.get_task") as get_task:
2323
task = task_for_test()
24+
create.return_value = task
2425
get_task.return_value = task
2526
update.return_value = task
2627
result = add_error.delay(2, 2)

0 commit comments

Comments
 (0)