Sanket Patel
Sanket Patel

Reputation: 283

Scheduling a task at particular time using django-background-tasks

I am trying to use django-background-tasks to schedule a task at midnight and then repeat daily. I am able to achieve repeat feature but unable to get it to run at scheduled time.

The timezone in my django project is UTC.

Something i have tried so far:

now = datetime.datetime.now()

date = datetime.date(now.year, now.month, now.day)
print(timezone.get_current_timezone())
time = datetime.time(9, 49, 0, tzinfo=timezone.get_current_timezone())
aware_datetime = datetime.datetime.combine(date, time)
schedule_email_notification(schedule=aware_datetime, repeat=Task.DAILY)

Documentation is not clear on how to do so. If someone can help?

Upvotes: 2

Views: 2111

Answers (1)

Sanket Patel
Sanket Patel

Reputation: 283

I was able to find an answer afterwards.

date = datetime.datetime(year=current_year, month=current_month, day=current_day, hour=schedule_hour, minute=schedule_minute)
#pass the date to schedule parameter
schedule_email_notification(schedule=date, repeat=Task.DAILY)

Upvotes: 2

Related Questions