2

I'm running two jobs with APScheduler with GeventScheduler. But I want this jobs to run with pause, for example 1 minute and after the previous run has finished all tasks repeat this jobs. How can I achieve this?

yshalenyk
  • 45
  • 4
  • How about adding a [sleep](http://stackoverflow.com/questions/510348/how-can-i-make-a-time-delay-in-python) to the end of the first script? – Tim S. Mar 21 '16 at 17:53
  • They have to work asynchronically and process a lot of data, so I even don't know how long script should sleep between two runs. – yshalenyk Mar 22 '16 at 07:45

1 Answers1

2

This is worked for me

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)
Mark Zhang
  • 1,038
  • 1
  • 8
  • 8