I using Python Flask to along with apscheduler and trying to add/remove jobs as follows:
sched = Scheduler()
sched.start()
print "Schedular Started"
def new_job():
@sched.interval_schedule(seconds=2)
def job_function():
print "Hello World"
@app.route('/add')
def add():
new_job()
return 'started'
This bit works as expected. However, when I try to remove the job, like shown here:
@app.route('/remove')
def remove():
sched.unschedule_job(job_function.job)
return "Removed"
I'm getting a
NameError: global name 'job_function' is not defined" as expected.
My question is how can I remove a job using a different route?
Regards.
OK Sorted it!
For anybody else that needs to do this:
@sched.interval_schedule(seconds=2)
def job_function():
print "Hello World"
Then:
sched.unschedule_job(job_function.job)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With