Macros for SAS Application Developers
https://github.com/sasjs/core
mv_jobwaitfor.sas File Reference

Takes a table of running jobs and waits for ANY/ALL of them to complete. More...

Go to the source code of this file.

Detailed Description

Will poll /jobs/{jobId}/state at set intervals until ANY or ALL jobs are completed. Completion is determined by reference to the returned state, as per the following table:

state Wait? Notes
idle yes We assume processing will continue. Beware of idle sessions with no code submitted!
pending yes Job is preparing to run
running yes Job is running
canceled no Job was cancelled
completed no Job finished - does not mean it was successful. Check stateDetails
failed no Job failed to execute, could be a problem when calling the apis

Example

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, as a web service):

filename ft15f001 temp;
parmcards4;
  data ;
    rand=ranuni(0)*1000000;
    do x=1 to rand;
      y=rand*x;
      output;
    end;
  run;
;;;;
%mv_createwebservice(path=/Public/temp,name=demo)

Then, execute the job,multiple times, and wait for them all to finish:

%mv_jobexecute(path=/Public/temp,name=demo,outds=work.ds1)
%mv_jobexecute(path=/Public/temp,name=demo,outds=work.ds2)
%mv_jobexecute(path=/Public/temp,name=demo,outds=work.ds3)
%mv_jobexecute(path=/Public/temp,name=demo,outds=work.ds4)

data work.jobs;
  set work.ds1 work.ds2 work.ds3 work.ds4;
  where method='GET' and rel='state';
run;

%mv_jobwaitfor(ALL,inds=work.jobs,outds=work.jobstates)

Delete the job:

%mv_deletejes(path=/Public/temp,name=demo)
Parameters
[in]access_token_var=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.  Default option.
- sas_services - will use oauth_bearer=sas_services
[in]action=EitherALL (to wait for every job) or ANY (if one job completes, processing will continue). Default=ALL.
[in]inds=The input dataset containing the list of job uris, in the following format: /jobExecution/jobs/&JOBID./state and the corresponding job name. The uri should be in a uri variable, and the job path/name should be in a _program variable.
[in]raise_err=0Set to 1 to raise SYSCC when a job does not complete succcessfully
[in]mdebug=set to 1 to enable DEBUG messages
[out]outds=The output dataset containing the list of states by job (default=work.mv_jobexecute)
[out]outref=A fileref to which the spawned job logs should be appended.
Version
VIYA V.03.04
Author
Allan Bowe, source: https://github.com/sasjs/core

Dependencies

Definition in file mv_jobwaitfor.sas.