使用django-background-tasks在特定时间安排任务

问题描述 投票:1回答:1

我正在尝试使用django-background-tasks在午夜安排任务,然后每天重复。我能够实现重复功能但无法让它在预定时间运行。

我的django项目中的时区是UTC。

到目前为止我尝试过的东西:

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)

文档不清楚如何这样做。如果有人可以帮忙吗?

python django background-task
1个回答
0
投票

之后我能够找到答案。

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)
© www.soinside.com 2019 - 2024. All rights reserved.