Azure Function - 以编程方式检查其完成

Azure Function - Programmatically checking its done

我有一个 Azure 函数,我想检查它是否已完成 运行ning。

目前,我正在做的是进入门户中的应用程序,然后单击“监视器”并观察 date/time,直到它基本上停止显示新行。基本上,如果 10 分钟后没有条目,我就知道它完成了。

这不是很理想,所以无论如何我可以在 JavaScript 中进行此检查吗?

或者在 Portal 中有更简单的方法?我已经看到可以在 Application Insights 的日志(分析)中进行 运行 查询?有什么可以解决这个问题的吗?

任何 ideas/help 将不胜感激。

谢谢。

这是一个示例请求,它 return 与 JSON -

相同
curl 'https://management.azure.com//subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/microsoft.insights/components/<FUNC_APP_NAME>/api/query?api-version=2015-05-01' \
    -H 'Authorization: Bearer eyJ0....' \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    --data-binary $'{\n  "query": "requests | where timestamp >= ago(30d) | where cloud_RoleName =~ \'<FUNC_APP_NAME>\' and operation_Name == \'<FUNC_NAME>\' | summarize count=count() by success"\n}'

要获得更详细的视图,请使用 -

"query": "requests |
    project timestamp, id, operation_Name, success, resultCode, duration, operation_Id, cloud_RoleName, invocationId=customDimensions['InvocationId'] |
    where timestamp > ago(30d) |
    where cloud_RoleName =~ '<FUNC_APP_NAME>' and operation_Name == '<FUNC_NAME>' |
    order by timestamp desc |
    take 20"

来源: 在 Azure 门户中刷新屏幕截图中的边栏选项卡时,F12 开发人员工具 > 网络选项卡。

为了更优雅,我建议您查询 Application Insights API 以获得此数据,而不是 ARM API。

遥测可能最多延迟 5 分钟,通常要少得多,但请考虑到这一点。还要注意 400 Bad Request 被视为成功,全绿色,因为从技术上讲这是正确的,你的函数 运行 很好,它只是输入错误 -