I am using wm.tn.query services to export data from Trading Networks. The suggested way to do this is to obtain an ‘enumeration identifier’ from wm.tn.query:documentQuery
service, then retrieve and process records one ‘page’ at a time using wm.tn.enumerate:nth
. However, this process seems to be buggy. Any suggestions?
Here’s the skeleton form of my code, which has become quite complex. There are two REPEAT loops - the outer loop processes the pages one by one, the inner loop keeps re-reading the current page if the next page isn’t ready, and also decides when to exit the inner and outer loops.
INVOKE wm.tn.query:createDocumentQuery
INVOKE wm.tn.query:documentQuery (Return enumeration identifier to access paged query results)
SET N=1
REPEAT (OUTER_LOOP)
INVOKE wm.tn.enumerate:nth (Read page N)
<<Process data>>
REPEAT (INNER_LOOP) (Only move ahead when next page is ready)
IF N < pagesRead (the next page is ready)
N=N+1
EXIT INNER_LOOP
DEFAULT: (re-read page N)
Sleep 3 seconds
INVOKE wm.tn.enumerate:nth (Re-read page N to refresh outputs like pagesRead, threadRunning, etc)
IF N = pagesRead && threadRunning="false" && totalRows != -1 (the last page has been proceessed -- end flow)
EXIT OUTER_LOOP
Processing larger datasets returns inconsistent results in consecutive runs (differing number of records). Also, changing the pageSize
parameter in the wm.tn.query:documentQuery
call changes the number of records returned. These are sure indicators something is wrong with the pagination process.
I am not seeing errors or exceptions. I increased the TN tn.query.maxrows
parameter to 500000 to ensure TN doesn’t truncate results.
In comparison to the pagination approach, if I run a similar program that sets disablePaging=true
in wm.tn.query:documentQuery
, that program returns an increased number of records and does so reliably (record counts do not vary). However, this model is not suitable for large data export volumes.
Any suggestions?
PS: The code in this post is a updated version of the code in my older post here:
Can Trading Networks export document delivery data? - #7 by Sonam_Chauhan
*PPS: the outputs of wm.tn.enumerate:nth
also don’t always behave as documented. For example, this set of logged outputs observed below contradict this documentation: "When the query completes, (threadRunning is false), the service provides the total number of rows. ". Here, threadRunning is false but totalRows is still -1. *
```
resultCount=161
rowsRead=0
pagesRead=1
threadRunning=false
totalPages=%totalPages% <unsubstituted, i.e. null>
totalRows=-1