-
Notifications
You must be signed in to change notification settings - Fork 714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add argument wait
of remove_job
and remove_all_jobs
#751
Comments
I think this is a useful feature to have. I'll try to include it in v4.0 if possible. If it's too much work, then I'll target 4.1. |
Is that possible to implement this feature in version 3.x? |
I don't intent to add any new features to the 3.x branch. I have my hands full with so many projects already that working on two APScheduler branches is just not feasible. |
I ran into the same issue of not being able to stop scheduled jobs gracefully. Adding a wait parameter to There is one thing that can be done on its own, which sounds like it would be simpler than converting a bunch of methods to This would allow app-level callbacks to implement their own tracking of whether they are running or not, which is currently impossible because a job may be in transition from being scheduled to when the job callback is called, like this: job.pause() # disables further scheduling
if job.scheduled: # indicates that the job was scheduled before it
# was paused (even before callback is called)
await app_stop_on_start_or_wait_to_finish() , where |
I'm not sure about the terminology: what's a "job" here? |
https://apscheduler.readthedocs.io/en/3.x/modules/job.html#module-apscheduler.job Knowing the job status would allow application code to anticipate whether the job callback is going to be called, so scheduled jobs can be shut down gracefully. |
Sorry, I thought the comment belonged to a very different project, hence the confusion :) |
Thanks for responding. The use case is to be able to wait for (this issue) or be able to cancel (a more generic one) a job that has been scheduled, but the callback for which hasn't been called yet, which is cumbersome to implement reliably without some support from the framework (APscheduler). In practical terms, what I'm running into is that on application shutdown, I remove a scheduled job and I check/wait for an Where this approach fails is that if a job has been scheduled right before it was removed, but the callback hasn't been called yet, so the event says there's no scheduled job running and the app proceeds to shut down other app services, so when the scheduled job callback is called, it ends up with referencing partially destroyed application and with a weird exception like database service is gone, etc. Technically, it is possible to rig the code to set some kind of a die-when-or-if-called flag for the scheduled job before it is removed, but the call may be made when the service handling this scheduled job is destroyed, so there's no way to report anything (i.e. logger service may be gone as well) or handle anything gracefully. Having some job status flag, such as whether it has been scheduled to run, would allow app code to sleep for a moment or two while the just-callback is called and then wait for it to finish or, if allowed, to cancel it in the app code. Thinking aloud, if Sorry for the long post. I hope it makes sense. |
Things to check first
Feature description
remove_job
orremove_all_jobs
ofBackgroundScheduler
should block when there is still running jobs, such asshutdown(wait=True)
.Use case
Without blocking:
With blocking:
The text was updated successfully, but these errors were encountered: