1
votes

I have a problem with my Web app on Azure App Service and its timeout. It provides an API that creates a CosmosDB instance in an Azure Resource group. Since its creation takes a lot of time (~ 5 minutes), the App Service timeout (230 seconds) forces the App to return an HTTP Response 500, while the CosmosDB creation is successful. Within the method, the Resource is created and then some operations are performed on it.

        ICosmosDBAccount cosmosDbAccount = azure.CosmosDBAccounts
                    .Define(cosmosDbName)
                    .WithRegion(Region.EuropeNorth)
                    .WithNewResourceGroup(resourceGroupName)
                    .WithDataModelSql()
                    .WithSessionConsistency()
                    .WithDefaultWriteReplication()
                    .Create();

        DoStuff(cosmosDbAccount);

Since I've read that the timeout cannot be increased, is there a simple way to await the Resource creation and get a successful response?

1

1 Answers

0
votes

From your code point of view, you are using .net sdk to implement it.

From the official SDK source code, we should be very clear that the source code uses asynchronous methods to create resources, and finally determines whether the creation is complete by detecting the state value of ProvisioningState.

In webapp, the api we designed should be that it is reasonable to return data immediately after sending the request. If in our api, we need to wait for the asynchronous or synchronous callback result in the SDK, and then return the data, it must take a long time, so the design is unreasonable.

So my suggestion is to use rest api to achieve your needs.

  1. Create (use Database Accounts - Create Or Update)

    The database account create or update operation will complete asynchronously.

    Check the response result.

  2. Check the provisioningState in properties (use Database Accounts - Get)

    If the provisioningState is Succeeded, then we can know the resoure has been created successfully.

    If you want to achieve the same effect as in portal, it is recommended to add a timer to get the state value of provisioningState.