98%macro mv_jobwaitfor(action
99 ,access_token_var=ACCESS_TOKEN
100 ,grant_type=sas_services
102 ,outds=work.mv_jobwaitfor
108%
if &mdebug=1 %then %
do;
109 %put &sysmacroname entry vars:;
115%
if &grant_type=detect %then %
do;
116 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
117 %
else %let grant_type=sas_services;
119%
if &grant_type=sas_services %then %
do;
120 %let oauth_bearer=oauth_bearer=sas_services;
121 %let &access_token_var=;
124%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
125 and &grant_type ne sas_services
128 ,msg=%str(Invalid value
for grant_type: &grant_type)
131%mp_abort(iftrue=(
"&inds"=
"0")
133 ,msg=%str(input dataset not provided)
135%mp_abort(iftrue=(%mf_existvar(&inds,uri)=0)
137 ,msg=%str(The URI variable was not found in the input dataset(&inds))
139%mp_abort(iftrue=(%mf_existvar(&inds,_program)=0)
141 ,msg=%str(The _PROGRAM variable was not found in the input dataset(&inds))
144%if %mf_nobs(&inds)=0 %then %do;
145 %put NOTE: Zero observations in &inds, &sysmacroname will now exit;
149options noquotelenmax;
151%let base_uri=%mf_getplatform(VIYARESTAPI);
154 length jobparams $32767;
162 if length(strip(uri))>6 and substr(strip(uri),length(strip(uri))-5)=
'/state'
163 then uri=substr(strip(uri),1,length(strip(uri))-6);
164 call symputx(cats(
'joburi',_n_),strip(uri),
'l');
165 call symputx(cats(
'jobname',_n_),_program,
'l');
166 call symputx(cats(
'jobparams',_n_),jobparams,
'l');
167 if last then call symputx(
'uricnt',_n_,
'l');
171%
if &action=ALL %then %let runcnt=&uricnt;
172%
else %
if &action=ANY %then %let runcnt=1;
173%
else %let runcnt=&uricnt;
176%let fname0=%mf_getuniquefileref();
179 format _program uri $128. state $32. stateDetails $32. timestamp datetime19.
181 call missing (of _all_);
187 %
if "&&joburi&i" ne
"0" %then %
do;
188 proc http method=
'GET' out=&fname0 &oauth_bearer url=
"&base_uri/&&joburi&i";
189 headers
"Accept"=
"application/json"
190 %
if &grant_type=authorization_code %then %
do;
191 "Authorization"=
"Bearer &&&access_token_var"
194 %
if &SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 201
196 data _null_;infile &fname0;input;putlog _infile_;run;
197 %mp_abort(mac=&sysmacroname
198 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
205 %let libref1=%mf_getuniquelibref();
206 libname &libref1 json fileref=&fname0;
209 length state stateDetails $32;
211 call symputx(
'status',state,
'l');
212 call symputx(
'stateDetails',stateDetails,
'l');
215 libname &libref1 clear;
217 %
if &status=completed or &status=failed or &status=canceled %then %
do;
221 insert into &outds
set
222 _program=
"&&jobname&i",
225 stateDetails=symget(
"stateDetails"),
226 timestamp=datetime(),
227 jobparams=symget(
"jobparams&i");
229 %
if %str(&outref) ne 0 %then %
do;
230 %mv_getjoblog(uri=&&joburi&i,outref=&outref,mdebug=&mdebug)
234 %
else %
if &status=idle or &status=pending or &status=running %then %
do;
240 %mp_abort(mac=&sysmacroname
241 ,msg=%str(status &status not expected!!)
245 %
if (&raise_err) %then %
do;
246 %
if (&status = canceled or &status = failed or %length(&stateDetails)>0)
248 %
if (
"&stateDetails" =
"%str(war)ning") %then %let SYSCC=4;
250 %put %str(ERR)OR: Job &&jobname&i. did not complete. &stateDetails;
256 %
if &i=&uricnt %then %
do;
260 select count(*) into:goback from &outds;
261 %if &goback lt &runcnt %then %let i=0;
265%if &mdebug=1 %then %do;
266 %put &sysmacroname exit vars:;
271 filename &fname0 clear;