<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to get details about scheduling times in Administration and Deployment</title>
    <link>https://communities.sas.com/t5/Administration-and-Deployment/How-to-get-details-about-scheduling-times/m-p/784335#M23491</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P class=""&gt;Do you know if there is a way to retrieve details about how a job is scheduled while running it?&lt;/P&gt;
&lt;P class=""&gt;I have some jobs scheduled to run once per day and some jobs scheduled per hour and need to take different actions depending on what. For example, if Job A runs once per hour I would want it to meet a condition different from jobs scheduled once per day.&lt;/P&gt;
&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=""&gt;We have Sas Viya 3.5 running on Linux Rhel 7.&lt;/P&gt;
&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=""&gt;Regards Mattias&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Dec 2021 20:04:29 GMT</pubDate>
    <dc:creator>viswmmo</dc:creator>
    <dc:date>2021-12-06T20:04:29Z</dc:date>
    <item>
      <title>How to get details about scheduling times</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/How-to-get-details-about-scheduling-times/m-p/784335#M23491</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P class=""&gt;Do you know if there is a way to retrieve details about how a job is scheduled while running it?&lt;/P&gt;
&lt;P class=""&gt;I have some jobs scheduled to run once per day and some jobs scheduled per hour and need to take different actions depending on what. For example, if Job A runs once per hour I would want it to meet a condition different from jobs scheduled once per day.&lt;/P&gt;
&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=""&gt;We have Sas Viya 3.5 running on Linux Rhel 7.&lt;/P&gt;
&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=""&gt;Regards Mattias&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 20:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/How-to-get-details-about-scheduling-times/m-p/784335#M23491</guid>
      <dc:creator>viswmmo</dc:creator>
      <dc:date>2021-12-06T20:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to getting details about scheduling times</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/How-to-get-details-about-scheduling-times/m-p/784365#M23495</link>
      <description>Do you mean when job x is running have it check it's own schedule?&lt;BR /&gt;&lt;BR /&gt;You could call the endpoint defined in the macro variable SYS_JES_JOB_URI which would give you the associated job definition URI, which you could tie to the results of /scheduler/jobs requests listing to pull any associated triggers for the job.</description>
      <pubDate>Mon, 06 Dec 2021 19:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/How-to-get-details-about-scheduling-times/m-p/784365#M23495</guid>
      <dc:creator>gwootton</dc:creator>
      <dc:date>2021-12-06T19:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to getting details about scheduling times</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/How-to-get-details-about-scheduling-times/m-p/784374#M23496</link>
      <description>&lt;P&gt;Something like this (would probably need to build in a next relation check for the scheduler/jobs call), this sets the macro variable "retype" to whatever the reoccurrence type is (daily, weekly, etc):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let baseurl=%sysget(SAS_SERVICES_URL);

filename headout;
filename headout temp;
filename resp;
filename resp temp;

proc http url="&amp;amp;baseurl&amp;amp;SYS_JES_JOB_URI" oauth_bearer=sas_services out=resp headerout=headout HEADEROUT_OVERWRITE;
    headers "Accept"="application/json";
run;

libname resp;
libname resp json fileref=resp;

proc sql noprint;
select id into:id from resp.jobrequest ;
quit;


proc http oauth_bearer=sas_services url="&amp;amp;baseurl/scheduler/jobs" out=resp headerout=headout HEADEROUT_OVERWRITE;
    headers "Accept"="application/json";
run;

libname resp;
libname resp json fileref=resp;

proc sql noprint;
	select ordinal_items into:ordinal from resp.items_request where uri="/jobExecution/jobRequests/&amp;amp;id/jobs";
quit;

proc sql noprint;
	select b.type into:retype from resp.items_triggers as a,resp.triggers_recurrence as b where a.ordinal_items=&amp;amp;ordinal and a.ordinal_triggers=b.ordinal_triggers;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 19:45:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/How-to-get-details-about-scheduling-times/m-p/784374#M23496</guid>
      <dc:creator>gwootton</dc:creator>
      <dc:date>2021-12-06T19:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to getting details about scheduling times</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/How-to-get-details-about-scheduling-times/m-p/785203#M23505</link>
      <description>&lt;P&gt;Hi, thanks for the code. I'm just having some problems with the Proc http:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc http oauth_bearer=sas_services url="&amp;amp;baseurl/scheduler/jobs" out=resp headerout=headout HEADEROUT_OVERWRITE;&lt;BR /&gt;headers "Accept"="application/json";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It returns 10 obs in resp.items_request but among them are not the job I am searching for (&amp;amp;id).&lt;BR /&gt;So this next step returns 0 obs where url=/jobExecution/jobRequests/&amp;amp;id/jobs&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;proc sql noprint;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; select ordinal_items into:ordinal from resp.items_request where&amp;nbsp; &amp;nbsp; &amp;nbsp; uri="/jobExecution/jobRequests/&amp;amp;id/jobs";&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to filter proc http to return items just for job identified as &amp;amp;id?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 16:45:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/How-to-get-details-about-scheduling-times/m-p/785203#M23505</guid>
      <dc:creator>viswmmo</dc:creator>
      <dc:date>2021-12-09T16:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to getting details about scheduling times</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/How-to-get-details-about-scheduling-times/m-p/785217#M23506</link>
      <description>&lt;P&gt;I didn't include a loop in my code to check keep going through all the scheduler job results. The below code has such a loop:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let baseurl=%sysget(SAS_SERVICES_URL);

