search

Home  >  Q&A  >  body text

python - 请教一下大家,在django或者其他的项目中做定时任务?

有时候,需要在项目中做一些定时的任务,例如:我需要每隔几分钟去访问一个接口,然后根据返回值,做后续操作。

请教下,如何来实现?(PS:如果是用系统的crontab就不要说了。)

目前google了一种方法是使用celery。请加下大家,是否是条长期可行之路。
PHPzPHPz2893 days ago404

reply all(8)I'll reply

  • PHP中文网

    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.

    reply
    0
  • PHPz

    PHPz2017-04-18 09:25:53

    django-celery can meet your requirements

    reply
    0
  • 阿神

    阿神2017-04-18 09:25:53

    You can also use independent Celery, just use Celery's beat for scheduled tasks.

    reply
    0
  • 黄舟

    黄舟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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:25:53

    Someone made a Django module: django_crontab

    reply
    0
  • 高洛峰

    高洛峰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.

    reply
    0
  • 阿神

    阿神2017-04-18 09:25:53

    Why not use crontab? crontab is the most stable.

    reply
    0
  • ringa_lee

    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.

    reply
    0
  • Cancelreply