Apscheduler interfering task fails
I would like my main fire to be on at 6 am every day. but for testing purposes I set the interval to 5 seconds. The problem is, it never seems to work. I have a breakpoint in the maintask method that was never hit and nothing is printed to the console. I am guessing it doesn't work.
ETA: my code ends up in scheduler.start () where it stops because it is blocking. it should start my maintask in 5 seconds, but it never does.
python version is 2.7 apscheduler version 3.0.
I ran it on Windows and the same Debian result.
Here is my code.
from apscheduler.schedulers.blocking import BlockingScheduler
import datetime
def maintask():
print("blah")
def main():
scheduler = BlockingScheduler()
print("Scheduling Tasks")
start_time = (datetime.datetime.now()).replace(hour=6, minute=0, second=0, microsecond=0)
scheduler.scheduled_job(maintask, 'interval', id="MainTaskid", name="mainTask", start_date=start_time, seconds=5, misfire_grace_time=60)
print("Tasks Scheduled")
print("Running Tasks")
scheduler.start()
print("Good Bye")
return 0
if __name__ == "__main__":
main()
source to share
The problem is what you are using scheduled_job
instead of add_job
.
As the User's Guide explains , it scheduled_job
is mainly intended to be used as a decorator because it is "a convenience for declaring jobs that are not used by application runtime modification," while the latter is the "most common way" to add jobs.
In this particular case, I believe the problem is what is add_job
causing the scheduler to wake up and scheduled_job
doesn't - which you don't think is relevant, except for the fact re relying on this wake up to get the misfire check to work at startup. and not tomorrow until 6 in the morning.
Anyway, a simple change doesn't add_job
solve the problem.
source to share