Scheduling a regular event: Cron/Cron alternatives (including Celery)

前端 未结 4 1000
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-03 10:56

Something I\'ve had interest in is regularly running a certain set of actions at regular time intervals. Obviously, this is a task for cron, right?

Unfortunately, the In

4条回答
  •  你的背包
    2021-02-03 11:20

    I had the same problem, and held off trying to solve it with celery (too complicated) or cron (external to application) and ended up finding Advanced Python Scheduler. Only just started using it but it seems reasonably mature and stable, has decent documentation and will take a number of scheduling formats (e.g. cron style).

    From the documentation, running a function at a specific interval.

    from apscheduler.scheduler import Scheduler
    sched = Scheduler()
    sched.start()
    def hello_world():
        print "hello world"
    sched.add_interval_job(hello_world,seconds=10)
    

    This is non-blocking, and I run something pretty identical by simply importing the module from my urls.py. Hope this helps.

提交回复
热议问题