re_schedule() 抛出 id not found 错误
re_schedule() throwing id not found error
我正在尝试构建一个调度程序,其中一个用例是检查作业依赖关系并将依赖作业的执行延迟 20 分钟。
以下是我的例子,
from apscheduler.schedulers.blocking import BlockingScheduler
import datetime
import logging
sched = BlockingScheduler()
log_file_path="path\to\log\file"
@sched.scheduled_job('cron', day_of_week='mon-fri', hour=19, minute=53)
def scheduled_job():
sched.add_job(run_job, id='demo_reschedule')
logging.info("Schdeuled job at {}".format(datetime.datetime.now()))
def run_job():
now = datetime.datetime.now()
now_plus_20 = now + datetime.timedelta(minutes = 20)
sched.reschedule_job('demo_reschedule',trigger='date',run_date=now_plus_20)
logging.info("Rescheduled Job demo_reschedule to new time {}".format(now_plus_20))
if __name__ == "__main__":
logging.basicConfig(filename=log_file_path,
filemode='a',
format=('[%(asctime)s] %(levelname)-8s %(name)-12s %(message)s'),
datefmt='%H:%M:%S',
level=logging.INFO)
logging.info("Starting scheduler")
sched.start()
run_job 方法已成功添加,但在执行时,我收到以下错误,
[19:51:14] INFO root Starting scheduler
[19:51:14] INFO apscheduler.scheduler Added job "scheduled_job" to job store "default"
[19:51:14] INFO apscheduler.scheduler Scheduler started
[19:53:00] INFO apscheduler.executors.default Running job "scheduled_job (trigger: cron[day_of_week='mon-fri', hour='19', minute='53'], next run at: 2019-06-07 19:53:00 IST)" (scheduled at 2019-06-07 19:53:00+05:30)
[19:53:00] INFO apscheduler.scheduler Added job "run_job" to job store "default"
[19:53:00] INFO root Schdeuled job at 2019-06-07 19:53:00.024887
[19:53:00] INFO apscheduler.executors.default Job "scheduled_job (trigger: cron[day_of_week='mon-fri', hour='19', minute='53'], next run at: 2019-06-10 19:53:00 IST)" executed successfully
[19:53:00] INFO apscheduler.executors.default Running job "run_job (trigger: date[2019-06-07 19:53:00 IST], next run at: 2019-06-07 19:53:00 IST)" (scheduled at 2019-06-07 19:53:00.023890+05:30)
[19:53:00] INFO apscheduler.scheduler Removed job demo_reschedule
[19:53:00] ERROR apscheduler.executors.default Job "run_job (trigger: date[2019-06-07 19:53:00 IST], next run at: 2019-06-07 19:53:00 IST)" raised an exception
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\apscheduler\executors\base.py", line 125, in run_job
retval = job.func(*job.args, **job.kwargs)
File "path/to/demo_reschedule.py", line 33, in run_job
sched.reschedule_job('demo_reschedule',jobstore=None,trigger='date',run_date=now_plus_20)
File "C:\ProgramData\Anaconda3\lib\site-packages\apscheduler\schedulers\base.py", line 511, in reschedule_job
return self.modify_job(job_id, jobstore, trigger=trigger, next_run_time=next_run_time)
File "C:\ProgramData\Anaconda3\lib\site-packages\apscheduler\schedulers\base.py", line 483, in modify_job
job, jobstore = self._lookup_job(job_id, jobstore)
File "C:\ProgramData\Anaconda3\lib\site-packages\apscheduler\schedulers\base.py", line 816, in _lookup_job
raise JobLookupError(job_id)
apscheduler.jobstores.base.JobLookupError: 'No job by the id of demo_reschedule was found'
根据我的观察,执行作业后,它会立即从作业存储中删除,可能是因为这个原因,它无法找到该作业 ID,但我不确定。
请就如何缓解此问题提出建议。
感谢帮助:)
当调度器提交发现一个调度有运行它的进程时,它将删除该作业。这就是这里发生的事情——作业已提交给执行程序,但它不再存在于作业存储中,因为它的触发器已经 运行 次触发。请尝试添加新工作。
我正在尝试构建一个调度程序,其中一个用例是检查作业依赖关系并将依赖作业的执行延迟 20 分钟。
以下是我的例子,
from apscheduler.schedulers.blocking import BlockingScheduler
import datetime
import logging
sched = BlockingScheduler()
log_file_path="path\to\log\file"
@sched.scheduled_job('cron', day_of_week='mon-fri', hour=19, minute=53)
def scheduled_job():
sched.add_job(run_job, id='demo_reschedule')
logging.info("Schdeuled job at {}".format(datetime.datetime.now()))
def run_job():
now = datetime.datetime.now()
now_plus_20 = now + datetime.timedelta(minutes = 20)
sched.reschedule_job('demo_reschedule',trigger='date',run_date=now_plus_20)
logging.info("Rescheduled Job demo_reschedule to new time {}".format(now_plus_20))
if __name__ == "__main__":
logging.basicConfig(filename=log_file_path,
filemode='a',
format=('[%(asctime)s] %(levelname)-8s %(name)-12s %(message)s'),
datefmt='%H:%M:%S',
level=logging.INFO)
logging.info("Starting scheduler")
sched.start()
run_job 方法已成功添加,但在执行时,我收到以下错误,
[19:51:14] INFO root Starting scheduler
[19:51:14] INFO apscheduler.scheduler Added job "scheduled_job" to job store "default"
[19:51:14] INFO apscheduler.scheduler Scheduler started
[19:53:00] INFO apscheduler.executors.default Running job "scheduled_job (trigger: cron[day_of_week='mon-fri', hour='19', minute='53'], next run at: 2019-06-07 19:53:00 IST)" (scheduled at 2019-06-07 19:53:00+05:30)
[19:53:00] INFO apscheduler.scheduler Added job "run_job" to job store "default"
[19:53:00] INFO root Schdeuled job at 2019-06-07 19:53:00.024887
[19:53:00] INFO apscheduler.executors.default Job "scheduled_job (trigger: cron[day_of_week='mon-fri', hour='19', minute='53'], next run at: 2019-06-10 19:53:00 IST)" executed successfully
[19:53:00] INFO apscheduler.executors.default Running job "run_job (trigger: date[2019-06-07 19:53:00 IST], next run at: 2019-06-07 19:53:00 IST)" (scheduled at 2019-06-07 19:53:00.023890+05:30)
[19:53:00] INFO apscheduler.scheduler Removed job demo_reschedule
[19:53:00] ERROR apscheduler.executors.default Job "run_job (trigger: date[2019-06-07 19:53:00 IST], next run at: 2019-06-07 19:53:00 IST)" raised an exception
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\apscheduler\executors\base.py", line 125, in run_job
retval = job.func(*job.args, **job.kwargs)
File "path/to/demo_reschedule.py", line 33, in run_job
sched.reschedule_job('demo_reschedule',jobstore=None,trigger='date',run_date=now_plus_20)
File "C:\ProgramData\Anaconda3\lib\site-packages\apscheduler\schedulers\base.py", line 511, in reschedule_job
return self.modify_job(job_id, jobstore, trigger=trigger, next_run_time=next_run_time)
File "C:\ProgramData\Anaconda3\lib\site-packages\apscheduler\schedulers\base.py", line 483, in modify_job
job, jobstore = self._lookup_job(job_id, jobstore)
File "C:\ProgramData\Anaconda3\lib\site-packages\apscheduler\schedulers\base.py", line 816, in _lookup_job
raise JobLookupError(job_id)
apscheduler.jobstores.base.JobLookupError: 'No job by the id of demo_reschedule was found'
根据我的观察,执行作业后,它会立即从作业存储中删除,可能是因为这个原因,它无法找到该作业 ID,但我不确定。
请就如何缓解此问题提出建议。
感谢帮助:)
当调度器提交发现一个调度有运行它的进程时,它将删除该作业。这就是这里发生的事情——作业已提交给执行程序,但它不再存在于作业存储中,因为它的触发器已经 运行 次触发。请尝试添加新工作。