107%macro mv_jobwaitfor(action
108 ,access_token_var=ACCESS_TOKEN
109 ,grant_type=sas_services
111 ,outds=work.mv_jobwaitfor
117%
if &mdebug=1 %then %
do;
118 %put &sysmacroname entry vars:;
124%
if &grant_type=detect %then %
do;
125 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
126 %
else %let grant_type=sas_services;
128%
if &grant_type=sas_services %then %
do;
129 %let oauth_bearer=oauth_bearer=sas_services;
130 %let &access_token_var=;
133%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
134 and &grant_type ne sas_services
137 ,msg=%str(Invalid value
for grant_type: &grant_type)
140%mp_abort(iftrue=(
"&inds"=
"0")
142 ,msg=%str(input dataset not provided)
144%mp_abort(iftrue=(%mf_existvar(&inds,uri)=0)
146 ,msg=%str(The URI variable was not found in the input dataset(&inds))
148%mp_abort(iftrue=(%mf_existvar(&inds,_program)=0)
150 ,msg=%str(The _PROGRAM variable was not found in the input dataset(&inds))
153%if %mf_nobs(&inds)=0 %then %do;
154 %put NOTE: Zero observations in &inds, &sysmacroname will now exit;
158options noquotelenmax;
160%let base_uri=%mf_getplatform(VIYARESTAPI);
163 length jobparams $32767;
171 if length(strip(uri))>6 and substr(strip(uri),length(strip(uri))-5)=
'/state'
172 then uri=substr(strip(uri),1,length(strip(uri))-6);
173 call symputx(cats(
'joburi',_n_),strip(uri),
'l');
174 call symputx(cats(
'jobname',_n_),_program,
'l');
175 call symputx(cats(
'jobparams',_n_),jobparams,
'l');
176 if last then call symputx(
'uricnt',_n_,
'l');
180%
if &action=ALL %then %let runcnt=&uricnt;
181%
else %
if &action=ANY %then %let runcnt=1;
182%
else %let runcnt=&uricnt;
185%let fname0=%mf_getuniquefileref();
188 format _program uri $128. state $32. stateDetails $32. timestamp datetime19.
190 call missing (of _all_);
196 %
if "&&joburi&i" ne
"0" %then %
do;
197 proc http method=
'GET' out=&fname0 &oauth_bearer url=
"&base_uri/&&joburi&i";
198 headers
"Accept"=
"application/json"
199 %
if &grant_type=authorization_code %then %
do;
200 "Authorization"=
"Bearer &&&access_token_var"
203 %
if &SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 201
205 data _null_;infile &fname0;input;putlog _infile_;run;
206 %mp_abort(mac=&sysmacroname
207 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
214 %let libref1=%mf_getuniquelibref();
215 libname &libref1 json fileref=&fname0;
218 length state stateDetails $32;
220 call symputx(
'status',state,
'l');
221 call symputx(
'stateDetails',stateDetails,
'l');
224 libname &libref1 clear;
226 %
if &status=completed or &status=failed or &status=canceled %then %
do;
230 insert into &outds
set
231 _program=
"&&jobname&i",
234 stateDetails=symget(
"stateDetails"),
235 timestamp=datetime(),
236 jobparams=symget(
"jobparams&i");
238 %
if %str(&outref) ne 0 %then %
do;
239 %mv_getjoblog(uri=&&joburi&i,outref=&outref,mdebug=&mdebug)
243 %
else %
if &status=idle or &status=pending or &status=running %then %
do;
249 %mp_abort(mac=&sysmacroname
250 ,msg=%str(status &status not expected!!)
254 %
if (&raise_err) %then %
do;
255 %
if (&status = canceled or &status = failed or %length(&stateDetails)>0)
257 %
if (
"&stateDetails" =
"%str(war)ning") %then %let SYSCC=4;
259 %put %str(ERR)OR: Job &&jobname&i. did not complete. &stateDetails;
265 %
if &i=&uricnt %then %
do;
269 select count(*) into:goback from &outds;
270 %if &goback lt &runcnt %then %let i=0;
274%if &mdebug=1 %then %do;
275 %put &sysmacroname exit vars:;
280 filename &fname0 clear;