Forums

Respond before function closes

I have a flask route that is receiving a message from slack. I have to send a 2xx response to slack within 5s but it starts a function that takes longer than that. I'm waiting for an ai response. I'm not sending the response back so I don't need it to wait, I just need to let it know I got the message.

I tried a lot of things that didn't work like threading, call_on_close or stream_with_context but nothing quite worked.

You could delegate the AI bit to an external queue, see this help page for some ideas.