File in use, Catch/Try a number of times

L

Larry Bud

We have a web service that a client can send XML to, and that XML is
appended to a file on the server for each call.

At night, a separate processing console app will process the XML.

How would you recommend this interaction to occur so the web service
doesn't step on the toes of the processing app and vice versa?

I thought of having the console app move the XML file out of the
current folder and put it somewhere else. The WS will then recreate
the XML file for the next day. But if the WS is accessing the file, I
won't be able to move it. Should I just loop for a certain amount of
time until the file is able to be moved?

Then in the WS, if the file is being moved and is access, do the same?
 
M

Mark Rae [MVP]

How would you recommend this interaction to occur so the web service
doesn't step on the toes of the processing app and vice versa?

Firstly, the absolute last thing I'd do is have a text file on a web server
which can potentially be locked by more than one user - seems like a
disaster waiting to happen...

Instead, every time a client does an upload, I'd create a separate file with
a dynamically created filename - I'd almost certainly construct the filename
based on a combination of the client's unique identifier and a timestamp
e.g. 123-20080111144130.xml or 20080111144130-123.xml. That way you wouldn't
need to worry about file locking or overwriting...

Then I'd set my processing app to run at just after midnight, and design it
so that it polled the folder containing the XML file(s), inspecting the
filename so that it processed only the files where the timetamp portion of
the filename was earlier than the current day, deleting / renaming them
after successful processing...
 
L

Larry Bud

Firstly, the absolute last thing I'd do is have a text file on a web server
which can potentially be locked by more than one user - seems like a
disaster waiting to happen...

Instead, every time a client does an upload, I'd create a separate file with
a dynamically created filename - I'd almost certainly construct the filename
based on a combination of the client's unique identifier and a timestamp
e.g. 123-20080111144130.xml or 20080111144130-123.xml. That way you wouldn't
need to worry about file locking or overwriting...

Then I'd set my processing app to run at just after midnight, and design it
so that it polled the folder containing the XML file(s), inspecting the
filename so that it processed only the files where the timetamp portion of
the filename was earlier than the current day, deleting / renaming them
after successful processing...

Great advice, thank you very much!
 
B

bruce barker

an additional good trick is to create the file with a name like <unique>.out,
then after its closed rename to <unique>.xml. then the pickup prograg will
not hit open files.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top