Hacker Newsnew | past | comments | ask | show | jobs | submit | dbader's commentslogin

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 :-)


Thank you!


Thanks :-)


I use something like this for submitting jobs to beanstalkc:

  schedule.every().hour.do(beanstalkc.put, "my_job_id")


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):
    ...


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.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: