HNHacker News
TopNewBestAskShowJobs

dbader

328 karma · joined January 7, 2013

blog: https://dbader.org/ email: mail@dbader.org twitter: https://twitter.com/dbader_org
submissionscomments
dbader··on Ask HN: Mailing lists that HN readers ought to know about?
Hey, Dan Bader here. I just wanted to say thanks for including my Python Tricks (https://dbader.org/python-tricks) series in your list, that's awesome :-)
dbader··on Utility website to display and share text in a large font to read from a distance
Thank you!
dbader··on Schedule: Python job scheduling for humans.
Thanks :-)
dbader··on Schedule: Python job scheduling for humans.
I use something like this for submitting jobs to beanstalkc:

  schedule.every().hour.do(beanstalkc.put, "my_job_id")
dbader··on Schedule: Python job scheduling for humans.
You're certainly right that the module should provide a main loop of some sort for convenience.

I wasn't totally sure how to implement this to make everyone happy -- some people may want to use time.sleep(), others want threading.Event().wait(). Maybe I'll simply go with something like this:

  def run_forever(sleep_func=time.sleep):
    ...
dbader··on Schedule: Python job scheduling for humans.
Using system utilities like cron, can be suboptimal if all you're trying to do is schedule periodic tasks within an application, e.g. database cleanup tasks, periodic polling of other services etc.

The main gripes with cron are:

- cron can be overkill. It requires maintaining a separate crontab file for your app. Wit schedule you can keep everything in pure Python.

- cron is per machine. Multiple app servers require locks of some sort to prevent job duplication. To solve this, we could put triggered jobs on a shared jobqueue (beanstalkc, resque, ...) and have them processed by several workers.

- cron's syntax, while powerful, can be difficult to understand and maintain. Schedule provides an easy to read syntax based on the builder pattern, e.g. "schedule.every(2).hours.do(job, args)"

Much of this was said in better words by Addam Wiggins: http://adam.heroku.com/past/2010/4/13/rethinking_cron/

I wrote schedule because I needed a lightweight scheduling solution for a Python web service backend. It's 'clockwork' (https://github.com/tomykaira/clockwork) for Python.