BlobTrigger triggering job multiple times in Azure

2019-07-30 16:14发布

问题:

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?

回答1:

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.



回答2:

This issues is fixed as of 0.5.0-beta. BlobTriggers are only fired when a new blob is detected or an existing blob is updated. For more information please see this post http://azure.microsoft.com/blog/2014/09/06/announcing-the-0-5-0-beta-preview-of-microsoft-azure-webjobs-sdk/