Skip to content

Instantly share code, notes, and snippets.

@andrew-grischenko
Last active October 28, 2022 16:04
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 andrew-grischenko/a2d42fd707632c0928e72047fb7741fd to your computer and use it in GitHub Desktop.
Save andrew-grischenko/a2d42fd707632c0928e72047fb7741fd to your computer and use it in GitHub Desktop.
...
let responseMessage: string = '';
const statusOptions = [ 'All', 'Running', 'Failed', 'Cancelled', 'Succeeded' ];
const NO_FILTER = 0;
var runsList = {
runs: []
};
let runsCount = 0;
let nextLink: string = `https://management.azure.com/providers/Microsoft.ProcessSimple/scopes/admin/environments/${environment}/flows/${flow}/runs?api-version=2016-11-01`;
if(statusOption != statusOptions[NO_FILTER])
nextLink += `&$filter=Status%20eq%20%27${statusOption.toLowerCase()}%27`;
try {
while(nextLink && runsCount <= RUNS_LIMIT) {
await getHttp(nextLink,
req.headers['authorization'])
.then(runs => {
if(!runs || !runs.value)
throw Error('No runs found - the response is unexpected');
const items = (periodOption != periodOptions[NO_FILTER]) ?
runs.value.filter( (item) => new Date(item.properties.startTime) >= dateFrom && new Date(item.properties.startTime) <= dateTo) :
runs.value;
items.forEach(element => {
runsList.runs.push(
{
'id': element.id,
'name': element.name,
'type': element.type,
'properties': element.properties
}
)
});
runsCount += items.length;
nextLink = runs.nextLink;
});
}
responseMessage = JSON.stringify(runsList);
context.log(`Total runs found: ${runsList.runs.length}`);
}
catch ( err ) {
responseMessage = `Error: ${err}`;
}
...
@amirmsai
Copy link

Hi Andrew,
what type of scope do you used ?

@RickKush
Copy link

How could I get the latest single run from the run history?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment