'How detect if slot swapping is in progress

Im using .net sdk fluent azure API to change slots. I have two slots, prod and maintenance. I use azure queue trigger function to update appsettings, restart function and swap slots. This is code:

//TODO:checking if swapping is in progress, if not run below code
       var targetSlot = maintenanceSlot.Parent;
       _logger.LogInformation("Updating slot settings");
       maintenanceSlot.Update().WithAppSetting(credential.DirectorySettingName, directoryId).Apply();
       _logger.LogInformation("Restarting slot");
       await maintenanceSlot.RestartAsync();

       _logger.LogInformation("Swaping {SlotName} with production", credential.DeploymentSlotSufix);
       await targetSlot.SwapAsync(maintenanceSlot.Name);
       _logger.LogInformation($"Swaping finish for: {directoryId}");

It takes about 2-7 minutes to swap slots. The main problem is that this code can be triggered several times in short time period for the same environment. If swaping is in progress when I run this code I got 409 confilct error. I dont want to catch this error. I want to check if swapping is in progress. Is it possible to check that?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source