0

I have function app pointing to azure storage using BlobTrigger.

[FunctionName("ProcessFiles")]
public async Task Run([BlobTrigger("container-path/{name}", Connection = "myconnection")] Stream myBlob, string name, ILogger log)
{
    //Processing Logic here
}

I also have set up LifeCycle management policy, where in files residing for > 3 months in Container will be auto deleted.

{
  "rules": [
    {
      "enabled": false,
      "name": "Delete 1 day or older",
      "type": "Lifecycle",
      "definition": {
        "actions": {
          "baseBlob": {
            "delete": {
              "daysAfterModificationGreaterThan": 1
            }
          }
        },
        "filters": {
          "blobTypes": [
            "blockBlob"
          ]
        }
      }
    }
  ]
}

Now the issue is after every 1 day, when the file is being deleted, the BlobTrigger is being fired again and as a result the file is being processed again.

If I disable the LifeCycleManagement Policy, the issue does not occur. However, what I need is to process the function app logic only when a new file is being 'added' and not when 'deleted'.

The solution is already in production and can't change the BlobStorage Trigger as such so am hoping to use some property internally to detect if this is an add action and proceed accordingly.

Any workaround ideas please?

Skin
  • 9,085
  • 2
  • 13
  • 29
user2948533
  • 1,143
  • 3
  • 13
  • 32
  • My only suggestion would be to check if the blob exists when the trigger fires. If it doesn't it must've been deleted. There is a better option in LogicApps but if you can't change the trigger mechanism then it is what it is. – Skin Apr 19 '23 at 01:18

1 Answers1

0

Based on what the OP has said, it is assumed that the trigger cannot be changed but for anyone reading this in future, my suggestion would be to look at using the LogicApp trigger as shown below.

From there, a HTTP triggered Azure Function could be invoked OR you could simply continue on using the LogicApp.

LogicApp Trigger

Skin
  • 9,085
  • 2
  • 13
  • 29