I'm used to use webjob on Azure triggering an Azure queue. It works like a charm.
static void Main(string[] args)
{
JobHost host = new JobHost();
host.RunAndBlock();
}
public static void ProcessQueueMessage([QueueTrigger("logqueue")] string logMessage, TextWriter logger)
{
logger.WriteLine(logMessage);
}
What's really good with queueTrigger is until the process triggered by a message isnot done, the message is keep invisible (not delete). So If you turn off the webjob (for webjob update for example) The message will be visible (after a little timeout) in the queue to be process by the updated webjob (perfect).
Now I wanna do the same thing but on a worker role. Today I do like this.
while (true)
{
var cloudMessage = await sourceImportationQueue.GetMessageAsync();
if (cloudMessage != null)
sourceImportationQueue.DeleteMessage(cloudMessage);
// process my job (few hours)
else
await Task.Delay(1000 * 5);
}
But if I stop the worker during is job, I lost the message. So how can I do like webJob triggering ?
Finally I find a simple solution. Before running my job of several hours, I launch a task
KeepHiddenMessageAsync
that update the message with the timeout. Before the end of the timeout a new update of the message is done. If an problem occur then the timeout of the message will be reached and the message will become visible.