我们有一个使用Azure函数获取结果的终点。有时我们几乎立即获得结果,有时我们在10或20 s之后获得结果。
我想知道是否有更好的方法可以使用邮递员来测试这些端点,或者您是否使用另一种工具来测试依赖于持久功能的端点。此解决方案行之有效,但始终不可靠。
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;
答案 0 :(得分:0)
当您在http触发的函数中开始编排时,内置的持久函数http响应具有以下输出:
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=="
}
然后,您轮询 Location 标头中提到的端点(或 statusQueryGetUri 属性的值),并应用重试中提到的等待时间-后标题。获得实际结果200响应后,请检查 runtimeStatus 属性(如果该属性标记为 Completed (或 Failed 等))。 >
此解决方案与您现有的解决方案没有太大不同。但是您正在使用DF的更多内置功能。</ p>
有关DF HTTP API的更多信息:https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-http-api