131%macro mv_jobflow(inds=0,outds=work.mv_jobflow
133 ,access_token_var=ACCESS_TOKEN
134 ,grant_type=sas_services
140%
if &mdebug=1 %then %
do;
141 %put &sysmacroname entry vars:;
152%
if &grant_type=detect %then %
do;
153 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
154 %
else %let grant_type=sas_services;
156%
if &grant_type=sas_services %then %
do;
157 %let oauth_bearer=oauth_bearer=sas_services;
158 %let &access_token_var=;
161%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
162 and &grant_type ne sas_services
165 ,msg=%str(Invalid value
for grant_type: &grant_type)
168%mp_abort(iftrue=(
"&inds"=
"0")
170 ,msg=%str(Input dataset was not provided)
172%mp_abort(iftrue=(%mf_existVarList(&inds,_PROGRAM)=0)
174 ,msg=%str(The _PROGRAM column must exist on input dataset &inds)
176%mp_abort(iftrue=(&maxconcurrency<1)
178 ,msg=%str(The maxconcurrency variable should be a positive integer)
182%if %mf_existVarList(&inds,_CONTEXTNAME FLOW_ID)=0 %then %do;
184 %
if %mf_existvarList(&inds,_CONTEXTNAME)=0 %then %
do;
185 length _CONTEXTNAME $128;
186 retain _CONTEXTNAME
"SAS Job Execution compute context";
188 %
if %mf_existvarList(&inds,FLOW_ID)=0 %then %
do;
192 retain _omitSessionResults
"false";
194 &dbg. putlog (_all_)(=);
200select count(*) into: missings
202 where flow_id is null or _program is null;
203%mp_abort(iftrue=(&missings>0)
205 ,msg=%str(input dataset has &missings missing values for FLOW_ID or _PROGRAM)
208%if %mf_nobs(&inds)=0 %then %do;
209 %put No observations in &inds! Leaving macro &sysmacroname;
218options noquotelenmax;
220%let base_uri=%mf_getplatform(VIYARESTAPI);
228 set &inds (keep=flow_id) end=last;
230 if last.flow_id then do;
232 call symputx(cats('flow',cnt),flow_id,'l');
234 if last then call symputx('flowcnt',cnt,'l');
238%local fid jid jds jdsapp jdsrunning jdswaitfor;
239data;run;%let jds=&syslast;
240data;run;%let jdsapp=&syslast;
241data;run;%let jdsrunning=&syslast;
242data;run;%let jdswaitfor=&syslast;
245%do fid=1 %to &flowcnt;
247 %if not ( &raise_err and &syscc ) %then %do;
249 %put preparing job attributes for flow &&flow&fid;
251 data &jds(drop=_contextName _program);
252 set &inds(where=(flow_id=&&flow&fid));
253 if _contextName='' then _contextName="SAS Job Execution compute context";
254 call symputx(cats('job',_n_),_program,'l');
255 call symputx(cats('context',_n_),_contextName,'l');
256 call symputx('jcnt',_n_,'l');
257 &dbg. if _n_= 1 then putlog "Loop &fid";
258 &dbg. putlog (_all_)(=);
262 %local nvars cvars ii _vnm;
263 %let cvars=%mf_getvarlist(&jds,typefilter=C);
264 %let nvars=%mf_getvarlist(&jds,typefilter=N);
265 %put exporting job variables in json format;
270 length _param $32767;
272 %if %length(&cvars)>0 %then %do ii=1 %to %sysfunc(countw(&cvars,%str( )));
273 %let _vnm=%scan(&cvars,&ii,%str( ));
274 if _param ne '' then _param=cats(_param,',');
285 _param=cats(_param,'"'
288 ,tranwrd(tranwrd(tranwrd(tranwrd(trim(&_vnm),'\','\\'),'0D'x,'\r'),'0A'x,'\n'),'"','\"')
292 %if %length(&nvars)>0 %then %do ii=1 %to %sysfunc(countw(&nvars,%str( )));
293 %let _vnm=%scan(&nvars,&ii,%str( ));
294 if _param ne '' then _param=cats(_param,',');
295 _param=cats(_param,'"'
298 ,strip(put(&_vnm,best32.))
302 call symputx(cats('jparams',&jid),_param,'l');
308 %local concurrency completed;
311 proc sql; drop table &jdsrunning;
316 %if "&&job&jid" ne "0" %then %do;
319 %if %sysfunc(exist(&outds))=1 %then %do;
320 %local jobcheck; %let jobcheck=0;
322 select count(*) into: jobcheck
323 from &outds where uuid="&&jobuid&jid";
324 %if &jobcheck>0 %then %do;
325 %put &&job&jid in flow &fid with uid &&jobuid&jid completed!;
332 %if ("&&jobuid&jid"="0") and (&concurrency<&maxconcurrency) %then %do;
335 %if not ( &raise_err and &syscc ) %then %do;
337 %local jobname jobpath;
338 %let jobname=%scan(&&job&jid,-1,/);
340 %substr(&&job&jid,1,%length(&&job&jid)-%length(&jobname)-1);
345 %put executing &jobpath/&jobname with paramstring %superq(jparams&jid);
346 %mv_jobexecute(path=&jobpath
348 ,paramstring=%superq(jparams&jid)
350 ,contextname=&&context&jid
354 format jobparams $32767.;
355 set &jdsapp(where=(method='GET' and rel='state'));
356 jobparams=symget("jparams&jid");
358 uuid=scan(uri,-2,'/');
359 call symputx("jobuid&jid",uuid,'l');
361 proc append base=&jdsrunning data=&jdsapp;
363 %let concurrency=%eval(&concurrency+1);
372 %put jobid &&job&jid in flow &fid skipped due to SYSCC (&syscc);
373 %let completed = %eval(&completed+1);
380 %if &jid=&jcnt %then %do;
382 %mv_jobwaitfor(ANY,inds=&jdsrunning,outds=&jdswaitfor,outref=&outref
383 ,raise_err=&raise_err,mdebug=&mdebug)
385 %let done=%mf_nobs(&jdswaitfor);
386 %if &done>0 %then %do;
387 %let completed=%eval(&completed+&done);
388 %let concurrency=%eval(&concurrency-&done);
392 uuid=scan(uri,-1,'/');
394 proc append base=&outds data=&jdsapp;
398 delete from &jdsrunning
399 where uuid in (select uuid from &outds
400 where state in ('canceled','completed','failed')
404 %if &completed < &jcnt %then %do;
406 %put looping flow &fid again;
407 %put &completed of &jcnt jobs completed, &concurrency jobs running;
415 %put Flow &&flow&fid skipped due to SYSCC (&syscc);
421%if &mdebug=1 %then %do;
422 %put &sysmacroname exit vars:;