0

I'm adding a job to a scheduler using apscheduler using a script. Unfortunately, the job is not properly scheduled when using a script as I didn't start the scheduler.

scheduler = self.getscheduler() # initializes and returns scheduler
scheduler.add_job(trigger=trigger, func = function, jobstore = 'mongo') #sample code. Note that I did not call scheduler.start()

I'm seeing a message: apscheduler.scheduler - INFO - Adding job tentatively -- it will be properly scheduled when the scheduler starts

The script is supposed to add jobs to the scheduler (not to run the scheduler at that particular instance) and there are some other info which are to be added on the event of a job added to the database. Is it possible to add a job and force the scheduler to add it to the jobstore without actually running the scheduler?

I know, that it is possible to start and shutdown the scheduler after addition of each job to make the scheduler save the job information into the jobstore. Is that really a good approach?

Edit: My original intention was to isolate initialization process of my software. I just wanted to add some jobs to a scheduler, which is not yet started. The real issue is that I've given permission for the user to start and stop scheduler. I cannot assure that there is a running instance of scheduler in the system. I've temporarily fixed the problem by starting the scheduler and shutting it down after addition of jobs. It works.

Raghu Venmarathoor
  • 858
  • 11
  • 28

1 Answers1

0

You would have to have some way to notify the scheduler that a job has been added, so that it could wake up and adjust the delay to its next wakeup. It's better to do this via some sort of RPC mechanism. What kind of mechanism is appropriate for your particular use case, I don't know. But RPyC and Execnet are good candidates. Use one of them or something else to remotely control the scheduler process to add said jobs, and you'll be fine.

Alex Grönholm
  • 5,563
  • 29
  • 32
  • I've no idea how to use RPC with this. I'll try it out and inform later. My concern is that the scheduler already knows that the job is supposed to be added. It is waiting till the scheduler is started, which I am not intended to do at that particular instant. I hope we both are in the same page. I'm using python and apscheduler. Thanks anyway. – Raghu Venmarathoor Mar 06 '15 at 12:43
  • Did I misunderstand your requirements? Are you not adding the jobs in a process that will not eventually start the scheduler? I thought that was it. – Alex Grönholm Mar 07 '15 at 20:01
  • I haven't used RPC in my life and I sort of got confused when I read your answer. I was trying to implement an initialization of my software. I just wanted to add some jobs to scheduler, without starting the scheduler at all. I've temporarily fixed the problem by starting the scheduler and stopping it afterwards. Is that really a right approach? The real issue is that I've given control to user to start and stop scheduler, by the current design, I might not be able to ensure that an instance of Scheduler is running when jobs are added. – Raghu Venmarathoor Mar 07 '15 at 20:42
  • Well, this is problematic. APScheduler was not designed to be used like this. The reason it doesn't add jobs to the job store before starting up is because the user could do additional configuration before that, and this will affect the final job parameters. – Alex Grönholm Mar 09 '15 at 00:17
  • Thanks. I'll figure out something. At least, starting and stopping works for now. – Raghu Venmarathoor Mar 09 '15 at 08:10