From db51b04ce267d9f65e5cd2c21095079adae6ead1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20K=C3=B6gl?= Date: Sun, 6 Aug 2017 14:25:24 +0200 Subject: [PATCH] Upgrade to Celery 4 http://docs.celeryproject.org/en/latest/whatsnew-4.0.html http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html --- Procfile | 2 +- mygpo/celery.py | 4 ++-- mygpo/settings.py | 17 ++++++----------- requirements.txt | 5 +++-- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Procfile b/Procfile index bf6acf24..cbbcbbb6 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ web: gunicorn mygpo.wsgi:application -c gunicorn.conf.py -beat: python manage.py celery beat -S djcelery.schedulers.DatabaseScheduler --pidfile /var/run/mygpo/celerybeat.pid +beat: python manage.py celery beat -S django --pidfile /var/run/mygpo/celerybeat.pid diff --git a/mygpo/celery.py b/mygpo/celery.py index 6be6bb4c..1e9ba704 100644 --- a/mygpo/celery.py +++ b/mygpo/celery.py @@ -7,5 +7,5 @@ from celery import Celery os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mygpo.settings') celery = Celery('mygpo.celery') -celery.config_from_object('django.conf:settings') -celery.autodiscover_tasks(lambda: settings.INSTALLED_APPS) +celery.config_from_object('django.conf:settings', namespace='CELERY') +celery.autodiscover_tasks() diff --git a/mygpo/settings.py b/mygpo/settings.py index a6cec47e..fe156f9a 100644 --- a/mygpo/settings.py +++ b/mygpo/settings.py @@ -124,7 +124,8 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.staticfiles', 'django.contrib.sites', - 'djcelery', + 'django_celery_results', + 'django_celery_beat', 'mygpo.core', 'mygpo.podcasts', 'mygpo.chapters', @@ -328,19 +329,13 @@ DEFAULT_BASE_URL = os.getenv('DEFAULT_BASE_URL', '') ### Celery -BROKER_URL = os.getenv('BROKER_URL', 'redis://localhost') -CELERY_RESULT_BACKEND = 'djcelery.backends.database:DatabaseBackend' +CELERY_BROKER_URL = os.getenv('BROKER_URL', 'redis://localhost') +CELERY_RESULT_BACKEND = 'django-db' -SERVER_EMAIL = os.getenv('SERVER_EMAIL', 'no-reply@example.com') +CELERY_RESULT_EXPIRES = 60 * 60 # 1h expiry time in seconds -CELERY_TASK_RESULT_EXPIRES = 60 * 60 # 1h expiry time in seconds +CELERY_ACCEPT_CONTENT = ['json'] -CELERY_ACCEPT_CONTENT = ['pickle', 'json'] - -CELERY_SEND_TASK_ERROR_EMAILS = get_bool('CELERY_SEND_TASK_ERROR_EMAILS', - False) - -BROKER_POOL_LIMIT = get_intOrNone('BROKER_POOL_LIMIT', 10) ### Google API diff --git a/requirements.txt b/requirements.txt index e4216e33..75868e19 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ Django==1.10.7 Babel==2.4.0 Pillow==4.1.1 -celery[redis]==3.1.25 +celery[redis]==4.1.0 dj-database-url==0.4.2 django-redis-sessions==0.5.6 python3-memcached==1.51 @@ -14,5 +14,6 @@ psycopg2==2.7.1 pyes==0.99.6 python-dateutil==2.6.0 redis==2.10.5 -django-celery==3.2.1 +django-celery-results==1.0.1 +django-celery-beat==1.0.1 requests==2.18.1 -- 2.11.4.GIT