【问题标题】:Scheduling a task at particular time using django-background-tasks使用 django-background-tasks 在特定时间安排任务
【发布时间】:2019-06-03 07:22:01
【问题描述】:

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

    后来我找到了答案。

    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)
    

    【讨论】:

      猜你喜欢
      • 2020-01-10
      • 1970-01-01
      • 2019-07-07
      • 2015-08-29
      • 2012-08-01
      • 2012-09-18
      • 2010-12-31
      • 1970-01-01
      相关资源
      最近更新 更多