Reputation: 721
I'm trying to set up a Flask API Server from which I can data from local database via an ongoing HTTP Request to another database.
In the local code, I run a thread that is running and updating the local DB every 1 minute.
app = Flask(__name__)
cached_event_log = None
@app.route('/event_log', methods=['GET'])
def get_event_log():
if cached_event_log != None and .get_latest_event_time == cached_event_log[-1]:
return jsonify(cached_event_log)
#MAKE CONNECTION TO DB AND GET THE DATA
return jsonify(event_log)
if(__name__ == '__main__'):
app.run(Debug=True)
I'm struggling to find a "standard" way to set up A request.
Any opinion would be highly appreciated- Thank you,
Upvotes: 0
Views: 1311
Reputation: 247
You could set up a cron job to run a script at a specified interval
Or use something like Advanced Python Scheduler https://apscheduler.readthedocs.io/en/3.0/
Advanced Python Scheduler support in Flask https://github.com/viniciuschiele/flask-apscheduler
Upvotes: 2