|
Macros for SAS Application Developers
https://github.com/sasjs/core |
Extract the log from a completed SAS Viya Job. More...
Go to the source code of this file.
Extracts log from a Viya job and writes it out to a fileref.
To query the job, you need the URI. Sample code for achieving this is provided below.
%* First, compile the macros;
filename mc url
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
%inc mc;
%* Next, create a job (in this case, a web service);
filename ft15f001 temp;
parmcards4;
data ;
rand=ranuni(0)*1000;
do x=1 to rand;
y=rand*4;
output;
end;
run;
proc sort data=&syslast
by descending y;
run;
;;;;
%mv_createwebservice(path=/Public/temp,name=demo)
%* Execute it;
%mv_jobexecute(path=/Public/temp
,name=demo
,outds=work.info
)
%* Wait for it to finish;
data work.info;
set work.info;
where method='GET' and rel='state';
run;
%mv_jobwaitfor(ALL,inds=work.info,outds=work.jobstates)
%* and grab the uri;
data _null_;
set work.jobstates;
call symputx('uri',uri);
run;
%* Finally, fetch the log;
%mv_getjoblog(uri=&uri,outref=mylog)
This macro is used by the mv_jobwaitfor.sas macro, which is generally a more convenient way to wait for the job to finish before fetching the log.
If the remote session calls endsas then it is not possible to get the log from the provided uri, and so the log from the parent session is fetched instead. This happens for a 400 response, eg below:
ErrorResponse[version=2,status=400,err=5113,id=,message=The session requested is currently in a failed or stopped state.,detail=[path: /compute/sessions/LONGURI-ses0006/jobs/LONGURI/log/content, traceId: 63 51aa617d01fd2b],remediation=Correct the errors in the session request, and create a new session.,targetUri=<null>,errors=[],links=[]]
| [in] | access_token_var= | The global macro variable to contain the access token |
| [in] | mdebug= | (0) Set to 1 to enable DEBUG messages |
| [in] | grant_type= | valid values:
|
| [in] | uri= | The uri of the running job for which to fetch the status, in the format /jobExecution/jobs/$UUID (unquoted). |
| [out] | outref= | The output fileref to which to APPEND the log (is always appended). |
Definition in file mv_getjoblog.sas.