132%macro mv_jobflow(inds=0,outds=work.mv_jobflow
134 ,access_token_var=ACCESS_TOKEN
135 ,grant_type=sas_services
141%
if &mdebug=1 %then %
do;
142 %put &sysmacroname entry vars:;
153%
if &grant_type=detect %then %
do;
154 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
155 %
else %let grant_type=sas_services;
157%
if &grant_type=sas_services %then %
do;
158 %let oauth_bearer=oauth_bearer=sas_services;
159 %let &access_token_var=;
162%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
163 and &grant_type ne sas_services
166 ,msg=%str(Invalid value
for grant_type: &grant_type)
169%mp_abort(iftrue=(
"&inds"=
"0")
171 ,msg=%str(Input dataset was not provided)
173%mp_abort(iftrue=(%mf_existVarList(&inds,_PROGRAM)=0)
175 ,msg=%str(The _PROGRAM column must exist on input dataset &inds)
177%mp_abort(iftrue=(&maxconcurrency<1)
179 ,msg=%str(The maxconcurrency variable should be a positive integer)
183%
if %mf_existVarList(&inds,_CONTEXTNAME FLOW_ID)=0 %then %
do;
185 %
if %mf_existvarList(&inds,_CONTEXTNAME)=0 %then %
do;
186 length _CONTEXTNAME $128;
187 retain _CONTEXTNAME
"SAS Job Execution compute context";
189 %
if %mf_existvarList(&inds,FLOW_ID)=0 %then %
do;
193 retain _omitSessionResults
"false";
195 &dbg. putlog (_all_)(=);
201select count(*) into: missings
203 where flow_id is null or _program is null;
204%mp_abort(iftrue=(&missings>0)
206 ,msg=%str(input dataset has &missings missing values for FLOW_ID or _PROGRAM)
209%if %mf_nobs(&inds)=0 %then %do;
210 %put No observations in &inds! Leaving macro &sysmacroname;
219options noquotelenmax;
221%let base_uri=%mf_getplatform(VIYARESTAPI);
229 set &inds (keep=flow_id) end=last;
231 if last.flow_id then do;
233 call symputx(cats('flow',cnt),flow_id,
'l');
235 if last then call symputx('flowcnt',cnt,
'l');
239%local fid jid jds jdsapp jdsrunning jdswaitfor;
240data;run;%let jds=&syslast;
241data;run;%let jdsapp=&syslast;
242data;run;%let jdsrunning=&syslast;
243data;run;%let jdswaitfor=&syslast;
246%do fid=1 %to &flowcnt;
248 %if not ( &raise_err and &syscc ) %then %do;
250 %put preparing job attributes for flow &&flow&fid;
252 data &jds(drop=_contextName _program);
253 set &inds(where=(flow_id=&&flow&fid));
254 if _contextName='' then _contextName=
"SAS Job Execution compute context";
255 call symputx(cats('job',_n_),_program,
'l');
256 call symputx(cats('context',_n_),_contextName,
'l');
257 call symputx('jcnt',_n_,
'l');
258 &dbg. if _n_= 1 then putlog
"Loop &fid";
259 &dbg. putlog (_all_)(=);
263 %local nvars cvars ii _vnm;
264 %let cvars=%mf_getvarlist(&jds,typefilter=C);
265 %let nvars=%mf_getvarlist(&jds,typefilter=N);
266 %put exporting job variables in json format;
271 length _param $32767;
273 %if %length(&cvars)>0 %then %do ii=1 %to %sysfunc(countw(&cvars,%str( )));
274 %let _vnm=%scan(&cvars,&ii,%str( ));
275 if _param ne '' then _param=cats(_param,
',');
286 _param=cats(_param,
'"'
289 ,tranwrd(tranwrd(tranwrd(tranwrd(trim(&_vnm),
'\',
'\\'),'0D'x,
'\r'),'0A'x,
'\n'),
'"',
'\"')
293 %if %length(&nvars)>0 %then %do ii=1 %to %sysfunc(countw(&nvars,%str( )));
294 %let _vnm=%scan(&nvars,&ii,%str( ));
295 if _param ne '' then _param=cats(_param,
',');
296 _param=cats(_param,
'"'
299 ,strip(put(&_vnm,best32.))
303 call symputx(cats('jparams',&jid),_param,
'l');
309 %local concurrency completed;
312 proc sql; drop table &jdsrunning;
317 %if
"&&job&jid" ne
"0" %then %do;
320 %if %sysfunc(exist(&outds))=1 %then %do;
321 %local jobcheck; %let jobcheck=0;
323 select count(*) into: jobcheck
324 from &outds where uuid=
"&&jobuid&jid";
325 %if &jobcheck>0 %then %do;
326 %put &&job&jid in flow &fid with uid &&jobuid&jid completed!;
333 %if (
"&&jobuid&jid"=
"0") and (&concurrency<&maxconcurrency) %then %do;
336 %if not ( &raise_err and &syscc ) %then %do;
338 %local jobname jobpath;
339 %let jobname=%scan(&&job&jid,-1,/);
341 %substr(&&job&jid,1,%length(&&job&jid)-%length(&jobname)-1);
346 %put executing &jobpath/&jobname with paramstring %superq(jparams&jid);
347 %mv_jobexecute(path=&jobpath
349 ,paramstring=%superq(jparams&jid)
351 ,contextname=&&context&jid
355 format jobparams $32767.;
356 set &jdsapp(where=(method='GET' and rel='state'));
357 jobparams=symget(
"jparams&jid");
359 uuid=scan(uri,-2,
'/');
360 call symputx(
"jobuid&jid",uuid,
'l');
362 proc append base=&jdsrunning data=&jdsapp;
364 %let concurrency=%eval(&concurrency+1);
373 %put jobid &&job&jid in flow &fid skipped due to SYSCC (&syscc);
374 %let completed = %eval(&completed+1);
381 %if &jid=&jcnt %then %do;
383 %mv_jobwaitfor(ANY,inds=&jdsrunning,outds=&jdswaitfor,outref=&outref
384 ,raise_err=&raise_err,mdebug=&mdebug)
386 %let done=%mf_nobs(&jdswaitfor);
387 %if &done>0 %then %do;
388 %let completed=%eval(&completed+&done);
389 %let concurrency=%eval(&concurrency-&done);
393 uuid=scan(uri,-1,
'/');
395 proc append base=&outds data=&jdsapp;
399 delete from &jdsrunning
400 where uuid in (select uuid from &outds
401 where state in ('canceled
','completed
','failed')
405 %if &completed < &jcnt %then %do;
407 %put looping flow &fid again;
408 %put &completed of &jcnt jobs completed, &concurrency jobs running;
416 %put Flow &&flow&fid skipped due to SYSCC (&syscc);
422%if &mdebug=1 %then %do;
423 %put &sysmacroname exit vars:;