I have a process from 10 seconds, but after the 10 seconds, I don't need to return the information to the user but write it down on a dynamoDB, that's why I would like the user doesn't have to wait 10 seconds. Instead, I would like an immediate "Success" response after the post request.
I read a couple of posts and in this one, the answer was with a Teardown Callback, but there wasn't an example.
I read then this, but it doesn't help me with my problem.
I read of course teardown-callbacks and this pattern but I don't know how I could use it another way.
My code looks like this:
@app.route('/ocr/read_image', methods=['POST'])
def get_text():
return jsonify('Success')
@app.teardown_request
def teardown_request(response):
time.sleep(10)
It actually returns the "Success" Message but just after the 10 seconds.
Is there a way to return the "Succes" Message before the 10 seconds?
I've been reading that it's maybe possible with celery but I would love avoid it if I can.
Does anyone know how to do it?