I'm attempting to implement the suggested organization of code from the Huey docs into an existing app, and also following the simple example. The goal is to build a crontab that will run the task every day at 3:00 am.
I powered up two terminal tabs, the first one with the consumer running the script from the example:
PYTHONPATH=.:$PYTHONPATH
export WORKER_CLASS=${1:-thread}
huey_consumer.py main.huey --workers=4 -k $WORKER_CLASS -C -S
Then, in the other tab, I run the main.py script:
python main.py
config.py
from huey import SqliteHuey
huey = SqliteHuey(filename='/tmp/huey.db')
tasks.py
from config import huey
# Note that this time is 1 minute before whenever I'm debugging.
# I'm using the 3 am example as what we're aiming for in our final product.
@huey.periodic_task(crontab(minute='0', hour='3'))
def run_this_function():
system = New_Class() # Class instantiation since there's a bunch that happens when a new class is set up
system.run_method # Runs a bunch of methods from the class in one location
main.py
from config import huey
from tasks import run_this_function
def main:
run_this_function()
if __name__ == "__main__":
main()
The task runs immediately, and as I'm brand new to Huey, not sure what I might be missing to make it work on a schedule. I've tried so many crontab combinations, not sure if the challenge is there, or in how I call the run_this_function
in the main
method. Any help is appreciated!