top of page

Python's Schedule API


One of the main features of my project is sending notifications to my users about the who and the how of the person they should reach out to. There are a few options that I researched:

Heroku Scheduler:

Sounds like exactly what I need, minus the limitation of the frequency: every 10 mins, every hour, or everyday. I'll need one script to run monthly and another quarterly.

Cron:

After investing a solid day into trying to schedule a cronjob using a Python script, I searched for alternatives and came across a unicorn - the Schedule API.

The Schedule API is used for scheduling jobs with Python. For those interested in using it, here's a quick tutorial:

$ pip install schedule

def job():

print "Scheduling away."

schedule.every(30).seconds.do(job)

while True:

schedule.run_pending()

And that's it! If your function requires parameters, create a separate function whose sole purpose is to call the other function, inclusive of the arguments. Note that the function call within the method .do() cannot contain parenthesis. This structures the scheduler like an event-listener. The function above is set to be called every 30 seconds just for testing purposes, but the execution frequency can be customized further. Check out Daniel Bader's Github for the syntax.

My send_event_notification function (within sendnotif.py) sends an email, requiring the recipient's name and email address as well as a portion of the content as parameters. The next challenge on my plate is figuring out how to call this script every time a new Contact is added.

Recent Posts
Archive
bottom of page