1
0
mirror of https://github.com/sasjs/core.git synced 2025-12-20 01:34:35 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
4b375e0b8c fix: leading zero in time component of mf_uid() 2021-03-19 20:34:16 +01:00
7db207dd1c chore: updating all.sas 2021-03-19 20:29:35 +01:00
2 changed files with 40 additions and 13 deletions

47
all.sas
View File

@@ -1426,12 +1426,12 @@ Usage:
%mend;/** %mend;/**
@file @file
@brief Creates a Unique ID based on system time in a friendly format @brief Creates a unique ID based on system time in friendly format
@details format = YYYYMMDD_HHMMSSmmm_<sysjobid>_<3randomDigits> @details format = YYYYMMDD_HHMMSSmmm_<sysjobid>_<3randomDigits>
%put %mf_uid(); %put %mf_uid();
@version 9.2 @version 9.3
@author Allan Bowe @author Allan Bowe
**/ **/
@@ -1440,7 +1440,7 @@ Usage:
)/*/STORE SOURCE*/; )/*/STORE SOURCE*/;
%local today now; %local today now;
%let today=%sysfunc(today(),yymmddn8.); %let today=%sysfunc(today(),yymmddn8.);
%let now=%sysfunc(compress(%sysfunc(time(),time12.3),:.)); %let now=%sysfunc(compress(%sysfunc(time(),tod12.3),:.));
&today._&now._&sysjobid._%sysevalf(%sysfunc(ranuni(0))*999,CEIL) &today._&now._&sysjobid._%sysevalf(%sysfunc(ranuni(0))*999,CEIL)
@@ -13910,6 +13910,8 @@ libname &libref;
@li sas_services - will use oauth_bearer=sas_services @li sas_services - will use oauth_bearer=sas_services
@param [in] inds= The input dataset containing a list of jobs and parameters @param [in] inds= The input dataset containing a list of jobs and parameters
@param [in] maxconcurrency= The max number of parallel jobs to run. Default=8. @param [in] maxconcurrency= The max number of parallel jobs to run. Default=8.
@param [in] raise_err=0 Set to 1 to raise SYSCC when a job does not complete
succcessfully
@param [in] mdebug= set to 1 to enable DEBUG messages @param [in] mdebug= set to 1 to enable DEBUG messages
@param [out] outds= The output dataset containing the results @param [out] outds= The output dataset containing the results
@param [out] outref= The output fileref to which to append the log file(s). @param [out] outref= The output fileref to which to append the log file(s).
@@ -13933,6 +13935,7 @@ libname &libref;
,access_token_var=ACCESS_TOKEN ,access_token_var=ACCESS_TOKEN
,grant_type=sas_services ,grant_type=sas_services
,outref=0 ,outref=0
,raise_err=0
,mdebug=0 ,mdebug=0
); );
%local oauth_bearer; %local oauth_bearer;
@@ -14111,7 +14114,8 @@ data;run;%let jdswaitfor=&syslast;
%end; %end;
%if &jid=&jcnt %then %do; %if &jid=&jcnt %then %do;
/* we are at the end of the loop - time to see which jobs have finished */ /* we are at the end of the loop - time to see which jobs have finished */
%mv_jobwaitfor(ANY,inds=&jdsrunning,outds=&jdswaitfor,outref=&outref) %mv_jobwaitfor(ANY,inds=&jdsrunning,outds=&jdswaitfor,outref=&outref
,raise_err=&raise_err)
%local done; %local done;
%let done=%mf_nobs(&jdswaitfor); %let done=%mf_nobs(&jdswaitfor);
%if &done>0 %then %do; %if &done>0 %then %do;
@@ -14218,6 +14222,8 @@ data;run;%let jdswaitfor=&syslast;
following format: `/jobExecution/jobs/&JOBID./state` and the corresponding following format: `/jobExecution/jobs/&JOBID./state` and the corresponding
job name. The uri should be in a `uri` variable, and the job path/name job name. The uri should be in a `uri` variable, and the job path/name
should be in a `_program` variable. should be in a `_program` variable.
@param [in] raise_err=0 Set to 1 to raise SYSCC when a job does not complete
succcessfully
@param [out] outds= The output dataset containing the list of states by job @param [out] outds= The output dataset containing the list of states by job
(default=work.mv_jobexecute) (default=work.mv_jobexecute)
@param [out] outref= A fileref to which the spawned job logs should be appended. @param [out] outref= A fileref to which the spawned job logs should be appended.
@@ -14229,6 +14235,7 @@ data;run;%let jdswaitfor=&syslast;
@li mp_abort.sas @li mp_abort.sas
@li mf_getplatform.sas @li mf_getplatform.sas
@li mf_getuniquefileref.sas @li mf_getuniquefileref.sas
@li mf_getuniquelibref.sas
@li mf_existvar.sas @li mf_existvar.sas
@li mf_nobs.sas @li mf_nobs.sas
@li mv_getjoblog.sas @li mv_getjoblog.sas
@@ -14241,6 +14248,7 @@ data;run;%let jdswaitfor=&syslast;
,inds=0 ,inds=0
,outds=work.mv_jobwaitfor ,outds=work.mv_jobwaitfor
,outref=0 ,outref=0
,raise_err=0
); );
%local oauth_bearer; %local oauth_bearer;
%if &grant_type=detect %then %do; %if &grant_type=detect %then %do;
@@ -14284,7 +14292,7 @@ options noquotelenmax;
data _null_; data _null_;
length jobparams $32767; length jobparams $32767;
set &inds end=last; set &inds end=last;
call symputx(cats('joburi',_n_),substr(uri,1,55)!!'/state','l'); call symputx(cats('joburi',_n_),substr(uri,1,55),'l');
call symputx(cats('jobname',_n_),_program,'l'); call symputx(cats('jobname',_n_),_program,'l');
call symputx(cats('jobparams',_n_),jobparams,'l'); call symputx(cats('jobparams',_n_),jobparams,'l');
if last then call symputx('uricnt',_n_,'l'); if last then call symputx('uricnt',_n_,'l');
@@ -14299,7 +14307,7 @@ run;
%let fname0=%mf_getuniquefileref(); %let fname0=%mf_getuniquefileref();
data &outds; data &outds;
format _program uri $128. state $32. timestamp datetime19. jobparams $32767.; format _program uri $128. state $32. stateDetails $32. timestamp datetime19. jobparams $32767.;
stop; stop;
run; run;
@@ -14307,7 +14315,7 @@ run;
%do i=1 %to &uricnt; %do i=1 %to &uricnt;
%if "&&joburi&i" ne "0" %then %do; %if "&&joburi&i" ne "0" %then %do;
proc http method='GET' out=&fname0 &oauth_bearer url="&base_uri/&&joburi&i"; proc http method='GET' out=&fname0 &oauth_bearer url="&base_uri/&&joburi&i";
headers "Accept"="text/plain" headers "Accept"="application/json"
%if &grant_type=authorization_code %then %do; %if &grant_type=authorization_code %then %do;
"Authorization"="Bearer &&&access_token_var" "Authorization"="Bearer &&&access_token_var"
%end; ; %end; ;
@@ -14321,12 +14329,20 @@ run;
%end; %end;
%let status=notset; %let status=notset;
%local libref1;
%let libref1=%mf_getuniquelibref();
libname &libref1 json fileref=&fname0;
data _null_; data _null_;
infile &fname0; length state stateDetails $32;
input; set &libref1..root;
call symputx('status',_infile_,'l'); call symputx('status',state,'l');
call symputx('stateDetails',stateDetails,'l');
run; run;
libname &libref1 clear;
%if &status=completed or &status=failed or &status=canceled %then %do; %if &status=completed or &status=failed or &status=canceled %then %do;
%local plainuri; %local plainuri;
%let plainuri=%substr(&&joburi&i,1,55); %let plainuri=%substr(&&joburi&i,1,55);
@@ -14335,6 +14351,7 @@ run;
_program="&&jobname&i", _program="&&jobname&i",
uri="&plainuri", uri="&plainuri",
state="&status", state="&status",
stateDetails=symget("stateDetails"),
timestamp=datetime(), timestamp=datetime(),
jobparams=symget("jobparams&i"); jobparams=symget("jobparams&i");
%let joburi&i=0; /* do not re-check */ %let joburi&i=0; /* do not re-check */
@@ -14353,6 +14370,16 @@ run;
,msg=%str(status &status not expected!!) ,msg=%str(status &status not expected!!)
) )
%end; %end;
%if (&raise_err) %then %do;
%if (&status = canceled or &status = failed or %length(&stateDetails)>0) %then %do;
%if ("&stateDetails" = "%str(war)ning") %then %let SYSCC=4;
%else %let SYSCC=5;
%put %str(ERR)OR: Job &&jobname&i. did not complete successfully. &stateDetails;
%return;
%end;
%end;
%end; %end;
%if &i=&uricnt %then %do; %if &i=&uricnt %then %do;
%local goback; %local goback;

View File

@@ -1,11 +1,11 @@
/** /**
@file @file
@brief Creates a Unique ID based on system time in a friendly format @brief Creates a unique ID based on system time in friendly format
@details format = YYYYMMDD_HHMMSSmmm_<sysjobid>_<3randomDigits> @details format = YYYYMMDD_HHMMSSmmm_<sysjobid>_<3randomDigits>
%put %mf_uid(); %put %mf_uid();
@version 9.2 @version 9.3
@author Allan Bowe @author Allan Bowe
**/ **/
@@ -14,7 +14,7 @@
)/*/STORE SOURCE*/; )/*/STORE SOURCE*/;
%local today now; %local today now;
%let today=%sysfunc(today(),yymmddn8.); %let today=%sysfunc(today(),yymmddn8.);
%let now=%sysfunc(compress(%sysfunc(time(),time12.3),:.)); %let now=%sysfunc(compress(%sysfunc(time(),tod12.3),:.));
&today._&now._&sysjobid._%sysevalf(%sysfunc(ranuni(0))*999,CEIL) &today._&now._&sysjobid._%sysevalf(%sysfunc(ranuni(0))*999,CEIL)