S
S
s1dney2014-08-12 13:21:47
Task Schedulers
s1dney, 2014-08-12 13:21:47

How to implement periodic jobs in python/flask?

There is such a micro-project on the flask micro-framework. There was a need for periodic cron-like jobs, with the ability to flexibly control this matter (change the interval or suspend the job altogether).
I have seen this many times on production servers, and I don’t want to do this:

*/10     *       *       *       *       /var/www/project/tasks.py

I considered the option with Celery, but this solution looks too cumbersome for such an elementary task, after all, this is a tool for slightly different tasks, and I don’t want to run extra services.

Still, of course, you can write some kind of cron-bike on your knee, but this option is considered last.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
alexeiiromanoff, 2014-08-12
@alexeiromanoff

If you don't like unix cron and celery, the only option seems to be to write your own cron service.
In this case, the format for describing tasks can be more human. Yes, and overhead on the generation of processes can be avoided.
For example, the developers of Google App Engine did just that:
https://developers.google.com/appengine/docs/pytho...
I remember writing a simple script that parsed files similar to crontab and started tasks under Windows. This had to be done, because. The task scheduler under Windows is a very crooked and unreliable animal. My Python script registered as a Windows service and worked for 3 years without any problems, while doing its job.

K
Konstantin Kitmanov, 2014-08-12
@k12th

You need a delayed delivery message queue. Beanstalk and RabbitMQ can do this with a clever hack.

S
s1dney, 2014-08-25
@s1dney

I tried to tie Celery, but it looked like a crutch, and I wrote a very primitive algorithm for running tasks inside the Flask application, saving intermediate execution information in an existing database. Tasks are executed in separate threads.
Minimal overhead and 100 more lines of code to synchronize and restore tasks after uwsgi down.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question