question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG!! Apscheduler modify do not work when you update a cron job from later to early

See original GitHub issue

I found a bug that, if you firstly add a cron style job which will be scheduled at tomorrow, such as notify_job (trigger: cron[day_of_week='0-6', hour='0-2', minute='0-59', second='0-59'], next run at: 2017-10-25 00:00:00 CST)

then if you modify it by early, such as notify_job (trigger: cron[day_of_week='0-6', hour='*/', minute='*/5', second='*/20'], next run at: 2017-10-25 00:00:00 CST)

it will think hour is tomorrow; it does not work!!! following is my code snippet, it is dangerous!

task1 = scheduler.add_job(job_func, trigger='cron', day_of_week='0-6', hour='19,21', minute='*/5', second='0,10,20,30,30,40,40,50', args=[action, 'disk1', 'disk1'], end_date='2017-12-30')
job_func = clouds.cron.jobs.notify_job
task2 = scheduler.add_job(job_func, trigger='cron', day_of_week='0-6', hour='0-2', minute='0-59', second='0-59', args=['disk2', succ_callback, fail_callback])
task3 = scheduler.add_job(job_func, trigger='interval', seconds=20, args=['disk3', succ_callback, fail_callback])

scheduler.print_jobs()

time.sleep(5)
scheduler.remove_job(task3.id)

scheduler.print_jobs()


time.sleep(5)

from apscheduler.triggers.cron import CronTrigger
trigger = CronTrigger(day_of_week='0-6', hour='*', minute='*/5', second='*/20', end_date='2017-10-31')
# import pdb
# pdb.set_trace()
scheduler.modify_job(task2.id, trigger=trigger, args=[action, succ_callback, fail_callback], coalesce=True)
# scheduler.reschedule_job(task2.id)

print scheduler.get_job(task2.id)

time.sleep(10)
print 'pausing......'
scheduler.pause()

time.sleep(5)
print 'resuming......'
scheduler.resume()

output:

The job 2119531081404a19bf9366df356a9688 added
The job bb46475c58684677971a43d39541006e added
The job 544f0b1203e74f68be3c3b0af3c18d7b added
Jobstore default:
    notify_job (trigger: interval[0:00:20], next run at: 2017-10-24 19:58:47 CST)
    job (trigger: cron[day_of_week='0-6', hour='19,21', minute='*/5', second='0,10,20,30,30,40,40,50'], next run at: 2017-10-24 21:00:00 CST)
    notify_job (trigger: cron[day_of_week='0-6', hour='0-2', minute='0-59', second='0-59'], next run at: 2017-10-25 00:00:00 CST)
The job 544f0b1203e74f68be3c3b0af3c18d7b removed
Jobstore default:
    job (trigger: cron[day_of_week='0-6', hour='19,21', minute='*/5', second='0,10,20,30,30,40,40,50'], next run at: 2017-10-24 21:00:00 CST)
    notify_job (trigger: cron[day_of_week='0-6', hour='0-2', minute='0-59', second='0-59'], next run at: 2017-10-25 00:00:00 CST)
The job bb46475c58684677971a43d39541006e modified
notify_job (trigger: cron[day_of_week='0-6', hour='*', minute='*/5', second='*/20'], next run at: 2017-10-25 00:00:00 CST)
pausing......
resuming......

I also query mysql database to make sure it is, and the time in next_run_time always keep the same in tomorrow!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kitianFreshcommented, Nov 14, 2017

@agronholm I FOUND reschedule_job function can not modify job’s function args parameter, right?

sched.reschedule_job(self.id,
                     name=self.name,
                     misfire_grace_time=options.misfire_grace_time,
                     max_instances=options.max_instances,
                     coalesce=options.coalesce,
                     trigger=trigger,
                     func=cronjob,
                     args=[data['action'],None,None])

just trigger is valid, other do not! so if i want to modify and take effective immediately, I must first use modify and then use reschedule

1reaction
kitianFreshcommented, Nov 1, 2017

I think reschedule and modify job is very buggy!

Read more comments on GitHub >

github_iconTop Results From Across the Web

User guide — APScheduler 3.9.1 documentation
Job instance that you can use to modify or remove the job later. You can schedule jobs on the scheduler at any time....
Read more >
APScheduler Documentation - Read the Docs
Job instance that you can use to modify or remove the job later. You can schedule jobs on the scheduler at any time....
Read more >
Trigger 'cron' do not working in apscheduler 3 while 'interval ...
But it seems do not run the job correctly. In the following simple case, the trigger "interval" can work, but "cron" won't.
Read more >
Flask APScheduler - Cron Job only happens with active users ...
IMHO, it is not a good idea to used Apache + Webapp to run scheduled tasks. If your are under Windows, why don't...
Read more >
python-APScheduler - In-process task scheduler with Cron-lik...
You can add new jobs or remove old ones on the fly as you please. If you store your jobs in a database,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found