I'm using Django 4.0.4 and huey 2.4.3. What I would like to atchieve it's to run a task everyday at 10am, using a periodic task.
CodePudding user response:
For this you can use via pip install django-celery
and use celery.
from celery.schedules import crontab
from celery.task import periodic_task
@periodic_task(run_every=crontab(hour=10, minute=0))
def every_day():
print("This is run every Monday morning at 10:00")
CodePudding user response:
Since you mentioned that you are using huey
package as part of your code. You can utilize its periodic_task
decorator and add crontab within it.
from huey import crontab
@huey.periodic_task(crontab(hour='10'))
def every_ten_in_the_morning():
print('This task runs every 10 in the morning.')
You can also check its documentation to know more about huey periodic task : https://huey.readthedocs.io/en/latest/guide.html#periodic-tasks