96%macro mv_jobwaitfor(action
97 ,access_token_var=ACCESS_TOKEN
98 ,grant_type=sas_services
100 ,outds=work.mv_jobwaitfor
106%
if &mdebug=1 %then %
do;
107 %put &sysmacroname entry vars:;
113%
if &grant_type=detect %then %
do;
114 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
115 %
else %let grant_type=sas_services;
117%
if &grant_type=sas_services %then %
do;
118 %let oauth_bearer=oauth_bearer=sas_services;
119 %let &access_token_var=;
122%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
123 and &grant_type ne sas_services
126 ,msg=%str(Invalid value
for grant_type: &grant_type)
129%mp_abort(iftrue=(
"&inds"=
"0")
131 ,msg=%str(input dataset not provided)
133%mp_abort(iftrue=(%mf_existvar(&inds,uri)=0)
135 ,msg=%str(The URI variable was not found in the input dataset(&inds))
137%mp_abort(iftrue=(%mf_existvar(&inds,_program)=0)
139 ,msg=%str(The _PROGRAM variable was not found in the input dataset(&inds))
142%if %mf_nobs(&inds)=0 %then %do;
143 %put NOTE: Zero observations in &inds, &sysmacroname will now exit;
147options noquotelenmax;
149%let base_uri=%mf_getplatform(VIYARESTAPI);
152 length jobparams $32767;
154 call symputx(cats(
'joburi',_n_),substr(uri,1,55),
'l');
155 call symputx(cats(
'jobname',_n_),_program,
'l');
156 call symputx(cats(
'jobparams',_n_),jobparams,
'l');
157 if last then call symputx(
'uricnt',_n_,
'l');
161%
if &action=ALL %then %let runcnt=&uricnt;
162%
else %
if &action=ANY %then %let runcnt=1;
163%
else %let runcnt=&uricnt;
166%let fname0=%mf_getuniquefileref();
169 format _program uri $128. state $32. stateDetails $32. timestamp datetime19.
171 call missing (of _all_);
177 %
if "&&joburi&i" ne
"0" %then %
do;
178 proc http method=
'GET' out=&fname0 &oauth_bearer url=
"&base_uri/&&joburi&i";
179 headers
"Accept"=
"application/json"
180 %
if &grant_type=authorization_code %then %
do;
181 "Authorization"=
"Bearer &&&access_token_var"
184 %
if &SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 201
186 data _null_;infile &fname0;input;putlog _infile_;run;
187 %mp_abort(mac=&sysmacroname
188 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
195 %let libref1=%mf_getuniquelibref();
196 libname &libref1 json fileref=&fname0;
199 length state stateDetails $32;
201 call symputx(
'status',state,
'l');
202 call symputx(
'stateDetails',stateDetails,
'l');
205 libname &libref1 clear;
207 %
if &status=completed or &status=failed or &status=canceled %then %
do;
209 %let plainuri=%substr(&&joburi&i,1,55);
211 insert into &outds
set
212 _program=
"&&jobname&i",
215 stateDetails=symget(
"stateDetails"),
216 timestamp=datetime(),
217 jobparams=symget(
"jobparams&i");
220 %
if %str(&outref) ne 0 %then %
do;
221 %mv_getjoblog(uri=&plainuri,outref=&outref,mdebug=&mdebug)
224 %
else %
if &status=idle or &status=pending or &status=running %then %
do;
230 %mp_abort(mac=&sysmacroname
231 ,msg=%str(status &status not expected!!)
235 %
if (&raise_err) %then %
do;
236 %
if (&status = canceled or &status = failed or %length(&stateDetails)>0)
238 %
if (
"&stateDetails" =
"%str(war)ning") %then %let SYSCC=4;
240 %put %str(ERR)OR: Job &&jobname&i. did not complete. &stateDetails;
246 %
if &i=&uricnt %then %
do;
250 select count(*) into:goback from &outds;
251 %if &goback lt &runcnt %then %let i=0;
255%if &mdebug=1 %then %do;
256 %put &sysmacroname exit vars:;
261 filename &fname0 clear;