【发布时间】: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 分钟。 任何帮助都是值得的 ..
【问题讨论】:
-
哪个任务执行了两次?
print_hello? -
@sur.la.route 是 print_hello 和 print_world
-
你可以试试 simple-scheduler [pypi.org/project/simple_scheduler/].它默认在后台工作。您也可以多次使用不同的名称标记相同的函数。 [github.com/Vernal-Inertia/simple_scheduler/blob/main/examples/…
-
@Tanveer 如何安排特定日期的工作?
-
@manojadhikari 特定日期的工作仍在进行中[参见问题标签]。您目前的问题解决了吗?
标签: python django django-rest-framework scheduler apscheduler