1

For a scenario with sales orders, I'm needing to execute a task with a given delay.

To accomplish this, I added a task in my tasks.py file like so:

from huey import crontab
from huey.contrib.djhuey import db_task

@db_task(delay=3600)
def do_something_delayed(instance):
    print("Do something delayed...by 3600 seconds")

However, this delay setting doesnt seem to delay anything. The task is just scheduled and executed immediately.

What am I doing wrong?

S.D.
  • 2,486
  • 1
  • 16
  • 23

1 Answers1

2

Thanks to coleifer on the GitHub repo: https://github.com/coleifer/huey/issues/678#issuecomment-1184540964

The task() decorators do not accept a delay parameter, see https://huey.readthedocs.io/en/latest/api.html#Huey.task

I assume you've already read the docs on scheduling/delaying invocations of tasks: https://huey.readthedocs.io/en/latest/guide.html#scheduling-tasks -- but this applies to individual invocations.

If you want your task to always be delayed by 1 hour, the better way would be:

@db_task()
def do_something(instance):
    print("Do something")

def do_something_delayed(instance):
    return do_something.schedule((instance,), delay=3600)
S.D.
  • 2,486
  • 1
  • 16
  • 23