Azure WebJob服务总线触发器无法完成

时间:2017-05-14 23:23:19

标签: azure azure-webjobs azure-webjobssdk

我有一个Azure WebJob设置为连续运行,它使用Service Bus触发器来读取队列和主题。在处理队列时,消息会被发送到主题中,我有一个主题来管理缓存更新。

暂时,我只是从函数返回来禁用缓存更新,以便从主题中清除邮件。

public static void ProcessSearchUpdate([ServiceBusTrigger("events", "SearchClientUpdates", AccessRights.Listen)] BrokeredMessage message, System.IO.TextWriter log)
    {
        return;
    }

大多数情况下,事情按计划进行,消息只是被读取和丢弃。但是,有时,我得到以下异常,我假设是webjobs sdk试图写日志的东西。

正如您所看到的,我的方法没有做任何事情,因此不应该超时。

当它失败时,它会阻止任何触发器执行,这非常烦人。似乎SDK中的任何失败都有5分钟的超时,它可以防止任何事情运行5分钟,加上重启时间。

Microsoft.WindowsAzure.Storage.StorageException: Microsoft.WindowsAzure.Storage.StorageException: The client could not finish the operation within specified timeout. ---> System.TimeoutException: The client could not finish the operation within specified timeout.
 --- End of inner exception stack trace ---
 at Microsoft.WindowsAzure.Storage.Core.Util.StorageAsyncResult`1.End() in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Util\StorageAsyncResult.cs:line 77
 at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.EndUploadFromStream(IAsyncResult asyncResult) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlockBlob.cs:line 774
 at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.EndUploadFromByteArray(IAsyncResult asyncResult) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlockBlob.cs:line 1162
 at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.EndUploadText(IAsyncResult asyncResult) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlockBlob.cs:line 1285
 at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.<>c__DisplayClass4.<CreateCallbackVoid>b__3(IAsyncResult ar) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Util\AsyncExtensions.cs:line 114
 --- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Microsoft.Azure.WebJobs.Host.Loggers.UpdateOutputLogCommand.<UpdateOutputBlob>d__10.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Microsoft.Azure.WebJobs.Host.Loggers.UpdateOutputLogCommand.<SaveAndCloseAsync>d__6.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
 at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>d__13.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<TryExecuteAsync>d__1.MoveNext()
 Request Information
 RequestID:
 RequestDate:
 StatusMessage:

1 个答案:

答案 0 :(得分:0)

与WebJob日志系统相关的异常。 Azure WebJob SDK将定期将日志刷新到blob存储。为了解决超时问题,我们可以增加WebJob SDK用于此的CloudBlobClient的超时值。以下步骤供您参考。

步骤1.使用NuGet将Microsoft.Azure.WebJobs的版本更新为2.0.0。

enter image description here

步骤2.实现我们自己的StorageClientFactory,它可以重置blob客户端的超时值。

public class MyStorageClientFactory : Microsoft.Azure.WebJobs.Host.StorageClientFactory
{
    public override CloudBlobClient CreateCloudBlobClient(StorageClientFactoryContext context)
    {
        CloudBlobClient client = context.Account.CreateCloudBlobClient();
        client.DefaultRequestOptions.ServerTimeout = TimeSpan.FromMinutes(60);
        return client;
    }
}

步骤3.让JobHost使用自定义StorageClientFactory。

JobHostConfiguration configuration = new JobHostConfiguration();
configuration.StorageClientFactory = new MyStorageClientFactory();

var host = new JobHost(configuration);