man*_*ari 3 python django scheduler django-rest-framework apscheduler
计划的作业执行两次,差异以纳秒为单位。我在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()
Run Code Online (Sandbox Code Playgroud)
从应用程序文件夹中添加 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()
Run Code Online (Sandbox Code Playgroud)
我希望它仅以5 分钟的间隔 执行一次。任何帮助都是值得赞赏的..