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


This Content is from Stack Overflow. Question asked by James Xu

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.

def longrunningtask(a,b):
   res = stuff.delay(a, b)
   return res

from .task import foo 

def dosomething(input_list):
  for ele in input_list: 
  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

  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 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.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?