0

We have an end point that uses azure functions to get the results. Sometimes we get the results almost instantly and sometimes we get the results after 10 s or 20 s.

I m wondering if there is a better way to test those endpoints using postman or do you use a different tool for testing the end points that relies on the durable functions.This solution works ok but is not reliable always.

statusCode = responseCode.code;
var result = JSON.parse(responseBody);

var maxNumberOfTries = 24;
var sleepBetweenTries = 5000;

if (!pm.environment.get("collection_tries")) {
    pm.environment.set("collection_tries", 1);
}

console.log(result);
tests["Status code is 200"] = statusCode == environment["status_OK"];

if (result.abc.length == 0) {
    if (pm.environment.get("collection_tries") <= maxNumberOfTries && statusCode == 200) {
        var tries = parseInt(pm.environment.get("collection_tries"), 10);
        pm.environment.set("collection_tries", tries + 1);
        setTimeout(function () { }, sleepBetweenTries);
        postman.setNextRequest(pm.info.requestId);
    }
    else {
        pm.environment.unset("collection_tries");
        console.log("Exceeded all attempts to check ABC");
        tests["ABC exist"] = false;
    }
} else {
    pm.environment.unset("collection_tries");
    tests["ABC exist"] = true;
    
    var abcid = result._id;
Doris Lv
  • 3,083
  • 1
  • 5
  • 14
Cerena
  • 43
  • 7

1 Answers1

0

When you start an orchestration in your http triggered function the built-in durable functions http response has the following output:

HTTP/1.1 202 Accepted
Connection: close
Date: Wed, 26 Aug 2020 07:43:55 GMT
Content-Type: application/json; charset=utf-8
Server: Kestrel
Content-Length: 958
Location: http://localhost:7071/runtime/webhooks/durabletask/instances/a30d3b1b203e4135b302204b99c989b3?taskHub=DurableDemo&connection=Storage&code=4X/ekkGia/Ng07GHcwLz9CKLClggXjdKKZQ0hQC6pifxteBWvA19jg==
Retry-After: 10

{
  "id": "a30d3b1b203e4135b302204b99c989b3",
  "statusQueryGetUri": "http://localhost:7071/runtime/webhooks/durabletask/instances/a30d3b1b203e4135b302204b99c989b3?taskHub=DurableDemo&connection=Storage&code=4X/ekkGia/Ng07GHcwLz9CKLClggXjdKKZQ0hQC6pifxteBWvA19jg==",
  "sendEventPostUri": "http://localhost:7071/runtime/webhooks/durabletask/instances/a30d3b1b203e4135b302204b99c989b3/raiseEvent/{eventName}?taskHub=DurableDemo&connection=Storage&code=4X/ekkGia/Ng07GHcwLz9CKLClggXjdKKZQ0hQC6pifxteBWvA19jg==",
  "terminatePostUri": "http://localhost:7071/runtime/webhooks/durabletask/instances/a30d3b1b203e4135b302204b99c989b3/terminate?reason={text}&taskHub=DurableDemo&connection=Storage&code=4X/ekkGia/Ng07GHcwLz9CKLClggXjdKKZQ0hQC6pifxteBWvA19jg==",
  "purgeHistoryDeleteUri": "http://localhost:7071/runtime/webhooks/durabletask/instances/a30d3b1b203e4135b302204b99c989b3?taskHub=DurableDemo&connection=Storage&code=4X/ekkGia/Ng07GHcwLz9CKLClggXjdKKZQ0hQC6pifxteBWvA19jg=="
}

You then poll the endpoint mentioned in the Location header (or the value of the statusQueryGetUri property) and apply a wait time which is mentioned in the Retry-After header. Once you get a 200 response with the actual result you check the runtimeStatus property if that is marked as Completed (or Failed etc).

This solution is not much different than what you have already. But you're using a bit more built-in functionality from DF.

More info about the DF HTTP API: https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-http-api

Marc
  • 1,798
  • 8
  • 15