I’m working out an “orchestration” module that manages running jobs that are functions from different modules, where the orchestrator dynamically constructs an XQuery that runs the specified function with the specified string parameters.
I’m running jobs through a function that takes a sequence of jobs (XQuery strings) and calls jobs:eval() on each one in sequence:
declare function orch:runJobs($jobs as xs:string*) as xs:string* { let $debug := util:logToLog('Have ' || count($jobs) || ' jobs:') let $debug := prof:dump($jobs) return for $job at $i in $jobs let $debug := (util:logToLog('Running job'), prof:dump($job)) return try { jobs:eval($job, (), map{'cache' : true(), 'log' : 'Running job: ' || $job}) } catch * { util:logToLog('orch:runJobs', ('Error running job ' || $err:code || ': ' || $err:description) ) } };
What I’m trying to achieve is a sequence of jobs run such that job 2 does not start until job 1 is finished and I don’t think that’s actually what I’m producing here. Most of these jobs are manipulating databases: dropping, creating, renaming, copying, etc., but a few will be longer-running—constructing indexes and whatnot.
My question: What is the (best?) way to produce a sequence of jobs where each job waits for the preceding?
Is it simply to do a jobs:wait(jobs:eval()) on each job or is there something better?
Or am I missing a simpler way to perform this kind of job orchestration?
Thanks,
E.
_____________________________________________ Eliot Kimber Sr Staff Content Engineer O: 512 554 9368 M: 512 554 9368 servicenow.comhttps://www.servicenow.com LinkedInhttps://www.linkedin.com/company/servicenow | Twitterhttps://twitter.com/servicenow | YouTubehttps://www.youtube.com/user/servicenowinc | Facebookhttps://www.facebook.com/servicenow