|
From: Pieter L. <pie...@be...> - 2019-07-08 22:16:37
|
Thanks Anthony, that seems to work! Now I only have to work around some write permission limitations. btw curious as I was, I looked at xml.io and found an exist-db instance. I am not sure you want to expose this (but maybe you do). best Pieter On 08/07/2019 20:42, Anthony Frey wrote: > The problem I found with util:eval-async() is that the first argument > is documented as "expression as item()" which implies that it should > be an XQuery string or possibly an xs:anyURI that points to an > executable resource. However, the function as implemented actually > expects an inline XQuery expression, e.g. > > util:eval-async(let $foo := 'bar' return $foo) > > So, what actually happens is that the XQuery processor evaluates the > inner expression before actually invoking the concurrent thread which > kind of defeats the purpose of the async call. > > Instead, I've been using this technique for many years and have found > it to be reliable. The method simply uses the built-in Quartz > scheduler to schedule a new job with no delay. Like you, I don't > really need true fork/join concurrency or callbacks. I use it mostly > for very long running queries with lots of updates that would exceed > any reasonable web request timeout. > > let $async-id := util:uuid() > > let $expr := concat( > > 'xquery version "3.0"; ', > > 'declare variable $local:async-id := "',$async-id, '"; ', > > 'let $output := true() ', > > 'let $void := async-util:finish-eval($output, $local:async-id) ', > > 'return $output' > > ) > > let $void := async-util:eval($expr, $async-id) > > > async-util.xqm: > > xquery version "3.0"; > > > module namespace async-util="tag:an...@xm... > <mailto:tag%3Aa...@xm...>,2019:exist/async-util"; > > > declare variable $async-util:default-period:= 0; > > declare variable $async-util:default-delay:= 0; > > declare variable $async-util:repeat:= 0; > > declare variable $async-util:output-col:= "/db/data/async"; > > > declare function async-util:eval($expras item(), $async-idas > xs:string) as item()* > > { > > let $xql-name:= concat($async-id,".xql") > > let$xql-uri:= concat($async-util:output-col,"/",$xql-name) > > let$void:= xmldb:store($async-util:output-col,$xql-name,$expr) > > let$void:= async-util:exec($xql-uri) > > > return > > $async-id > > }; > > > declare function async-util:finish-eval($outputas item()*, $async-idas > xs:string) as item()* > > { > > let $void := > > if (empty($output)) then ( > > xmldb:store($async-util:output-col,concat($async-id,".txt"), > xs:string('')) > > ) else if($outputinstance of node()) then ( > > xmldb:store($async-util:output-col,concat($async-id,".xml"), $output) > > ) else if($outputinstance of xs:base64Binary) then ( > > xmldb:store($async-util:output-col,concat($async-id,".bin"), $output) > > ) else ( > > xmldb:store($async-util:output-col,concat($async-id,".txt"), > xs:string($output)) > > ) > > let$xql-name:= concat($async-id,".xql") > > let$void:= xmldb:remove($async-util:output-col,$xql-name) > > return > > $output > > }; > > > declare function async-util:job-pending($async-idas xs:string?) as > xs:boolean{ > > let $xql-name:= concat($async-id,".xql") > > let$xql-uri:= concat($async-util:output-col,"/",$xql-name) > > let$doc:= util:binary-doc($xql-uri) > > return > > exists($doc) > > }; > > > declare function async-util:exec($xquery-resourceas xs:string) as empty() > > { > > async-util:exec($xquery-resource, <parameters/>) > > }; > > > declare function async-util:exec($xquery-resourceas xs:string, > $parametersas element()?) as empty() > > { > > async-util:exec($xquery-resource, concat("async: ",$xquery-resource), > $parameters) > > }; > > > declare function async-util:exec($xquery-resourceas xs:string, $nameas > xs:string, $parametersas element()?) as empty() > > { > > let $void:= scheduler:schedule-xquery-periodic-job($xquery-resource, > $async-util:default-period, $name, $parameters, > $async-util:default-delay, $async-util:repeat) > > return () > > }; > > ᐧ > > On Mon, Jul 8, 2019 at 4:48 AM Pieter Lamers > <pie...@be... <mailto:pie...@be...>> wrote: > > Hi Craig, > > Thanks for your replies. I am not particularly interested in the > process > completion in eXist, because I would have the PDF open in an external > viewer, and it would auto refresh when ready. I am sorry to hear that > this is not possible with eval-async. > > I thought I had found the function to at least do something (apart > from > spitting out a process id), but I cannot reproduce that now. I don't > think I can get the suggested XSLT solution to work, but I may > give it a > try. Any other solutions welcome. > > Best, > Pieter > > > On 07/07/2019 23:37, Craig Berry via Exist-open wrote: > >> On Jul 7, 2019, at 2:42 PM, Craig Berry via Exist-open > <exi...@li... > <mailto:exi...@li...>> wrote: > >> > >> The paper here: > >> > >> > <http://archive.xmlprague.cz/2019/files/xmlprague-2019-proceedings.pdf> > >> > >> says on page 9 regarding util:eval-async, "This facility proved > not to be particularly practical and has since been removed." > > More specifically, it's on the list of removals for eXist-db 5.0 > and in a discussion about all 5.x removals here: > > > > <https://github.com/eXist-db/exist/issues/2626> > > > > @joewiz notes simply, regarding util:eval-async, "long broken." > > > > There is a prototype implementation of a new approach to > concurrency written in XSLT here: > > > > <https://github.com/Saxonica/EXPath-Task-XSLT> > > > > but even if this syntax became available within eXist, I don't > think it really satisfies the OP's use case, which is really more > about spawning an external subprocess without pausing execution > while waiting for completion than about running XQuery tasks > asynchronously. > > > > It's not too hard to imagine an overload of process:execute that > provides this option with either a process:wait-for to coordinate > completion or perhaps a callback mechanism (because eventually you > do want to know whether that process completed successfully), but > I don't know whether this could be done safely with eXist's > present concurrency capabilities. > > > > ________________________________________ > > Craig A. Berry > > > > "... getting out of a sonnet is much more > > difficult than getting in." > > Brad Leithauser > > > > > > > > _______________________________________________ > > Exist-open mailing list > > Exi...@li... > <mailto:Exi...@li...> > > https://lists.sourceforge.net/lists/listinfo/exist-open > > -- > Pieter Lamers > John Benjamins Publishing Company > Postal Address: P.O. Box 36224, 1020 ME AMSTERDAM, The Netherlands > Visiting Address: Klaprozenweg 75G, 1033 NN AMSTERDAM, The Netherlands > Warehouse: Kelvinstraat 11-13, 1446 TK PURMEREND, The Netherlands > tel: +31 20 630 4747 > web: www.benjamins.com <http://www.benjamins.com> > > > > _______________________________________________ > Exist-open mailing list > Exi...@li... > <mailto:Exi...@li...> > https://lists.sourceforge.net/lists/listinfo/exist-open > -- Pieter Lamers John Benjamins Publishing Company Postal Address: P.O. Box 36224, 1020 ME AMSTERDAM, The Netherlands Visiting Address: Klaprozenweg 75G, 1033 NN AMSTERDAM, The Netherlands Warehouse: Kelvinstraat 11-13, 1446 TK PURMEREND, The Netherlands tel: +31 20 630 4747 web: www.benjamins.com |