Is celery-beats can only trigger a celery task or normal task (Django)?

Viewed 29

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.

tasks.py:

@app.shared_task
def longrunningtask(a):
   res = APIcall(a)
   return res 

caller.py:

from .task import longrunningtask

def dosomething(input_list):
  for ele in input_list: 
     res.append(longrunningtask.delay(ele))
  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.caller.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

  1. 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.
  2. 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 while.

Any suggestion or idea of this use case is also superhelpful!

0 Answers
Related