I am trying to get APScheduler to return the list of jobs but it always returns a none value.
main.py:
def test():
print("test")
app = Flask(__name__)
scheduler.add_job(func=test, trigger='cron', hour='11', minute= '36')
scheduler.start()
@app.route('/viewjobs', methods=['POST'])
def view():
if request.method == 'POST':
string = str(scheduler.print_jobs())
return(string)
if __name == '__main__':
app.run()
Now when i send a POST request using curl i get None. what am i doing wrong?
If you look at the documentation, it clearly says that print_jobs()
prints a formatted list of jobs to the standard output. The function call returns None
. A quick fix would be to use a StringIO object as the output sink and return its contents:
buffer = io.StringIO()
scheduler.print_jobs(out=buffer)
return buffer.getvalue()
Disclaimer: I have not tested this in practice.