89 %macro mv_jobwaitfor(action
90 ,access_token_var=ACCESS_TOKEN
91 ,grant_type=sas_services
93 ,outds=work.mv_jobwaitfor
96 %
if &grant_type=detect %then %
do;
97 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
98 %
else %let grant_type=sas_services;
100 %
if &grant_type=sas_services %then %
do;
101 %let oauth_bearer=oauth_bearer=sas_services;
102 %let &access_token_var=;
105 %mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
106 and &grant_type ne sas_services
109 ,msg=%str(Invalid value
for grant_type: &grant_type)
112 %mp_abort(iftrue=(
"&inds"=
"0")
114 ,msg=%str(input dataset not provided)
116 %mp_abort(iftrue=(%mf_existvar(&inds,uri)=0)
118 ,msg=%str(The URI variable was not found in the input dataset(&inds))
120 %mp_abort(iftrue=(%mf_existvar(&inds,_program)=0)
122 ,msg=%str(The _PROGRAM variable was not found in the input dataset(&inds))
125 %
if %mf_nobs(&inds)=0 %then %
do;
126 %put NOTE: Zero observations in &inds, &sysmacroname will now exit;
130 options noquotelenmax;
132 %let base_uri=%mf_getplatform(VIYARESTAPI);
135 length jobparams $32767;
137 call symputx(cats(
'joburi',_n_),uri,
'l');
138 call symputx(cats(
'jobname',_n_),_program,
'l');
139 call symputx(cats(
'jobparams',_n_),jobparams,
'l');
140 if last then call symputx(
'uricnt',_n_,
'l');
144 %
if &action=ALL %then %let runcnt=&uricnt;
145 %
else %
if &action=ANY %then %let runcnt=1;
146 %
else %let runcnt=&uricnt;
149 %let fname0=%mf_getuniquefileref();
152 format _program uri $128. state $32. timestamp datetime19. jobparams $32767.;
158 %
if "&&joburi&i" ne
"0" %then %
do;
159 proc http method=
'GET' out=&fname0 &oauth_bearer url=
"&base_uri/&&joburi&i";
160 headers
"Accept"=
"text/plain"
161 %
if &grant_type=authorization_code %then %
do;
162 "Authorization"=
"Bearer &&&access_token_var"
165 %
if &SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 201 %then
167 data _null_;infile &fname0;input;putlog _infile_;run;
168 %mp_abort(mac=&sysmacroname
169 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
177 call symputx(
'status',_infile_,
'l');
180 %
if &status=completed or &status=failed or &status=canceled %then %
do;
182 insert into &outds
set
183 _program=
"&&jobname&i",
186 timestamp=datetime(),
187 jobparams=symget(
"jobparams&i");
190 %
else %
if &status=idle or &status=pending or &status=running %then %
do;
196 %mp_abort(mac=&sysmacroname
197 ,msg=%str(status &status not expected!!)
201 %
if &i=&uricnt %then %
do;
205 select count(*) into:goback from &outds;
206 %if &goback lt &runcnt %then %let i=0;
211 filename &fname0 clear;