Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use python-crontab to schedule scripts instead of manually entering in crontab #13

Open
tmthyjames opened this issue Sep 28, 2017 · 2 comments

Comments

@tmthyjames
Copy link
Owner

This library looks promising for scheduling cron jobs from python. This centralizes all of the cron work. If a cron job changes or gets renamed or whatever, a migration script can be written.

@huangsam
Copy link
Contributor

Cool, never heard of that library. You can look into celery to see if it fits your use case.

@sparklespdx
Copy link
Contributor

sparklespdx commented Apr 14, 2018

I'm using https://pypi.python.org/pypi/APScheduler in another project and it works really well for me. There's a flask extension but I'm not a big fan of how it is configured. However, since it's all happening outside the request context, you don't really need to integrate it with Flask, I just run it in the main application loop and it works fine, logs to stdout like you would expect. With the cron scheduler you don't even really need a message queue for this, can just use the in-memory one.

The nice thing about a pure python implementation is that it makes it easy to deploy the application in Heroku and such.

Check it out and tell me what you think, here's some example code. The task runners take the Flask app object as an argument so they can have the config:

def start_and_run_scheduler(app):

    def assignments(app):
        assign_hosts_to_teams(app)
        assign_users_to_teams(app)

    sched = BackgroundScheduler()
    # Every hour at :10
    sched.add_job(assignments, 'cron', minute=10, args=(app,),)
    # Every day at Midnight
    sched.add_job(fill_ddi_cache, 'cron', hour=0, minute=0, args=(app,), )
    sched.start()
    logger.info('Started task scheduler')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants