Getting a list of upcoming job executions

Rob3 (8 posts)
January 31, 2019 02:38 PM
Accepted Answer

Hi, I'm trying to create a list of all the jobs scheduled to be run in the next 24 hours. The job monitor does exactly what I want, but I'm wondering if there's any way to export that information? I notice there's a print button on the bottom of the window, but it doesn't seem to do anything when I click it & I want the list to be output as text.

 

Barring that, is there a way to accomplish this through the API, or through running SQL on the database? I was able to use the API to get all the jobs and their schedules, but what I need is a list of specific execution times rather than "Every hour on Monday, Tuesday..."

 

Thanks.

 

Bill Staff (599 posts)
January 31, 2019 03:13 PM
Accepted Answer

That button in the Job Monitor just launches the Job History Report, which doesn't work for future instances, so nothing happens if there are no past instances shown. We should rethink this so you can produce something useful from this view.

You can use one of the Job Execution Schedule reports to get a listing. The report viewer will let you export the report to CSV, XLS, etc., but the file it produces is a little messy.

To use the API, you want the GetJobExecutionTimes method. This example gets all scheduled executions for the current day and writes them to the console in CSV format:

    using (var session = Scheduler.Connect(ServerName, LoginAuthenticationType.Windows, "", ""))
    {
        using (var context = session.NewDataContext())
        {
            var parms=new  JobQueryParameters();
            
            //Add WellKnownOIDs.RootGroup to look at all jobs.
            //Alternatively, add the OIDs of specific jobs or groups you want to report on
            parms.TargetObjects.Add(WellKnownOIDs.RootGroup);
            parms.IncludeHeldJobs= IncludeExcludeType.Exclude;  //don't include held jobs in the report


            //get execution times for all of today
            var today = DateTime.Now;
            var startTime=DateTimeHandling.StartOfDay(today);
            var endTime=DateTimeHandling.EndOfDay(today);

            var runtimes=context.GetJobExecutionTimes(parms,startTime,endTime);
            
            foreach(var item in runtimes)
            {
                //each item represents a job with scheduled executions
                foreach(var runtime in item.ExecutionTimes)
                {
                    //each runtime is the date/time of the scheduled execution
                    Console.Write("\"{0}\",{1:yyyy-MM-dd HH:mm}\n", item.FullyQualifiedJobName, runtime);
                }
            }
        }

    }

 

 

Rob3 (8 posts)
March 22, 2019 01:27 PM
Accepted Answer

Bill,

 

Thanks for the code, that solution pulls the jobs exactly like we wanted. However, we ran into another issue as we started adding more jobs to the server. The job will time out when it tries to get all executions for the next week, since there are too many to grab. I'm able to use endTime=DateTimeHandling.EndOfDay(today.AddDays(5)), but if I go to 7 days I get the error ADT005166E ("Local socket timeout was '00:02:00'"). Wondering if there's a way to adjust the value of this timeout? Failing that, is there a function in the API to only get the NEXT run of each job? (I looked into GetJobExecutionTimes and its parms param but they didn't seem able to grab this information). Alternatively I thought about running GetExecutionTimes several times in a row with smaller intervals & combining the results afterward, but I'm not sure if there's a way to add the JobExecutionTimes collections GetJobExecutionTimes returns, since I still need it separated by job. Any advice on these?

 

Thanks.

Bill Staff (599 posts)
March 22, 2019 03:36 PM
Accepted Answer

If you just want to look at the next start time for each job, use DataContext.GetJobs to fetch all the jobs, then iterate through them and look at Job.Status.NextStart.

It's possible to reconfigure the socket timeout but it would be more reliable to just batch your calls. You'd need to add a little code to merge the results from your multiple calls.

How many jobs are you dealing with here? I'm curious to replicate the performance/timeout problem so we can implement some sort of solution in the future.

Rob3 (8 posts)
March 26, 2019 12:07 PM
Accepted Answer

The most I was able to get without it timing out was about 31,000 job executions (we "only" have about 700 jobs, but there are a few that run every 1/5/10 minutes)

 

Job.Status.NextStart was exactly what I needed though, thanks a bunch.

Replies are disabled for this topic.