Skip to content

Commit 4769da1

Browse files
maciej-golMaciej Gol
and
Maciej Gol
authored
Minimum required celery version is 5.0 (#136)
Co-authored-by: Maciej Gol <[email protected]>
1 parent 665afff commit 4769da1

12 files changed

+58
-32
lines changed

local-compose.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
version: "3.6"
2+
services:
3+
postgres:
4+
image: postgres:13
5+
environment:
6+
- POSTGRES_PASSWORD=qwe123
7+
- POSTGRES_USER=tenant_celery
8+
- POSTGRES_DB=tenant_celery
9+
network_mode: host
10+
11+
rabbitmq:
12+
image: rabbitmq
13+
network_mode: host
14+
15+
redis:
16+
image: redis
17+
network_mode: host
18+
19+
app:
20+
image: "python:${PYTHON_VERSION:-3.8}-slim"
21+
depends_on:
22+
- postgres
23+
- redis
24+
environment:
25+
- DATABASE_HOST=postgres
26+
- BROKER_URL=${BROKER_URL:-amqp://guest:guest@rabbitmq:5672/}
27+
- ADDITIONAL_REQUIREMENTS=${ADDITIONAL_REQUIREMENTS}
28+
- TASK_TENANT_CACHE_SECONDS=10
29+
30+
volumes:
31+
- ./tenant_schemas_celery:/app/tenant_schemas_celery
32+
- ./test_app:/app/test_app
33+
- ./requirements.txt:/app/requirements.txt
34+
- ./__app_run_tests:/app/__app_run_tests
35+
- ./setup.py:/app/setup.py
36+
- ./VERSION:/app/VERSION
37+
- ./README.md:/app/README.md
38+
39+
command: ["bash", "-c", "cd /app && ./__app_run_tests"]

run-celery-worker

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
. .env/bin/activate
3+
cd test_app
4+
export DJANGO_SETTINGS_MODULE=test_app.settings
5+
6+
celery -A tenant_schemas_celery.test_app:app worker -l INFO

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
],
2525
description='Celery integration for django-tenant-schemas and django-tenants',
2626
install_requires=[
27-
'celery',
27+
'celery>=5',
2828
],
2929
packages=find_packages(),
3030
python_requires=">=3.8",

tenant_schemas_celery/app.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
try:
42
from celery import Celery
53
except ImportError:
@@ -80,7 +78,7 @@ class CeleryApp(Celery):
8078

8179
def __init__(self, *args, **kwargs):
8280
kwargs.setdefault("task_cls", self.task_cls)
83-
super(CeleryApp, self).__init__(*args, **kwargs)
81+
super().__init__(*args, **kwargs)
8482

8583
def create_task_cls(self):
8684
return self.subclass_with_self(
@@ -99,4 +97,4 @@ def _add_current_schema(self, kwds):
9997

10098
def send_task(self, name, args=None, kwargs=None, **options):
10199
self._update_headers(options)
102-
return super(CeleryApp, self).send_task(name, args=args, kwargs=kwargs, **options)
100+
return super().send_task(name, args=args, kwargs=kwargs, **options)

tenant_schemas_celery/integration_test.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
import time
42

53
import pytest

tenant_schemas_celery/registry_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from celery import Task
55

66
from tenant_schemas_celery.task import TenantTask
7-
from .test_app import app
8-
from .test_tasks import get_schema_name, get_schema_from_class_task, SchemaClassTask
7+
from tenant_schemas_celery.test_app import app
8+
from tenant_schemas_celery.test_tasks import get_schema_name, get_schema_from_class_task, SchemaClassTask
99

1010

1111
def test_get_schema_name_registration(transactional_db):

tenant_schemas_celery/task.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import celery
2-
from celery.app.task import Task
1+
from celery import Task
32
from django.db import connection
43

54
from tenant_schemas_celery.cache import SimpleCache
@@ -9,7 +8,7 @@
98

109
class SharedTenantCache(SimpleCache):
1110
def __init__(self):
12-
super(SharedTenantCache, self).__init__(storage=_shared_storage)
11+
super().__init__(storage=_shared_storage)
1312

1413

1514
class TenantTask(Task):
@@ -37,7 +36,7 @@ def tenant_cache(cls):
3736

3837
@classmethod
3938
def get_tenant_for_schema(cls, schema_name):
40-
from .compat import get_tenant_model
39+
from tenant_schemas_celery.compat import get_tenant_model
4140

4241
missing = object()
4342
cache = cls.tenant_cache()
@@ -65,11 +64,5 @@ def _add_current_schema(self, kwds):
6564
kwds["_schema_name"] = kwds.get("_schema_name", connection.schema_name)
6665

6766
def apply(self, args=None, kwargs=None, *arg, **kw):
68-
if celery.VERSION[0] < 4:
69-
kwargs = kwargs or {}
70-
self._add_current_schema(kwargs)
71-
72-
else:
73-
# Celery 4.0 introduced strong typing and the `headers` meta dict.
74-
self._update_headers(kw)
75-
return super(TenantTask, self).apply(args, kwargs, *arg, **kw)
67+
self._update_headers(kw)
68+
return super().apply(args, kwargs, *arg, **kw)

tenant_schemas_celery/test_app.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22

33
try:
4-
from .app import CeleryApp
4+
from tenant_schemas_celery.app import CeleryApp
55
except ImportError:
66
app = None
77
else:

tenant_schemas_celery/test_scheduler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pytest import fixture, mark
99
from tenant_schemas_celery.app import CeleryApp
1010

11-
from .scheduler import (
11+
from tenant_schemas_celery.scheduler import (
1212
TenantAwarePersistentScheduler,
1313
TenantAwareSchedulerMixin,
1414
)

tenant_schemas_celery/test_utils.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
from django.core.exceptions import FieldDoesNotExist
42

53
from test_app.shared.models import Client

test-compose.yml

-6
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,12 @@ services:
66
- POSTGRES_PASSWORD=qwe123
77
- POSTGRES_USER=tenant_celery
88
- POSTGRES_DB=tenant_celery
9-
logging:
10-
driver: "none"
119

1210
rabbitmq:
1311
image: rabbitmq
14-
logging:
15-
driver: "none"
1612

1713
redis:
1814
image: redis
19-
logging:
20-
driver: "none"
2115

2216
app:
2317
image: "python:${PYTHON_VERSION:-3.8}-slim"

test_app/test_app/settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160

161161
STATIC_URL = '/static/'
162162

163-
CELERY_BROKER_URL = os.environ.get("BROKER_URL", 'amqp://tenants:tenants@localhost:5672/')
163+
CELERY_BROKER_URL = os.environ.get("BROKER_URL", 'amqp://guest:guest@localhost:5672/')
164164
CELERYBEAT_SCHEDULE = {
165165
'test-periodic-task': {
166166
'task': 'test_app.tenant.tasks.periodic_print_schema',

0 commit comments

Comments
 (0)