0

I have created a azure function on powershell which works on http hit . It is writing a JSON file at its root folder after processing it. But if multiple hit occurs at same time then it throws file in use error. I know azure function doesn't work good on multi threading and variables can be modified while running one process and 2nd process occurs. I don't want to use queue storage so any good suggestion how to do it?

2
  • First of all: anything you write in the json file might (will) be gone after (the app service plan for) your function recycles or changes. Also, if your function scales, you'll get a second json file that doesn't hold any history. You might not want that... Second: why not use Storage/SQL/Cosmos DB/Table Storage/Application Insights/whatever for this solution? And third: The problem should only occur with multiple instances on the same instance. You could look into creating a lock for the file. Commented Dec 1, 2017 at 8:18
  • I am reading file data and over writing it again to the same file so that I can get history data also and its working fine when hit occurs with some interval, but when two hit occurs at the same then both instances tries to access file where one can hold it and other throws the error and as a result error one instance clears all file data and leaving empty file behind. Commented Dec 1, 2017 at 9:29

1 Answer 1

1

DO NOT WRITE ANYTHING TO THE AZURE FUNCTIONS FILESYSTEM THAT YOU DO NOT WANT TO LOSE.

Use Cosmos DB or some other external data store to store your data.

Without a code sample, it is hard to say what you might be doing wrong. You should be able to do this fine, from a code point of view, but you need to check if the file is in use and handle errors when it is (i.e. wait or throw a 429 error/etc.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.