Hi All,
I'm having trouble getting the <util:available> tag returning me a 'true' condition when a file is being found (which is actually the ability to execute a set of commands within the utl tag, from what I can gather).
What I'm trying to do is poll a fileshare directory for the existence of a file, and when the file existence is detected, exit the polling loop (and carry on with the rest of the GEL).
The problem I'm trying to solve is a file doesn't exist error when trying to open a file using the <file:readFile>. To make this issue most interesting, only our production environment exhibits the issue of not finding this file on the fileshare using the <file:readFile> tag (and if I simply 'retry' the process after 2-8 minutes, the script finds the file just fine, without any polling logic needed).
Two snippets below, namespaces and polling loop. The loop does iterate, but the commands within the util:available doesn't ever get executed. The loop does iterate, and sleeps ok with the said milliseconds, but the file is never 'seen' by the util:available. Funny thing is, the file is actually there......
What am I doing wrong? I've tried with and without the "file://" prefic for the uri.
The fileshare directory is of the form /fs0/clarity1/files/filestore/clarity/
(I'm on v13.1, CA on demand).
Regards,
Sam.
======================
<gel:script
xmlns:core="jelly:core"
xmlns:file="jelly:com.niku.union.gel.FileTagLibrary"
xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sql="jelly:sql"
xmlns:util="jelly:util"
xmlns:xog="http://www.niku.com/xog"
>
<!-- snip -->
<core:set value="false" var="errorFlag"/>
<!-- snip -->
<!-- check for file existence a number of times, before timing out if required-->
<!-- CA couldn't resolve this timing issue for us, which only happens in PROD, not in dev or test yet. -->
<core:if test="${errorFlag==false}">
<core:set value="0" var="v_file_exists"/>
<core:set value="0" var="v_counter"/>
<core:set value="24" var="v_counter_limit"/>
<core:set value="500" var="v_sleep_ms"/>
<core:while test="${v_counter le v_counter_limit and v_file_exists eq 0}">
<core:catch var="v_exception">
<util:available uri="file://${v_fileStore}${file}">
<gel:log category="File" level="INFO">File available returned true on iteration ${v_counter}.</gel:log>
<core:set value="1" var="v_file_exists"/>
</util:available>
</core:catch>
<core:choose>
<core:when test="${v_exception!=null}">
<gel:log category="File" level="WARN">Unable to test for file existence:${file} from directory:${v_fileStore} Exception:${v_exception}.</gel:log>
<core:set value="true" var="errorFlag"/>
</core:when>
<core:when test="${v_counter lt v_counter_limit}">
<gel:log category="File" level="INFO">File polling iteration ${v_counter}, sleeping...</gel:log>
<util:sleep millis="${v_sleep_ms}"/>
</core:when>
<core:when test="${v_counter ge v_counter_limit}">
<core:set value="Polled too many times / Timed out polling for file existence:${file} from directory:${v_fileStore} Iteration:(${v_counter}) out of (${v_counter_limit}), waiting (${v_sleep_ms/1000}) seconds between each." var="v_exception"/>
<gel:log category="File" level="WARN">${v_exception}</gel:log>
<core:set value="true" var="errorFlag"/>
</core:when>
<core:otherwise>
<gel:log category="File" level="WARN">Shouldnt ever be here ${v_counter}.</gel:log>
</core:otherwise>
</core:choose>
<core:set value="${v_counter+1}" var="v_counter"/>
</core:while>
</core:if>
<!-- open the file from the windows directory, and load to a gel variable. -->
<core:if test="${errorFlag==false}">
<core:catch var="v_exception">
<file:readFile
delimiter="~"
embedded="false"
escapeText="true"
fileName="${v_fileStore}${file}"
var="v_file_in_mem"/>
</core:catch>
<core:choose>
<core:when test="${v_exception!=null}">
<gel:log category="File" level="ERROR">Unable to read file:${file} from directory:${v_fileStore} Exception:${v_exception}.</gel:log>
<core:set value="true" var="errorFlag"/>
</core:when>
<core:otherwise>
<core:set value="${v_file_in_mem.size()}" var="v_file_in_mem_size"/>
<core:set value="0" var="v_count"/>
<core:if test="${DEBUG>0}">
<gel:log category="File" level="INFO">File has ${v_file_in_mem_size} rows.</gel:log>
</core:if>
</core:otherwise>
</core:choose>
</core:if>