Question
· Oct 12, 2022

How to check if on a file on a network shared folder is available/exists with a timeout ?

I use the following code to check the last modified date of file which is on a network shared folder (eg: "\\someserver\subfolder\foobar.txt")

set file = ##class(%File).%New(filePath)
set lastModifiedDate = file.DateModified //might hang up for a very long time 
set file = "" //close file

if the file is not available or does not exists, DateModified property return a negative value (which is fine). I use that property to quickly check if file has been modified and need to be imported.

Here is the issue: sometimes, accessing DateModified property will hang up for a long time (about 5 minutes) which is unacceptable in my case. It usually occurs because of some network issue (eg: server not available).

I have tried the following : 

set file = ##class(%File).%New(filePath)
if file.Open("R", 5) //5 seconds timeout, but still hang up
{
   //file is available
}
set file = ""

 and this

OPEN filePath:("R"):5 //might also hang up for several minutes
IF $TEST
{
   //...
}
CLOSE filePath

or this 

if ##class(%File).Exists(filePath)
{
   //...
}

It does not improve anything and still hang up. The 5 seconds timeout works only with local files.

It looks like the timeout is more "how long to wait until the file is created or become available" rather than "maximum time the related I/O operation should take before giving up".

I have in mind to start a job and wait for some amount of time and kill it if necessary but since (AFAIK) each job call spawn a new process I am not sure it's a good idea.

Any suggestions ?

Product version: IRIS 2021.1
$ZV: IRIS for Windows (x86-64) 2021.1 (Build 215U) Wed Jun 9 2021 09:39:22 EDT
Discussion (2)2
Log in or sign up to continue