Azure 函数未触发 - Blob 存储触发器

时间:2021-04-26 18:23:36

标签: azure azure-functions azure-functions-runtime azure-blob-trigger

我有一个简单的 Azure 函数,当在 Blob 存储中添加新项目时会触发该函数。

该函数读取上传到 Blob 存储的新 JSON 文件并将信息加载到数据库中。

它在本地工作,当我部署该功能时,它也按预期工作,但几天后我检查数据时发现该功能没有触发。但是,功能应用程序显示“正在运行”状态。我重新启动了应用程序,它再次开始上传数据,只是在几个小时后停止了。

它似乎只有在我重新启动应用程序或在浏览器中打开 Azure Functions 时才有效。

一些额外的数据:

我正在添加一些我认为可能相关的信息,但我是 Azure Functions 的新手,因此如果我忽略了任何更重要的信息,请随时提出要求。我也有 Application Insights 监控应用。

运行时版本:3.0.15571.0

模式:消费

1.应用洞察检查

我检查了过去 3 天内的请求。它的工作时间与我昨天试图找出问题所在的时间相同。有很多请求,因为它正在赶上所有未处理的旧文件: enter image description here

最后一个请求是昨天,因为我们可以检查查询: enter image description here

2. kudu 检查

我正在查看的日志是我编码到函数中的预期日志、一些我不知道其含义的意外日志以及我的 SQL 连接中的一些错误:

显示的信息如下:

2021-04-26T17:50:23.377 [Information] Executing 'FunctionSaveOnBDD' (Reason='New blob detected: containerforiotcentral/c618a003-9934-4b25-a674-cd709b6afb07/4/2021/03/27/11/22/vliwcspeyze7a', Id=34a100dc-135f-41ed-ba7b-209d85f28b63)
2021-04-26T17:50:23.377 [Information] Trigger Details: MessageId: 0113b888-75f7-4cb8-b9cd-562255e34c56, DequeueCount: 1, InsertionTime: 2021-04-26T17:39:03.000+00:00, BlobCreated: 2021-03-27T11:23:53.000+00:00, BlobLastModified: 2021-03-27T11:23:53.000+00:00
2021-04-26T17:50:23.378 [Information] Executing 'FunctionSaveOnBDD' (Reason='New blob detected: containerforiotcentral/c618a003-9934-4b25-a674-cd709b6afb07/4/2021/03/27/11/21/vliwcspeyze7a', Id=5e7ee513-346d-45d4-a8a4-b2f981ed470a)
2021-04-26T17:50:23.378 [Information] Trigger Details: MessageId: 7525894a-ba7c-47b9-802a-54faa60a603a, DequeueCount: 1, InsertionTime: 2021-04-26T17:39:03.000+00:00, BlobCreated: 2021-03-27T11:22:53.000+00:00, BlobLastModified: 2021-03-27T11:22:53.000+00:00
2021-04-26T17:50:23.378 [Information] Executing 'FunctionSaveOnBDD' (Reason='New blob detected: containerforiotcentral/c618a003-9934-4b25-a674-cd709b6afb07/4/2021/03/27/11/23/vliwcspeyze7a', Id=e3d0ca32-2d07-4b18-8bb9-4edda7de68b5)
2021-04-26T17:50:23.378 [Information] Trigger Details: MessageId: b8bbd557-9710-4cea-81f7-7a243aa96111, DequeueCount: 1, InsertionTime: 2021-04-26T17:39:03.000+00:00, BlobCreated: 2021-03-27T11:24:53.000+00:00, BlobLastModified: 2021-03-27T11:24:53.000+00:00
2021-04-26T17:50:23.379 [Information] Executed 'FunctionSaveOnBDD' (Succeeded, Id=704c2ace-9688-40da-8aa7-a19190ece7c1, Duration=702ms)
2021-04-26T17:50:23.399 [Information] C# Blob trigger function Processed blob
 Name:c618a003-9934-4b25-a674-cd709b6afb07/4/2021/03/27/11/04/vliwcspeyze7a 
 Content: telemetry

其中最后一行是函数执行写入的日志。 我的 SQL 连接也出现了一些错误,这些错误在我测试时没有发生:

2021-04-26T17:50:23.270 [Information] Microsoft.Data.SqlClient.SqlException (0x80131904): Transaction (Process ID 66) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
   at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at Microsoft.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean isAsync, Int32 timeout, Boolean asyncWrite)
   at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String methodName)
   at Microsoft.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at AzureFunctionBlobTrigger0103DEF.BlobTriggersaveonBDD.Run(Stream myBlob, String name, ILogger log) in C:\Users\Tere\source\repos\AzureFunctionBlobTrigger0103DEF\BlobTriggersaveonBDD.cs:line 52
ClientConnectionId:f46c83df-9566-4af9-866e-12728d39b646
Error Number:1205,State:18,Class:13
ClientConnectionId before routing:3f74ce3e-43a1-4c9c-8ddb-8e9c9d8610a9
Routing Destination:af4408adfd33.tr16.westeurope1-a.worker.database.windows.net,11040

1 个答案:

答案 0 :(得分:0)

<块引用>

它似乎只有在我重新启动应用程序或打开时才有效 浏览器中的 Azure Functions。

这种情况不应该发生。您如何确定这一点?

请使用以下两种方式检查:

1、使用应用洞察:

转到您的 Application Insights,然后运行:

requests

并且请不要忘记设置时间范围:

enter image description here

2、使用kudu:

直接转到https://yourfunctionappname.scm.azurewebsites.net/DebugConsole,然后点击\home\LogFiles\Application\Functions\Function\yourtriggername

请检查日志,也许你能找到一些东西。