【问题标题】:Apscheduler Job in Django executes twiceDjango 中的 Apscheduler Job 执行两次
【发布时间】:2021-08-25 13:13:36
【问题描述】:

计划的作业以纳秒为单位执行两次。我在 task.py

中有如下任务
def print_hello():
   print("time-->",datetime.datetime.now())
   print("hello")

def print_world():
   print("time-->",datetime.datetime.now())
   print("hello")

scheduler = BackgroundScheduler()
scheduler1 = BackgroundScheduler()

从 app 文件夹中添加 app.py 包含以下代码行..

from django.apps import AppConfig
from datetime import date
class ExploitDataConfig(AppConfig):
     name = 'exploit_data' 

     def ready(self):
    
         from exploit_data import task   

         task.scheduler.add_job(task.print_hello, 'interval', minutes=5)
         task.scheduler1.add_job(task.print_world, 'interval', minutes=5
         task.scheduler.start()
         task.scheduler1.start()

我希望它只执行一次,间隔为 5 分钟。 任何帮助都是值得的 ..

【问题讨论】:

标签: python django django-rest-framework scheduler apscheduler


【解决方案1】:

也许这会有所帮助:

python manage.py runserver --noreload

【讨论】:

  • 感谢它有效,但我认为这不是问题的标准解决方案..
猜你喜欢
  • 2013-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-28
  • 2013-10-03
  • 2015-04-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多