Future-proof your skills with Linux, Python, vim & git as I share with you the most timeless and love-worthy tools in tech through my two great projects that work great together.

Switching a Python Scheduler to Huey Task Queue Using Crontab API

In this video, I show how I successfully switched from the Python pip install schedule package to the less Pythonic crontab method of Huey. I walk through the nuances of periodic scheduling, working directory .service file values, and more. Subscribe to my channel for more tips and tricks on switching over to Huey!

Switching to Huey Task Queue Using Crontab API - My Journey and Tips!

By Michael Levin

Tuesday, August 9, 2022

Here’s a video I didn’t think I was going to do. I was going to switch over from one Python Scheduler to another, dealing with the changing “API-language” this entails, going from the very Pythonic “for humans” API of pip install schedule to the much less Pythonic crontab method of Huey, a scheduler with is also really a data pipeline task queue system like the much more popular Python Celery package but with much lower dependencies, so you can run it without all this devops stuff (tech liability).

Over my last several videos, I went from the pip install schedule package from PyPI that has an API that beautifully looks like this:


# Or alternatively, use Python decorators:

def job():
    print("I am a scheduled job")

Task queue (for reliability). To pip install huey whose scheduling portion of their API looks like this: Huey is patterned after the much more popular Celery API.

@huey.periodic_task(crontab(minute='0', hour='3'))
def nightly_backup():

def every_three_minutes():
    print('This task runs every three minutes')

So you see, Schedule allows per-line standalone scheduling instructions with a well designed “API-language” plus the convenience of Python decorators where those “for humans” language conventions carry over.

Huey on the other hand only allows function decorators, which in and of itself is not a bad thing, but the API follows the long-standing Unix conventions of the cron program. Now while it’s generally good to follow the Unix/Linux API-standards, scheduling is one of the more difficult places to do so.

Switching my Munchkin container that currently uses the Python PyPI pip install Schedule package over to Huey is the subject of this video.

Just get to it and make it happen. Do a series of quick, small passes even if you’re producing videos to document it and help people at large dealing with these same issues.

How to test that your scheduler is running when all you have is periodic scheduling and you want a scheduled even to happen moments after you start the scheduler?

There were stumbling blocks having to do with “exact scheduling” vs. periodic scheduling, but we got it to work. Nuances:

Don’t forget to subscribe!