有时候,需要在项目中做一些定时的任务,例如:我需要每隔几分钟去访问一个接口,然后根据返回值,做后续操作。
请教下,如何来实现?(PS:如果是用系统的crontab就不要说了。)
目前google了一种方法是使用celery。请加下大家,是否是条长期可行之路。
PHP中文网2017-04-18 09:25:53
If you use Django’s own server to run your website, you can use django-celery. But if it is a website running with uWSGI, it is best to use uWSGI's signal for scheduled tasks. Other scheduled tasks are likely to be killed by uWSGI because they occupy the thread for a long time. I have worked on a website before that needs to crawl data on a scheduled basis. After trying several solutions, I finally used uWSGI's signal, which is more stable.
阿神2017-04-18 09:25:53
You can also use independent Celery, just use Celery's beat for scheduled tasks.
黄舟2017-04-18 09:25:53
You can use crontab directly. If you want to better manage the scheduled process (such as using the supervisord tool), you can use celery scheduled tasks.
Here is a question: Flask configures celery scheduled tasks
高洛峰2017-04-18 09:25:53
For scheduled tasks, I usually use huey. I have used crontab before, but the virtual environment on the server cannot be activated using the script. I have been working on it for a long time without solving it. Then I found huey, which is actually similar to the django project. An app is installed that can implement multi-threading, periodicity and other functions.
ringa_lee2017-04-18 09:25:53
You can use Scheduler, because the content is a bit more, if you need examples, you can contact me.