I'm working on a flask app which continuously keeps checking for new messages from an AWS SQS queue and receives them. For this specific I've written a function which can be triggered by an endpoint. - /start
. For simplicity, in the code, I haven't posted all the logic for receiving messages from SQS queue. Just printing datetime and waiting for 3 seconds.
How do I make this endpoint to be hit as soon as the flask server is up and ready to serve the requests?
Is there any decorator or something to make this possible?
quque_services.py:
from datetime import datetime
import time
def receive_messages():
print(datetime.now())
time.sleep(3)
__init__.py:
from flask import Flask, request, jsonify
from app.workload.services.queue_services import receive_messages
def create_app(**kwargs):
app = Flask(__name__, **kwargs)
@app.route('/start')
def queue_receiver():
while True:
receive_messages()
return app
wsgi.py:
from app import create_app
application = create_app()
if __name__ == "__main__":
application.run()