I have an application made it with django using redis and celery for some asynchronous tasks. I am using the celery tasks to execute some stored procedures. This SP take from 5 mins to 30 mins to execute completely(depending in amount of records). Everything works great. But I need the be able to execute the tasks several times. but right now when I run task and another user run the task too, the two tasks are executed at the same time. I need the task enter in queue and only executed when the first task finish. My settings.py:
BROKER_URL = 'redis://localhost:6379/0'
CELERY_IMPORTS = ("pc.tasks", )
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_RESULT_BACKEND='djcelery.backends.cache:CacheBackend'
tasks.py
from __future__ import absolute_import
from celery.decorators import task
from celery import task, shared_task
from .models import Servicio, Proveedor, Lectura_FTP, Actualizar_Descarga
from .models import Lista_Archivos, Lista_Final, Buscar_Conci
@task
def carga_ftp():
tabla = Proc_Carga()
sp = tabla.carga()
return None
@task
def conci(idprov,pfecha):
conci = Buscar_Conci()
spconc = conci.buscarcon(idprov,pfecha)
I call the tasks in my view in this way:
conci.delay(prov,DateV);
How can I create or setup a queue list of taks and everry tasks is executed only when the previous taks is finished
Thanks in advance
You can limit the tasks workers, in your cause i assume you just need one worker at time, so just start one worker when calling the djcelery.
python manage.py celery worker -B --concurrency=1