Skip to content

Instantly share code, notes, and snippets.

@DaveRuijter
Created December 12, 2021 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaveRuijter/81c5a3fc1727c05f8072d553ba13701f to your computer and use it in GitHub Desktop.
Save DaveRuijter/81c5a3fc1727c05f8072d553ba13701f to your computer and use it in GitHub Desktop.
ADF/ASA pipeline to verify if a pipeline is running / in progress
{
"name": "00_is_pipeline_running",
"properties": {
"activities": [
{
"name": "Get Pipeline Runs",
"type": "WebActivity",
"dependsOn": [
{
"activity": "getSubscriptionID",
"dependencyConditions": [
"Succeeded"
]
},
{
"activity": "getAdfResourceGroupName",
"dependencyConditions": [
"Succeeded"
]
}
],
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"url": {
"value": "https://management.azure.com/subscriptions/@{activity('getSubscriptionID').output.value}/resourceGroups/@{activity('getAdfResourceGroupName').output.value}/providers/Microsoft.DataFactory/factories/@{pipeline().DataFactory}/queryPipelineRuns?api-version=2018-06-01",
"type": "Expression"
},
"method": "POST",
"body": {
"value": "{\n \"lastUpdatedAfter\": \"@{adddays(utcnow(),int(pipeline().parameters.QueryRunDays))}\",\n \"lastUpdatedBefore\": \"@{utcnow()}\",\n \"filters\": [\n {\n \"operand\": \"PipelineName\",\n \"operator\": \"Equals\",\n \"values\": [\n \"@{pipeline().parameters.PipelineName}\"\n ]\n },\n { \n \"operand\": \"Status\", \n \"operator\": \"In\", \n \"values\": [ \n \"InProgress\", \n \"Queued\"\n ] \n }\n ]\n}",
"type": "Expression"
},
"authentication": {
"type": "MSI",
"resource": "https://management.core.windows.net/"
}
}
},
{
"name": "Filter Running Pipelines",
"type": "Filter",
"dependsOn": [
{
"activity": "Get Pipeline Runs",
"dependencyConditions": [
"Succeeded"
]
}
],
"userProperties": [],
"typeProperties": {
"items": {
"value": "@activity('Get Pipeline Runs').output.value",
"type": "Expression"
},
"condition": {
"value": "@and(not(equals(item().runId,pipeline().parameters.ThisRunId)),or(equals(item().status,'InProgress'),equals(item().status,'Queued')))",
"type": "Expression"
}
}
},
{
"name": "If Pipeline Is Running",
"type": "IfCondition",
"dependsOn": [
{
"activity": "Filter Running Pipelines",
"dependencyConditions": [
"Succeeded"
]
}
],
"userProperties": [],
"typeProperties": {
"expression": {
"value": "@greaterOrEquals(int(activity('Filter Running Pipelines').output.FilteredItemsCount),1)",
"type": "Expression"
},
"ifTrueActivities": [
{
"name": "Raise Error",
"type": "Lookup",
"dependsOn": [],
"policy": {
"timeout": "7.00:00:00",
"retry": null,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "AzureSqlSource",
"sqlReaderQuery": {
"value": "RAISERROR('@{concat('Provided pipeline name (',pipeline().parameters.PipelineName,') still has a run in progress or queued given the query range parameters set in the properties table.')}',16,1);",
"type": "Expression"
},
"queryTimeout": "02:00:00",
"partitionOption": "None"
},
"dataset": {
"referenceName": "metadata",
"type": "DatasetReference",
"parameters": {
"table": "dummy",
"schema": "dummy"
}
},
"firstRowOnly": false
}
}
]
}
},
{
"name": "getSubscriptionID",
"type": "WebActivity",
"dependsOn": [],
"policy": {
"timeout": "7.00:00:00",
"retry": 3,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"url": {
"value": "@concat(pipeline().globalParameters.keyVaultUrl,'secrets/SubscriptionID?api-version=7.0')",
"type": "Expression"
},
"method": "GET",
"authentication": {
"type": "MSI",
"resource": "https://vault.azure.net"
}
}
},
{
"name": "getAdfResourceGroupName",
"type": "WebActivity",
"dependsOn": [],
"policy": {
"timeout": "7.00:00:00",
"retry": 3,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"url": {
"value": "@concat(pipeline().globalParameters.keyVaultUrl,'secrets/adfResourceGroupName?api-version=7.0')",
"type": "Expression"
},
"method": "GET",
"authentication": {
"type": "MSI",
"resource": "https://vault.azure.net"
}
}
}
],
"parameters": {
"PipelineName": {
"type": "string"
},
"ThisRunId": {
"type": "string"
},
"QueryRunDays": {
"type": "string",
"defaultValue": "-1"
}
},
"variables": {
"SubscriptionId": {
"type": "String"
},
"RunCount": {
"type": "String"
}
},
"folder": {
"name": "_platform"
},
"annotations": []
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment