Browse Source

Configurando celery e redis

django-celery
ulyssesBML 4 years ago
parent
commit
2be8848bea
  1. 9
      docker-compose-dev.yml
  2. 2
      requirements/requirements.txt
  3. 3
      sapl/__init__.py
  4. 9
      sapl/celery.py
  5. 6
      sapl/materia/tasks.py
  6. 7
      sapl/settings.py

9
docker-compose-dev.yml

@ -13,6 +13,14 @@ services:
networks: networks:
- sapl-net-dev - sapl-net-dev
redis:
image: redis:latest
command: redis-server
ports:
- "6379:6379"
networks:
- sapl-net-dev
sapl-dev: sapl-dev:
container_name: sapl-dev container_name: sapl-dev
image: sapl:dev image: sapl:dev
@ -31,6 +39,7 @@ services:
TZ: America/Sao_Paulo TZ: America/Sao_Paulo
depends_on: depends_on:
- sapldb-dev - sapldb-dev
- redis
networks: networks:
- sapl-net-dev - sapl-net-dev

2
requirements/requirements.txt

@ -32,6 +32,6 @@ pysolr==3.6.0
PyPDF4==1.27.0 PyPDF4==1.27.0
pyoai==2.5.0 pyoai==2.5.0
Unidecode==1.1.1 Unidecode==1.1.1
celery
git+https://github.com/interlegis/trml2pdf git+https://github.com/interlegis/trml2pdf
git+https://github.com/interlegis/django-admin-bootstrapped git+https://github.com/interlegis/django-admin-bootstrapped

3
sapl/__init__.py

@ -0,0 +1,3 @@
from .celery import celery_app
__all__ = ('celery_app',)

9
sapl/celery.py

@ -0,0 +1,9 @@
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sapl.settings')
celery_app = Celery('sapl')
celery_app.config_from_object('django.conf:settings', namespace='CELERY')
celery_app.autodiscover_tasks()

6
sapl/materia/tasks.py

@ -0,0 +1,6 @@
from celery import shared_task
#teste
@shared_task
def adding_task(x, y):
return x + y

7
sapl/settings.py

@ -99,7 +99,6 @@ INSTALLED_APPS = (
'speedinfo', 'speedinfo',
'webpack_loader', 'webpack_loader',
) + SAPL_APPS ) + SAPL_APPS
# FTS = Full Text Search # FTS = Full Text Search
@ -359,6 +358,12 @@ PASSWORD_HASHERS = [
'sapl.hashers.ZopeSHA1PasswordHasher', 'sapl.hashers.ZopeSHA1PasswordHasher',
] ]
#celery
CELERY_BROKER_URL = 'redis://redis:6379/0'
CELERY_RESULT_BACKEND = 'redis://redis:6379/0'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'
def remove_warnings(): def remove_warnings():
import warnings import warnings

Loading…
Cancel
Save