【问题标题】:APScheduler repeat jobs after previous run has finished上一次运行完成后,APScheduler 重复作业
【发布时间】:2016-03-21 17:39:46
【问题描述】:

我正在使用 GeventScheduler 使用 APScheduler 运行两个作业。但我希望此作业暂停运行,例如 1 分钟,并且在上一次运行完成后,所有任务重复此作业。我怎样才能做到这一点?

【问题讨论】:

  • 在第一个脚本的末尾添加一个sleep 怎么样?
  • 它们必须异步工作并处理大量数据,所以我什至不知道脚本应该在两次运行之间休眠多长时间。

标签: python apscheduler


【解决方案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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-28
    • 1970-01-01
    • 2010-11-29
    相关资源
    最近更新 更多