0

I am experiencing that my job is executed twice when i remove a job from apsheduler and then add another job with same job id.

if sched.get_job(str(id)) is not None:
    if schedule=='minutely':
        sched.modify_job(str(id), lambda: seedset_harvest(id),id=str(id), trigger='cron', minute='*/1', start_date=s, end_date=e)
else:
    if schedule=='minutely':
        sched.add_job(lambda: seedset_harvest(id),id=str(id), trigger='cron', minute='*/1', start_date=s, end_date=e)

I am trying to schedule a job every minute here. If the job doesn't exists, i am able to schedule my job properly, but if it exists, the job is executed twice at each trigger(in this case at each minute) instead.

Here I am trying to check if a job with a given id exists, if it does then i am modifying it. I am using modify_job(id, **changes). Only in this case the job is executed twice.

I would appreciate if anyone can tell what's wrong with the code here.

Please let me know if the information i provided is insufficient here and i will edit my post.

NOTE: sched is my sheduler here.

Rajat Vij
  • 689
  • 1
  • 6
  • 12
  • Why are you not able to pass the changes to job_modify()? Also, please don't use a lambda when you should be passing `args` instead. – Alex Grönholm Dec 05 '15 at 08:39
  • @AlexGrönholm Thanks for replying. It is some issue with how i was constructing the **changes. I am able to work it out now. I will update my post shortly. And i am passing lambda to execute the function i am scheduling. When i was looking into how to execute a function on each trigger i found this way to be a bit cleaner and it worked for me. – Rajat Vij Dec 07 '15 at 15:37
  • I don't think I can help you unless I get a script that I can run myself and reproduce the problem locally. – Alex Grönholm Dec 08 '15 at 15:54
  • I just noticed -- why are you passing the id to modify_job()? Also, modify_job() only takes one positional arguments and you're passing two to it. So it can never work this way. – Alex Grönholm Dec 08 '15 at 15:59
  • Another thing -- it looks like you're trying to reschedule the job. That's what the `reschedule()` method is for. – Alex Grönholm Dec 08 '15 at 16:04
  • I am able to user modify_job() now, it was just the way i was passing variable were incorrect. And i need to use modify_job() because apart from rescheduling i am changing the output of the function that i am calling in the job by calling the function at runtime using lambda : seetset_harvers(id). – Rajat Vij Dec 09 '15 at 16:34
  • I am thinking that this might not be an Apscheduler issue at all but the way my application is configured as I have 2 processes running from my application and i think when i am modifying the job, the function is executed twice for some reason. I will have to check again. Thanks for helping out. – Rajat Vij Dec 09 '15 at 16:39

0 Answers0