Good day SO,
I am currently using Django, and the Django-Background-Tasks package. I have a periodic task that I need to run at midnight, and it is to be repeated every midnight.
I am a beginner at using the package, and am confused by the following:
Here is my code:
from background_task import background
from datetime import datetime, date
today_date = datetime.datetime.today()
today_midnight = today_date.replace(hour=23, minute=59, second=59)
@background(schedule=today_midnight)
def send_reminders():...
send_reminders(repeat=Task.DAILY)
I wanted to set the parameter 'repeat' to task.DAILY, as stated in the documentation. However, I have encountered the following:
NameError: name 'Task' is not defined
I know I have to import something to define Task, but I couldn't find it. Can anyone help me?
This is defined in the background_task.models
module [GitHub]. So you should import this with:
from background_task.models import Task
DAILY
itself just specifies the number of seconds, so 24×60×60=86'400:
class Task(models.Model): # ... HOURLY = 3600 DAILY = 24 * HOURLY
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With