Azure / azure-webjobs-sdk-extensions

Azure WebJobs SDK Extensions
MIT License
342 stars 206 forks source link

FileTrigger firing too soon #180

Open KennethCowley opened 7 years ago

KennethCowley commented 7 years ago

Have implemented a WebJob which monitors a folder on the WebSite for incoming CSV files. I am using the filer trigger as the means of activating the processing code when the file arrives using the following code

public static void ProcessCSV([FileTrigger(FilePath, FilePattern, WatcherChangeTypes.Created, autoDelete: true)] Stream file, string name, TextWriter log) { do work }

The web Job starts successfully put when the file arrives in the folder I get the following exception

Function had errors. See Azure WebJobs SDK dashboard for details. Instance ID is 'e914f9d3-6132-4a43-b332-68d42d532947' [01/04/2017 07:39:17 > b46fd4: INFO] Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Program.ProcessCSV ---> System.IO.IOException: The process cannot access the file 'D:\home\data\CSV\dstl.csv' because it is being used by another process.

I am using PowerShell up upload the file to the WebSite (an app service in Azure) using the KUDU API as at this time there is no ability to monitor Azure Files using the trigger extensions. It looks like the trigger is firing too soon, i.e. before the upload is completed. How do I make it wait for the file to fully upload and be released so that I can process it?

mathewc commented 7 years ago

Sorry it took us too long to notice this issue, thanks for logging this.

How big are the files you're uploading? I'd like to try to reproduce this, so any instructions you can give me (or an example file demonstrating the issue) would help.

Likely we need to update the trigger so it waits until all write operations are complete before invoking your function. To work around this until we get a fix in place, instead of binding to Stream you can try biniding to FileInfo which will give you the path and won't attempt to read the file. Then, in your code, you can experiment with adding a delay, allowing the file upload operations to complete on the file before using the file APIs yourself to open it. Can you give that a try?

KennethCowley commented 7 years ago

Hi,

Thanks for gett8ing back to me, the files are not very big I have included one as an example for you to test with.

Thanks

Ken

[Description: cid:image001.gif@01D02C05.44CCB770]http://www.enterpriseholdings.com/

Dr Ken Cowley

Software Engineer 4

OFFICE +44 (0) 1784494748 MOBILE +44 (0) 7803265092

kenneth.d.cowley@ehi.commailto:kenneth.d.cowley@ehi.com

Operating

[Description: cid:image003.jpg@01D02C05.44CCB770]

Enterprise House Melburne Park Vicarage Road Egham TW20 9FB United Kingdom

From: Mathew Charles [mailto:notifications@github.com] Sent: 27 January 2017 03:55 To: Azure/azure-webjobs-sdk-extensions Cc: Cowley, Kenneth D; Author Subject: Re: [Azure/azure-webjobs-sdk-extensions] FileTrigger firing too soon (#180)

Sorry it took us too long to notice this issue, thanks for logging this.

How big are the files you're uploading? I'd like to try to reproduce this, so any instructions you can give me (or an example file demonstrating the issue) would help.

Likely we need to update the trigger so it waits until all write operations are complete before invoking your function. To work around this until we get a fix in place, instead of binding to Stream you can try biniding to FileInfo which will give you the path and won't attempt to read the file. Then, in your code, you can experiment with adding a delay, allowing the file upload operations to complete on the file before using the file APIs yourself to open it. Can you give that a try?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/Azure/azure-webjobs-sdk-extensions/issues/180#issuecomment-275583767, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AM2B8s-lJ91PbOdDMcIwfRL8spuWGxaYks5rWWqmgaJpZM4LamJy.


CONFIDENTIALITY NOTICE: This e-mail and any attachments are confidential and may contain information that is privileged. If you are not the named recipient, or responsible for delivering the message to the named recipient, you must not disclose, distribute, forward, copy, store or use this e- mail or its attachments in any form. If you have received this communication in error, please accept our apologies and promptly inform the sender by e-mail or by telephoning the above number. Please also immediately delete this message and any attachments from your systems.

To the extent permitted by law, we may monitor electronic communications for the purposes of ensuring compliance with our legal and regulatory obligations and internal policies. Although this e- mail and its attachments have been checked by an up-to-date virus-checking program before transmission, it is your responsibility as recipient to ensure they are actually virus free when received.

Enterprise Rent-A-Car UK Limited is registered in England and Wales with registered number 2946689. The company's registered office is Enterprise House, Melburne Park, Vicarage Road, Egham Surrey TW20 9FB.

rdeveen commented 6 years ago

Likely we need to update the trigger so it waits until all write operations are complete before invoking your function.

Would love to see this functionality added to the FileTrigger. Using the FileInfo and using a delay does not solve this problem.