I have this code here
# it's not every five mins but let's overlook that for now
@periodic_task(crontab(minute='*/1'))
def every_five_mins():
# ...
But I couldn't find where Huey calls the function. The only other place that I've used Huey is in settings.py
but still I only included
HUEY = {
'huey_class': 'huey.RedisHuey',
'name': DATABASES['default']['NAME'],
'results': True,
'store_none': False,
'immediate': False,
'utc': True,
'blocking': True,
'connection': {
'host': 'localhost',
'port': 6379,
'db': 0,
'connection_pool': None,
'read_timeout': 1,
'url': None,
},
'consumer': {
'workers': 1,
'worker_type': 'thread',
'initial_delay': 0.1,
'backoff': 1.15,
'max_delay': 10.0,
'scheduler_interval': 1,
'periodic': True,
'check_worker_health': True,
'health_check_interval': 1,
},
}
Can anyone please tell me how a task is executed? I want to know this because I want to pass in parameters into every_five_mins()
, e.g., every_five_mins(argument1=argument1)
but I can't do that without knowing where the function is called (otherwise argument1 is going to raise an undefined error).
Thanks in advance.
Periodic tasks are called by the consumer (you're running one right?) and I believe the design is such that you aren't meant to pass parameters to these - how would you even pass arguments to the consumer? I'm sure you can come up with a design but to me it doesn't really make sense. From the docs:
Depending on your needs, you may be able to achieve what you want by calling a function that returns some parameters for use within the task:
Alternatively, you can also define periodic tasks dynamically. Copying over the example from the docs (note, this doesn't work with process workers -- see link to docs):