Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mv_getjobstate.sas File Reference

Extract the status from a running SAS Viya job. More...

Go to the source code of this file.

Detailed Description

Extracts the status from a running job and appends it to an output dataset with the following structure:

| uri                                                           | state   | timestamp          |
|---------------------------------------------------------------|---------|--------------------|
| /jobExecution/jobs/5cebd840-2063-42c1-be0c-421ec3e1c175/state | running | 15JAN2021:12:35:08 |

To query the running job, you need the URI. Sample code for achieving this is provided below.

Example

First, compile the macros:

filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
%inc mc;

Next, create a long running 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;
  data _null_;
    call sleep(5,1);
  run;
;;;;
%mv_createwebservice(path=/Public/temp,name=demo)

Execute it, grab the uri, and finally, check the job status:

%mv_jobexecute(path=/Public/temp
  ,name=demo
  ,outds=work.info
)

data _null_;
  set work.info;
  if method='GET' and rel='state';
  call symputx('uri',uri);
run;

%mv_getjobstate(uri=&uri,outds=results)

You can run this macro as part of a loop to await the final 'completed' status. The full list of status values is:

  • idle
  • pending
  • running
  • canceled
  • completed
  • failed

If you have one or more jobs that you'd like to wait for completion you can also use the mv_jobwaitfor macro.

Parameters
[in]access_token_var=(ACCESS_TOKEN) The global macro variable to contain the access token
[in]grant_type=valid values:
  • password
  • authorization_code
  • detect - will check if access_token exists, if not will use sas_services if a SASStudioV session else authorization_code.
  • sas_services - will use oauth_bearer=sas_services.
[in]uri=The uri of the running job for which to fetch the status, in the format /jobExecution/jobs/$UUID/state (unquoted).
[out]outds=The output dataset in which to APPEND the status. Three fields are appended: CHECK_TM, URI and STATE. If the dataset does not exist, it is created.
Version
VIYA V.03.04
Author
Allan Bowe, source: https://github.com/sasjs/core

SAS Macros

Definition in file mv_getjobstate.sas.