azure.datafactory.tools icon indicating copy to clipboard operation
azure.datafactory.tools copied to clipboard

Adds TryCatch to StopTrigger, continuing if fails

Open henriquebrisola opened this issue 1 year ago • 4 comments

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

henriquebrisola avatar Jul 24 '24 14:07 henriquebrisola

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.

NowinskiK avatar Jul 24 '24 22:07 NowinskiK

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.

henriquebrisola avatar Jul 24 '24 23:07 henriquebrisola

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

NowinskiK avatar Jul 26 '24 08:07 NowinskiK

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" $_
    }
}

henriquebrisola avatar Jul 26 '24 14:07 henriquebrisola