gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 21:23:00 26 4
gpt4 key购买 nike

我正在尝试使用 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)

文档并不清楚如何做到这一点。如果有人可以帮忙吗?

最佳答案

后来我找到了答案。

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)

关于python - 使用 django-background-tasks 在特定时间安排任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54094532/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com