Azure-Player / azure.datafactory.tools

Tools for deploying Data Factory (v2) in Microsoft Azure
https://azureplayer.net/adftools
MIT License
209 stars 69 forks source link

Adds TryCatch to StopTrigger, continuing if fails #404

Open henriquebrisola opened 1 month ago

henriquebrisola commented 1 month ago

Hello, I am having an issue sometimes that if one of the triggers fails to be stopped, the whole deploy operation fails. Can we please add this simple try/catch to solve this issue? We might even add a number of tries in the future.

image

NowinskiK commented 1 month ago

In the first instance, I would like to understand why you are experiencing this error ("concurrent operations")? This should have never happened as #adftools does disable triggers one by one synchronously.

henriquebrisola commented 1 month ago

Unfortunately I don't know why this happens, no one should be changing anything directly in production, more than one deploy on master could happen, but I guess it is rare. Maybe some api is changing the trigger status. I not aware of all other projects happening wihtin the company that might influence on this, so my choice is to solve by code.

NowinskiK commented 1 month ago

Did you try to set $ErrorActionPreference = 'Continue' before running the Publish?

henriquebrisola commented 1 month ago

No, but continue is the default value and there is no other value set for it. Woundn't that also make everything else continue even when somethings should report the error? I created workaround, I added the $opt.TriggerStopMethod = 'DeployableOnly' (which starting back is not working due to #386) and then created a method to read all trigger files with runtimeState Started, so I was able to make sure they start back again after the deploy is done.

$triggersEnabledInRepo = ( # Get all triggers enabled in the Repo
    Get-ChildItem -Path (
        Join-Path -Path $fullRootPath -ChildPath '\trigger'
    ) -Recurse |
    Select-String '"runtimeState": "Started"' |
    Get-Item
).Basename

$triggersEnabledInRepo | ForEach-Object { # Start all triggers enabled in the Repo
    try{
        Write-Host "Starting" $_
        Start-AzDataFactoryV2Trigger `
        -ResourceGroupName "$ResourceGroupName" `
        -DataFactoryName "$DataFactoryName" `
        -TriggerName $_ `
        -Force | out-null
    }
    catch{
        Write-Host "Faile to start" $_
    }
}