Microsoft AZURE blob 触发功能间歇性工作
Microsoft AZURE blob triggered function working intermittently
我们 运行 遇到了 Blob 触发函数的问题。
函数写在javascript中。
我们很难为它建立一个自动化的部署过程。
以下是我们遵循的步骤。
使用 ARM 模板和参数文件在现有资源组中创建函数应用
New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile $templateFilePath -TemplateParameterFile $armParametersFilePath;
通过Kudu
api部署功能代码
Invoke-RestMethod -Uri "$apiUrl" -Method Put -InFile "$functionCodeArchivePath" -Credential $credentials -DisableKeepAlive -UserAgent "powershell/1.0" -TimeoutSec 600
运行 npm install
命令通过kudu api
Invoke-RestMethod -Uri "$apiCommandUrl" -Method Post -Body $json -DisableKeepAlive -ContentType "application/json" -Credential $credentials -UserAgent "powershell/1.0" -TimeoutSec 1200
在最后一步 - 在 Kudu 上获取依赖项 (npm install
) 的命令超时,这似乎是 known issue。
为了克服这个问题,我们在 this approach.
之后使用 WebPack 将所有依赖项打包到一个 JavaScript 文件中
现在部署速度更快了,虽然功能似乎没有正确执行。
当我们将文件放入我们的 blob 存储帐户时,该函数是从 触发的,该函数似乎并不总是记录执行跟踪。
有些运行有完整的日志,有些运行只有 Function started
而没有任何自定义日志语句。
这是日志,直接来自 Kudu (D:\home\LogFiles\Application\Functions\Function\functionname>)
2017-03-03T11:24:33.835 Function started (Id=77b5b022-eee0-45e0-8e14-15e89de59835)
2017-03-03T11:24:35.167 JavaScript blob trigger function started with blob:
2017-03-03T11:24:35.167 Name: _1486988111937
Blob Size: 8926 Bytes
2017-03-03T11:24:35.167 Extracting file
2017-03-03T11:24:35.167 JavaScript blob trigger function processed blob
Name: _1486988111937
Blob Size: 8926 Bytes
2017-03-03T11:24:35.183 Function completed (Success, Id=77b5b022-eee0-45e0-8e14-15e89de59835)
2017-03-03T11:24:35.292 { Error: [** SENSITIVE ERROR MESSAGE, INTERNAL TO FUNCTION, REMOVED **] }
2017-03-03T11:28:34.929 Function started (Id=8bd96186-50bc-43b0-916c-fefe4bd0cf51)
2017-03-03T11:38:18.302 Function started (Id=7967cc93-73cf-4acf-8428-20b0c70bbac9)
2017-03-03T11:39:32.235 Function started (Id=a0abb823-9497-429d-b477-4f7a9421132e)
2017-03-03T11:49:25.164 Function started (Id=ab16b1d9-114c-4718-aab2-ffc426cfbc98)
2017-03-03T11:53:51.172 Function started (Id=87ed29bc-122f-46d2-a658-d933330580c9)
2017-03-03T11:56:06.512 Function started (Id=23f8ee3f-cda0-45a3-8dd0-4babe9e45e4e)
2017-03-03T12:02:58.886 Function started (Id=c7ef7ad5-62b8-4b43-a043-bc394d9b02f5)
PS:我们的函数代码正在获取压缩文件 blob,将其解压缩并对压缩文件夹中的每个文件进行 API 调用。日志中标有 [** SENSITIVE ERROR MESSAGE, INTERNAL TO FUNCTION, REMOVED **]
的错误与我们 API.
的连接有关
看起来 Blob 触发并不那么可靠,至少根据这个页面:How to use Azure blob storage with the WebJobs SDK
The WebJobs SDK scans log files to watch for new or changed blobs. This process is not real-time; a function might not get triggered until several minutes or longer after the blob is created. In addition, storage logs are created on a "best efforts" basis; there is no guarantee that all events will be captured. Under some conditions, logs might be missed. If the speed and reliability limitations of blob triggers are not acceptable for your application, the recommended method is to create a queue message when you create the blob, and use the QueueTrigger attribute instead of the BlobTrigger attribute on the function that processes the blob.
您可能应该更改逻辑并为放入 Blob 存储的每个文件创建一个队列消息
我们 运行 遇到了 Blob 触发函数的问题。 函数写在javascript中。 我们很难为它建立一个自动化的部署过程。 以下是我们遵循的步骤。
使用 ARM 模板和参数文件在现有资源组中创建函数应用
New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile $templateFilePath -TemplateParameterFile $armParametersFilePath;
通过
Kudu
api部署功能代码Invoke-RestMethod -Uri "$apiUrl" -Method Put -InFile "$functionCodeArchivePath" -Credential $credentials -DisableKeepAlive -UserAgent "powershell/1.0" -TimeoutSec 600
运行
npm install
命令通过kudu apiInvoke-RestMethod -Uri "$apiCommandUrl" -Method Post -Body $json -DisableKeepAlive -ContentType "application/json" -Credential $credentials -UserAgent "powershell/1.0" -TimeoutSec 1200
在最后一步 - 在 Kudu 上获取依赖项 (npm install
) 的命令超时,这似乎是 known issue。
为了克服这个问题,我们在 this approach.
之后使用 WebPack 将所有依赖项打包到一个 JavaScript 文件中现在部署速度更快了,虽然功能似乎没有正确执行。
当我们将文件放入我们的 blob 存储帐户时,该函数是从 触发的,该函数似乎并不总是记录执行跟踪。
有些运行有完整的日志,有些运行只有 Function started
而没有任何自定义日志语句。
这是日志,直接来自 Kudu (D:\home\LogFiles\Application\Functions\Function\functionname>)
2017-03-03T11:24:33.835 Function started (Id=77b5b022-eee0-45e0-8e14-15e89de59835)
2017-03-03T11:24:35.167 JavaScript blob trigger function started with blob:
2017-03-03T11:24:35.167 Name: _1486988111937
Blob Size: 8926 Bytes
2017-03-03T11:24:35.167 Extracting file
2017-03-03T11:24:35.167 JavaScript blob trigger function processed blob
Name: _1486988111937
Blob Size: 8926 Bytes
2017-03-03T11:24:35.183 Function completed (Success, Id=77b5b022-eee0-45e0-8e14-15e89de59835)
2017-03-03T11:24:35.292 { Error: [** SENSITIVE ERROR MESSAGE, INTERNAL TO FUNCTION, REMOVED **] }
2017-03-03T11:28:34.929 Function started (Id=8bd96186-50bc-43b0-916c-fefe4bd0cf51)
2017-03-03T11:38:18.302 Function started (Id=7967cc93-73cf-4acf-8428-20b0c70bbac9)
2017-03-03T11:39:32.235 Function started (Id=a0abb823-9497-429d-b477-4f7a9421132e)
2017-03-03T11:49:25.164 Function started (Id=ab16b1d9-114c-4718-aab2-ffc426cfbc98)
2017-03-03T11:53:51.172 Function started (Id=87ed29bc-122f-46d2-a658-d933330580c9)
2017-03-03T11:56:06.512 Function started (Id=23f8ee3f-cda0-45a3-8dd0-4babe9e45e4e)
2017-03-03T12:02:58.886 Function started (Id=c7ef7ad5-62b8-4b43-a043-bc394d9b02f5)
PS:我们的函数代码正在获取压缩文件 blob,将其解压缩并对压缩文件夹中的每个文件进行 API 调用。日志中标有 [** SENSITIVE ERROR MESSAGE, INTERNAL TO FUNCTION, REMOVED **]
的错误与我们 API.
看起来 Blob 触发并不那么可靠,至少根据这个页面:How to use Azure blob storage with the WebJobs SDK
The WebJobs SDK scans log files to watch for new or changed blobs. This process is not real-time; a function might not get triggered until several minutes or longer after the blob is created. In addition, storage logs are created on a "best efforts" basis; there is no guarantee that all events will be captured. Under some conditions, logs might be missed. If the speed and reliability limitations of blob triggers are not acceptable for your application, the recommended method is to create a queue message when you create the blob, and use the QueueTrigger attribute instead of the BlobTrigger attribute on the function that processes the blob.
您可能应该更改逻辑并为放入 Blob 存储的每个文件创建一个队列消息