"504.0 GatewayTimeout" On Deployed Flask Web Application's do_task() function

Henrik Vlijter 0 Reputation points
2024-06-27T13:03:26.35+00:00

My Flask app is currently hosted on Azure and was deployed through docker hub. Once a form is submitted the do_task() function is called. This function takes a long time as it is using WhisperX. The program runs without problem locally but Azure's 240s limit stops me out and returns the error "504.0 GatewayTimeout". How can I go about running my program error-free on Azure?

Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,506 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,567 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
829 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. YutongTie-MSFT 47,991 Reputation points
    2024-06-29T09:38:30.2666667+00:00

    Hello @Henrik Vlijter

    Thanks for reaching out to us, could you please share more details like the error message and logs?

    Without further details, I would high recommend your raising a support ticket for this issue and investigate this issue further with support engineer. Please share the support ticket number once you create it, please also let us know if you have no support plan, I am happy to enable you a free ticket for this issue.

    To answer the question generally, to handle long-running tasks like do_task() in your Flask application hosted on Azure without encountering the "504.0 GatewayTimeout" error, you need to implement an asynchronous processing approach.

    Azure Functions is a serverless compute service that allows you to run event-driven code without managing infrastructure. For long-running tasks, you can leverage Azure Durable Functions or background processing techniques:

    • Azure Durable Functions: Suitable for orchestrating workflows and managing long-running tasks. You can break down do_task() into smaller steps and manage its execution flow.
    • Background Processing with Azure Functions: Use Azure Storage Queues or Azure Service Bus queues to decouple your web application from do_task(). The web application enqueues a message to trigger do_task() asynchronously.

    I hope this helps.

    Regards,

    Yutong

    -Please kindly accept the answer if you feel helpful to support the community, thanks a lot.

    0 comments No comments