我正在使用 APScheduler 运行两项作业与 GeventScheduler。但我希望此作业暂停运行,例如 1 分钟,并在上一次运行完成后所有任务重复此作业。我怎样才能实现这个目标?
最佳答案
这对我有用
def execution_listener(event):
job_id = event.job_id
if event.exception:
logging.error('job_id={} error!'.format(event.job_id))
else:
logging.info('job_id={} success'.format(event.job_id))
# check that the executed job is the first job
if job_id == CONST.JOB_ID.WORKEXP_CUT:
run_job_now(job_id, arg_dict)# run ypur job
def run_job_now(job_id, arg_dict):
logging.info('id={} start'.format(job_id))
job = scheduler.get_job(job_id)
if job:
job.modify(next_run_time=datetime.datetime.now())
else:
scheduler.add_job(next_run_time=datetime.datetime.now(), **arg_dict)
scheduler.add_listener(execution_listener, EVENT_JOB_EXECUTED | EVENT_JOB_ERROR)
关于python - APScheduler 在上次运行完成后重复作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36138049/