Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MatthewDavidCampbell/79bbc6f183db356aabee514dc465d076 to your computer and use it in GitHub Desktop.
Save MatthewDavidCampbell/79bbc6f183db356aabee514dc465d076 to your computer and use it in GitHub Desktop.
Copying Search document with array fields
{
"name": "Batch",
"properties": {
"activities": [
{
"name": "Find",
"type": "Until",
"dependsOn": [],
"userProperties": [],
"typeProperties": {
"expression": {
"value": "@equals(variables('IsCompleted'), bool('true'))",
"type": "Expression"
},
"activities": [
{
"name": "Set Remaining",
"type": "SetVariable",
"dependsOn": [],
"userProperties": [],
"typeProperties": {
"variableName": "Remaining",
"value": {
"value": "@string(sub(pipeline().parameters.Max, int(variables('Used'))))",
"type": "Expression"
}
}
},
{
"name": "Set Take",
"type": "SetVariable",
"dependsOn": [
{
"activity": "Set Remaining",
"dependencyConditions": [
"Completed"
]
}
],
"userProperties": [],
"typeProperties": {
"variableName": "Take",
"value": {
"value": "@if(less(int(variables('Remaining')), pipeline().parameters.Take), variables('Remaining'), string(pipeline().parameters.Take))",
"type": "Expression"
}
}
},
{
"name": "Get Documents",
"type": "WebActivity",
"dependsOn": [
{
"activity": "Set Skip",
"dependencyConditions": [
"Completed"
]
}
],
"policy": {
"timeout": "0.12:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"url": {
"value": "@concat(pipeline().parameters.FromSearchUrl,'&$skip=',variables('Skip'),'&$top=',variables('Take'),'&$orderby=Skapad desc')",
"type": "Expression"
},
"method": "GET",
"headers": {
"api-key": {
"value": "@pipeline().parameters.FromSearchApiKey",
"type": "Expression"
}
}
}
},
{
"name": "Set Skip",
"type": "SetVariable",
"dependsOn": [
{
"activity": "Set Take",
"dependencyConditions": [
"Completed"
]
}
],
"userProperties": [],
"typeProperties": {
"variableName": "Skip",
"value": {
"value": "@string(add(pipeline().parameters.Skip, int(variables('Used'))))",
"type": "Expression"
}
}
},
{
"name": "Circuit Breaker",
"type": "IfCondition",
"dependsOn": [
{
"activity": "Get Documents",
"dependencyConditions": [
"Completed"
]
}
],
"userProperties": [],
"typeProperties": {
"expression": {
"value": "@greater(length(activity('Get Documents').output.value), 0)",
"type": "Expression"
},
"ifFalseActivities": [
{
"name": "Nothing Left",
"type": "SetVariable",
"dependsOn": [],
"userProperties": [],
"typeProperties": {
"variableName": "IsCompleted",
"value": {
"value": "@bool('true')",
"type": "Expression"
}
}
}
],
"ifTrueActivities": [
{
"name": "Set Trainsient Used",
"type": "SetVariable",
"dependsOn": [
{
"activity": "Use Documents",
"dependencyConditions": [
"Completed"
]
}
],
"userProperties": [],
"typeProperties": {
"variableName": "TransientUsed",
"value": {
"value": "@string(add(length(activity('Get Documents').output.value), int(variables('Used'))))",
"type": "Expression"
}
}
},
{
"name": "Set Used",
"type": "SetVariable",
"dependsOn": [
{
"activity": "Set Trainsient Used",
"dependencyConditions": [
"Completed"
]
}
],
"userProperties": [],
"typeProperties": {
"variableName": "Used",
"value": {
"value": "@variables('TransientUsed')",
"type": "Expression"
}
}
},
{
"name": "Use Documents",
"type": "WebActivity",
"dependsOn": [],
"policy": {
"timeout": "0.12:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"url": {
"value": "@pipeline().parameters.ToSearchUrl",
"type": "Expression"
},
"method": "POST",
"headers": {
"api-key": {
"value": "@pipeline().parameters.ToSearchApiKey",
"type": "Expression"
},
"Content-Type": "application/json"
},
"body": {
"value": "@concat( '{ \"value\":', activity('Get Documents').output.value, '}' )",
"type": "Expression"
}
}
},
{
"name": "Maybe IsCompleted",
"type": "SetVariable",
"dependsOn": [
{
"activity": "Set Used",
"dependencyConditions": [
"Completed"
]
}
],
"userProperties": [],
"typeProperties": {
"variableName": "IsCompleted",
"value": {
"value": "@greaterOrEquals(int(variables('Used')), pipeline().parameters.Max)",
"type": "Expression"
}
}
},
{
"name": "Failure Use",
"type": "SetVariable",
"dependsOn": [
{
"activity": "Use Documents",
"dependencyConditions": [
"Failed"
]
}
],
"userProperties": [],
"typeProperties": {
"variableName": "IsCompleted",
"value": {
"value": "@bool('true')",
"type": "Expression"
}
}
}
]
}
},
{
"name": "Failure Get",
"type": "SetVariable",
"dependsOn": [
{
"activity": "Get Documents",
"dependencyConditions": [
"Failed"
]
}
],
"userProperties": [],
"typeProperties": {
"variableName": "IsCompleted",
"value": {
"value": "@bool('true')",
"type": "Expression"
}
}
}
],
"timeout": "0.12:00:00"
}
}
],
"concurrency": 1,
"parameters": {
"Take": {
"type": "int",
"defaultValue": 100
},
"Max": {
"type": "int",
"defaultValue": 1000
},
"Skip": {
"type": "int",
"defaultValue": 0
},
"FromSearchUrl": {
"type": "string"
},
"ToSearchUrl": {
"type": "string"
},
"FromSearchApiKey": {
"type": "string"
},
"ToSearchApiKey": {
"type": "string"
}
},
"variables": {
"IsCompleted": {
"type": "Boolean",
"defaultValue": false
},
"Used": {
"type": "String",
"defaultValue": "0"
},
"TransientUsed": {
"type": "String",
"defaultValue": "0"
},
"Take": {
"type": "String",
"defaultValue": "0"
},
"Remaining": {
"type": "String",
"defaultValue": "0"
},
"Skip": {
"type": "String",
"defaultValue": "0"
},
"Documents": {
"type": "String",
"defaultValue": "{ \"value\": [] }"
}
},
"annotations": []
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment