Example #1
0
        public static async Task ProcessMailAsync([QueueTrigger(QueueStore.NEW_MAIL)] CloudQueueMessage message, [Queue(QueueStore.NEW_MAIL)] CloudQueue nextQueue)
        {
            Console.WriteLine($"Started {QueueStore.NEW_MAIL}: {DateTime.UtcNow.ToLocalString()}");
            var msg = message.GetBaseQueueMessage();

            try
            {
                await _emailProvider.SendEmailAsync(msg.DeserializeData <MailQueueMessage>());
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception {QueueStore.NEW_MAIL}: {DateTime.UtcNow.ToLocalString()}, Retry {msg.RetryNext}: {e.Message}");
                if (!msg.RetryNext)
                {
                    // if a message is catched here then we inform the admin.
                    await _exceptionHandler.ProcessExceptionAsync(QueueStore.NEW_MAIL, e);

                    throw;
                }

                await nextQueue.AddMessageAsync(
                    CloudQueueMessage.CreateCloudQueueMessageFromByteArray(
                        msg.NextMessage.AsBytes()
                        ),
                    null,
                    TimeSpan.FromSeconds(msg.NextMessage.TriggerDelay),
                    new QueueRequestOptions(),
                    new OperationContext()
                    );
            }
            finally
            {
                Console.WriteLine($"Finished {QueueStore.NEW_MAIL}: {DateTime.UtcNow.ToLocalString()}");
            }
        }
Example #2
0
        public static void TriggerKeepAlive([QueueTrigger(QueueStore.KEEP_ALIVE)] CloudQueueMessage message)
        {
            try
            {
                var msg     = message.GetBaseQueueMessage();
                var content = msg.DeserializeData <DateTime>();
                var text    = $"Triggered WebJob keep-alive: {content.ToLocalString()}";

                Console.WriteLine(text);
            }
            catch
            {
                //ignore, the goal is only to keep the triggered job alive;
            }
        }
 public static async Task ProcessExceptionAsync([QueueTrigger(QueueStore.PROCESS_EXCEPTION)] CloudQueueMessage message)
 {
     Console.WriteLine($"Started {QueueStore.PROCESS_EXCEPTION}: {DateTime.UtcNow.ToLocalString()}");
     try
     {
         var msg       = message.GetBaseQueueMessage();
         var exception = msg.DeserializeData <ExceptionQueueMessage <Exception> >();
         await _exceptionHandler.NotifyExceptionAsync(exception.Exception, exception.Message, exception.Source, exception.Data);
     }
     catch (Exception e)
     {
         Console.WriteLine($"Exception {QueueStore.PROCESS_EXCEPTION}: {DateTime.UtcNow.ToLocalString()}, {e.Message}");
         throw;
     }
     finally
     {
         Console.WriteLine($"Finished {QueueStore.PROCESS_EXCEPTION}: {DateTime.UtcNow.ToLocalString()}");
     }
 }