Home > Blockchain >  Method to turn on Blob Trigger for only a short amount of time
Method to turn on Blob Trigger for only a short amount of time

Time:01-31

So, I have this Function App with a Blob Trigger, however I don't need it to be polling for new blobs all the time. I'm expecting new files to be found in a container only once a day, and I know at what time I expect those files to be found. What's the best method to approach this?

Here are the questions I have:

  • Is there a way that I can tell the Blob Trigger to enable for only about an hour a day? Or a way to turn it on- and after it processes new files and is inactive for a certain period of time to then turn it off automatically?
  • If not, how costly is the constant polling?
  • If I understand correctly, I could use an Event Grid Trigger instead, but the myblob: func.InputStream that the Blob Trigger initially passes to me when it detects a new blob is really handy because I can just hand that to pandas methods easily. If I go with Event Grid Trigger I think I'd have to go out of my way to find the name of the blob from event: func.EventGridEvent that is passed initially, download it to memory and then pass it to pandas methods. It seems like this would take longer for the file to be processed as well as a worry of not having enough memory to download. So with all of that in mind- I'm second guessing switching it to an Event Grid trigger. If any of that thinking is incorrect, please let me know.

CodePudding user response:

With Blob Trigger I don't think it's possible. What you can do is use Event Grid and implement event filtering by date, then your Azure Function will only get triggered by the events that match the filtering condition (which in this case will be the date/time you want)

https://learn.microsoft.com/en-us/azure/event-grid/how-to-filter-events#filter-by-operators-and-data

PS: with Event Grid you can also detect if it's a new/updated blob

CodePudding user response:

I do agree with @Thiago Custodio that you can use event grid trigger.

But as an alternative approach you can use Logic apps to trigger your azure function at a particular time as below:

enter image description here

You can use a recurrence trigger in Logic Apps and use at hours and at minutes to trigger your Azure Function.

In azure function you can code what activity you want to do.

And you can use Event Grid Trigger in Function app and even in Logic app as @Thiago Custodio suggested.

  • Related