./env/bin/pip install -e ./nextgisweb-celery
- Create config for celery
celery.ini example:
[celery]
BROKER_URL = redis://localhost:6379/1
RESULT_BACKEND = redis://localhost:6379/2
ACCEPT_CONTENT = ['application/json']
TASK_SERIALIZER = 'json'
RESULT_SERIALIZER = 'json'
- Add path to ngw config
config.ini example:
...
[celery]
celery_conf_file = /my/path/celery.ini
...
- Create your task in your component
tasks.py example:
from nextgisweb_celery.app import celery_app as app
@app.task(reject_on_worker_lost=True, soft_time_limit=60*60)
def add(x, y):
return x+y
- Import your tasks in your component init (DO IT!)
__init__.py example:
...
from .tasks import add
...
- Use your task in your component
view.py example:
from .tasks import add
...
add.delay(7,5)
...
./env/bin/celery -A nextgisweb_celery.app.celery_app --ngw-config /my/path/config.ini