Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add dynamic task to celery

Tags:

python

celery

I am trying to find a way to add a new task to celery after celery worker has been executed and after celery has been instantiated. I basically want to add a new task with a dynamic name based on user input. I will also want to set a rate limit for that new task.

I have not been able to find any documentation on this and no examples on my google searches. All I have been able to find is dynamically adding periodic tasks with celery beat.

Is there any way to do what I am looking to do?

like image 657
user1601716 Avatar asked Oct 17 '25 23:10

user1601716


1 Answers

You can register a task as:

def dynamic_task():
   return "Hi"

dynamic_task = app.task(dynamic_task, name='my_name')

See that you can register a list of functions in this way, then you will need to restart the worker, however you can use the signals https://docs.celeryproject.org/en/stable/userguide/signals.html as well.

like image 101
Elvis Ferrera Avatar answered Oct 19 '25 13:10

Elvis Ferrera