Search code examples
azure-webjobsazure-webjobssdk

BlobTrigger triggering job multiple times in Azure WebJobs 0.3 Beta


After upgrading to WebJobs 0.3 beta, Azure WebJobs is calling my method (with BlobTrigger as input) multiple times when a blob is posted to storage. This happens both when testing locally at the Console, and in Azure. In my case, I am taking the BlobTrigger, and then posting to a queue, like so:

        public static void ProcessFactoryFileSubmission(
        [BlobTrigger(blobs.RESPONSE + "/{requestId}_{factoryId}_{filename}")] ICloudBlob blob,
        [Table(tables.PACKAGE)] CloudTable table,
        [Queue(queues.FACTORY_RESPONSE)] out FactoryPackageResponseMessage responseQueue)

The queue is getting two messages, and in the webjobs azure dashboard it does show the function being invoked twice.

Why is this?


Solution

  • pianomanjh, this is a known limitation. There are a few combinations of triggers and outputs that don't play well. Let me explain how this works internally and why this case doesn't work:

    Case 1: BlobTrigger (input) + Blob (output): it is easy to know if the input blob was processed by looking for the output blob, which must exist and be newer.

    Case 2: QueueTrigger (input) + any output: it is easy to know if the input was processed because the queue message is deleted after it gets processed.

    Case 3: BlobTrigger (input) + Queue (output): it is not very easy to know if the input blob was processed because the message in the queue might or might not exist. Also, we are not storing any metadata on the blob to know if it was processed by a particular function.

    You are hitting case 3. A workaround to this is to move the blob in a different container/directory once it gets processed so it doesn't get picked again.