You can calculate the total execution time for an orchestration by calling the statusQueryGetUri returned when the durable function is first created. The call URI should look like this:
http://<functionappname>.azurewebsites.net/runtime/webhooks/durabletask/instances/<instanceId>?taskHub=<taskHub>&connection=<connectionName>&code=<systemKey>&showHistory=true
The response should look like this:
{
"createdTime": "2018-02-28T05:18:49Z",
"historyEvents": [
...
],
"input": null,
"customStatus": { "nextActions": ["A", "B", "C"], "foo": 2 },
"lastUpdatedTime": "2018-02-28T05:18:54Z",
"output": [
...
],
"runtimeStatus": "Completed"
}
The duration can be determined by polling the status URI until the runtimeStatus reaches any of the terminal states (Failed, Cancelled, Terminated, or Completed), and then subtracting createdTime from lastUpdatedTime.
The following Typescript snippet shows how a the above JSON response (parsed into the status variable) could be processed to show duration as hh:mm:ss:
formatDuration(status: DurableFunctionJob): string {
const diff:number = (new Date(status.lastUpdatedTime).getTime()
- new Date(status.createdTime).getTime());
return new Date(diff).toISOString().substr(11,8);
}
For the example response, this function outputs 00:00:05.