python - How to dynamically add tasks during the run of celery beat scheduler?
某草草2017-05-18 10:56:10
0
2
2197
I tried django-celery-beat. Adding tasks in the admin background can achieve dynamic addition of tasks. But it will take effect only after restarting celery beat. Is there any other way to try?
There is an idea that you can consider. I am currently trying this method and am in the stage of trying to cross the river by feeling the stones. Celery supports scheduled tasks, but it does not meet my needs. I need to dynamically add scheduled tasks like crontab under Linux. I also looked at django-celery-beat. Because I use Flask, I found that it is not worth reference for implementation, so I have been After reading the documentation and searching for information, I finally found a way. Celery's apply_async function is very useful. It has an eta parameter. Its simplified use is countdown, but the power of eta is huge because it only accepts datetime objects. , for example, if you give a task to be executed at 2017-05-02 20:0:0, you can use it like this:
Is it rarely used? If I have a task that needs to be executed at eight o'clock every night, I can use this eta parameter to achieve it. The pseudo code is as follows:
It provides functions for success and failure of task execution. We only need to rewrite it on this basis. I am only talking about the core part. There are many ways to do it specifically,
Cannot be added dynamically, beat must be restarted.
ask answered the reason #3493
There is an idea that you can consider. I am currently trying this method and am in the stage of trying to cross the river by feeling the stones. Celery supports scheduled tasks, but it does not meet my needs. I need to dynamically add scheduled tasks like crontab under Linux. I also looked at django-celery-beat. Because I use Flask, I found that it is not worth reference for implementation, so I have been After reading the documentation and searching for information, I finally found a way. Celery's apply_async function is very useful. It has an eta parameter. Its simplified use is countdown, but the power of eta is huge because it only accepts datetime objects. , for example, if you give a task to be executed at 2017-05-02 20:0:0, you can use it like this:
job.apply_async(args=args, kwarg=kwargs, eta=datetime(2017,5,2,20,0,0))
Is it rarely used? If I have a task that needs to be executed at eight o'clock every night, I can use this eta parameter to achieve it. The pseudo code is as follows:
A very important point here is how to calculate the next execution time when the task is successfully executed. The method is as follows
It provides functions for success and failure of task execution. We only need to rewrite it on this basis. I am only talking about the core part. There are many ways to do it specifically,