I am workign on a django project with celery and celery-beats. My main use case is use celery-beats to set up a periodical task as a background task, instead of using a front-end request to trigger. I would save the results and put it inside model, then pull the model to front-end view as a view to user.
My current problem is, not matter how I change the way I am calling my task, it always throwing the task is not registered in the task list inside celery.
I am trying to trigger a non-celery task(inside, it will call a celery taskthe , using celery beats module,
Below is the pesudo-code.
@app.shared_task def longrunningtask(a,b): res = stuff.delay(a, b) return res
from .task import foo def dosomething(input_list): for ele in input_list: res.append(longrunningtask()) return res
Periodical Task :
schedule, created = CrontabSchedule.objects.get_or_create(hour = 1, minute = 34) task = PeriodicTask.objects.create(crontab=schedule, name="XXX_task_", task='app.tasks.dosomething')) return HttpResponse("Done")
Nothing special about the periodical task, but This never works for me. It errored that
not detected tasks or not registered tasks if I do not make the dosomething() as celery task.
Problem is I do not want to make the caller function a celery task, the reason being, that
- Inside for loop, I would make parameter passing into the task(), I would like to see multiple celery long runing task is running with the for loop passing it and kick it. so I would create mutliple sub-task instead of as one giant running task.
- Not necessary since longrunningtask is the task I need it to be run as celery task, no need its parent to be inside celery task.
Can someone please help me out of this dilemma? It’s super frustrating and has been blocking me for a week.
Any suggestion or idea of this use case is also superhelpful!
This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.