filename headout;
filename headout temp;
filename resp;
filename resp temp;

/* Define a macro */
%macro getsched();

	/* Call the URL for this job to get its jobRequest ID */
	proc http url="&amp;amp;baseurl&amp;amp;SYS_JES_JOB_URI" oauth_bearer=sas_services out=resp headerout=headout HEADEROUT_OVERWRITE;
	    headers "Accept"="application/json";
	run;
	
	/* Read in the response using the JSON libname engine. */
	libname resp;
	libname resp json fileref=resp;
	
	/* Pull the ID into the macro variable "id" */
	proc sql noprint;
	select id into:id from resp.jobrequest ;
	quit;

	/* Call /scheduler/jobs to get all the scheduled jobs. */	
	proc http oauth_bearer=sas_services url="&amp;amp;baseurl/scheduler/jobs" out=resp headerout=headout HEADEROUT_OVERWRITE;
	    headers "Accept"="application/json";
	run;
	
	/* Read in the response using the JSON libname engine. */
	libname resp;
	libname resp json fileref=resp;
	
	/* Read in the "next" URL for scheduler if present, this means we might have to keep looking for the jobRequest */
	%let next=;
	data _null_;
	    set resp.links;
	    if rel="next" then call execute('%let next=%nrstr('||href||')');
	run;
	
	/* Try to find the ordinal for the job request in the list of schedules. */
	proc sql noprint;
		select ordinal_items into:ordinal from resp.items_request where uri="/jobExecution/jobRequests/&amp;amp;id/jobs";
	quit;
	
	/* If we find it, then create a macro variable "retype" that gives us the type of the reoccurrence (daily,hourly,etc) */
	%if %symexist(ordinal) %then %do;
		proc sql noprint;
			select b.type into:retype from resp.items_triggers as a,resp.triggers_recurrence as b where a.ordinal_items=&amp;amp;ordinal and a.ordinal_triggers=b.ordinal_triggers;
		quit;
	%end;
	
	/* If not, we need to check the next URL, or stop if there isn't one. */
	%else %do %while (%length(&amp;amp;next)&amp;gt;0);;
	
		/* Call the next URL we pulled earlier. */
		proc http oauth_bearer=sas_services url="&amp;amp;baseurl&amp;amp;next" out=resp headerout=headout HEADEROUT_OVERWRITE;
		    headers "Accept"="application/json";
		run;
		
		/* Read in the response using the JSON libname engine. */
		libname resp;
		libname resp json fileref=resp;	
	
		/* Empty the next variable from before. */
		%let next=;
		
		/* Try to find the ordinal in this response. */
		proc sql noprint;
			select ordinal_items into:ordinal from resp.items_request where uri="/jobExecution/jobRequests/&amp;amp;id/jobs";
		quit;
		
		/* If it exists, write the retype variable. */
		%if %symexist(ordinal) %then %do;
			proc sql noprint;
				select b.type into:retype from resp.items_triggers as a,resp.triggers_recurrence as b where a.ordinal_items=&amp;amp;ordinal and a.ordinal_triggers=b.ordinal_triggers;
			quit;
		%end;
		/* If not, read the next URL to pull the next set of schedules and continue the loop. */
		%else %do;
		data _null_;
		    set resp.links;
		    if rel="next" then call execute('%let next=%nrstr('||href||')');
		run;
		%end;
		
	%end;

	%if %symexist(retype) %then %put NOTE: Reoccurence type: %trim(&amp;amp;retype);
	%else %put WARN: No reoccurence set. This job is not scheduled.;

%mend getsched;
%getsched();
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Dec 2021 17:41:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/How-to-get-details-about-scheduling-times/m-p/785217#M23506</guid>
      <dc:creator>gwootton</dc:creator>
      <dc:date>2021-12-09T17:41:31Z</dc:date>
    </item>
  </channel>
</rss>

