6

I have the following logic in a WebJob using the new 0.3.0-beta WebJobs SDK. When my code fails processing the message, the Azure dashboard shows an Aggregate Exception (which makes sense since this is async). HOWEVER, it does not retry processing the message.

The very little documentation I've been able to find indicates that the message should be retried within 10 minutes of failure. Is this not the case with the new SDK?

public static Task ProcessMyMessageAsync(
    [QueueTrigger(Config.MY_QUEUE)] string msg, 
    int dequeueCount, 
    CancellationToken cancellationToken)
{
    var processor = Config.Container.GetInstance<IMessageProcessor>();
    return processor.HandleJobAsync(msg, dequeueCount, cancellationToken);
}

The exception I get stems from a SQL Timeout exception (its a db query against SQL Azure in my code):

System.AggregateException: System.AggregateException: One or more errors occurred. 
    ---> System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing  the command definition. See the inner exception for details. 
        ---> System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. 
        ---> System.ComponentModel.Win32Exception: The wait operation timed out
ericb
  • 3,400
  • 1
  • 21
  • 21
  • Does the failure occur during the binding phase or inside your function? Can you give more details about what exception you get? – Victor Hurdugaci Jun 27 '14 at 15:45
  • @VictorHurdugaci The exception doesn't appear to be related to the JobHost or anything like that. It is definitely within my code and since it's a SQL Timeout, I want the message to be retried. – ericb Jun 27 '14 at 16:38

1 Answers1

1

You should set MaxDequeueCount.

JobHostConfiguration jobHostConf = new JobHostConfiguration();
jobHostConf.Queues.MaxDequeueCount = 10;
var host = new JobHost(jobHostConf);
host.RunAndBlock();

That will retry 10 times, before the messages is put on a dead/bad letter queue.

You could also use a custom retry policy in the function. I suggest you look at "The Transient Fault Handling Application Block" https://msdn.microsoft.com/en-us/library/hh680934(v=pandp.50).aspx

Or you could enable retry in EF with a SqlAzureExecutionStrategy https://msdn.microsoft.com/en-us/data/dn456835.aspx

henrikwh
  • 61
  • 5