agronholm / apscheduler

Task scheduling library for Python
MIT License
6.18k stars 704 forks source link

Paused jobs do not execute when resumed #856

Closed parisosuch-dev closed 4 months ago

parisosuch-dev commented 8 months ago

Things to check first

Feature description

When a paused job is resumed and it was suppose to be executed while it was paused, it will not execute that job when the job is resumed. I believe this has to do with the next_run_time being removed and calculated on the resuming of the job. It would be great if this feature worked more like the entire scheduler being paused. When the scheduler itself is resumed, any scheduled jobs that would have been ran since pausing are executed on the resuming of the scheduler.

LMK if you want help with this feature.

Use case

I am working on a project that pauses certain groups of jobs based on the state of the system. I want those jobs to begin executing after they are resumed if they were suppose to be executed since the pausing of those jobs.

xLinkOut commented 6 months ago

Hello! I have a question regarding the issue you encountered: did you happen to start the scheduler with the paused=True parameter?

For example:

def job():
    print(datetime.now())

scheduler = BackgroundScheduler()
scheduler.add_job(job, 'interval', seconds=1, id="my_job")
scheduler.start(paused=True)

I ask this because I noticed that, in this case, the scheduler.resume_job("my_job") statement doesn't resume the job execution.

parisosuch-dev commented 5 months ago

Sorry I am late to this response. I don't recall if there was an issue or not. I think it has to do with the ability to unpause jobs and execute them if their execute time has been eclipsed.

Sorry, I cannot help much past that. I no longer work for the company I was under when working on this project.

agronholm commented 4 months ago

Schedule pausing/unpausing has been implemented for v4.0 in #902. That should cover your use case.