Depending on what you are doing, there may be better ways to get this data than through the API.
First, there's a Job Accounting report built in to the Console, which gives you instance counts and processing times.
If you need to integrate this into your own system, it's probably going to be more efficient to query the adTempus database directly rather than going through the API. This query will get you the total instances for each job in a given date range:
select g.fullname as GroupName,j.name as JobName,count(*) as TotalInstances |
from job j join executionhistoryitem ehi on j.oid=ehi.joboid |
join jobgroup g on j.jobgroup=g.oid |
where ehi.executionstart>='2009-03-01' and ehi.executionfinish<'2009-04-01' |
group by g.fullname,j.name |
This just gives you the total instances, but you could also easily sum up the execution times if you want that information.
You can accomplish what you want using the API, but the API isn't set up for aggregating data, so it takes some work and involves retrieving a lot of data. The following VB code shows how you could do this. It retrieves all jobs, then iterates through them.
For each job it fetches the history for the date range you're interested in. Here's where things get inefficient. If you only care about the total number of instances, you can get a record count without retrieving them all (Option A in the code). However, if you want to get anything else (like, say, summing up the total execution time), you would have to retrieve each instance and look at it, which can be slow if there's a lot of history to look at. To use this approach, comment out Option A and uncomment Option B below.
The code assumes you already have a connection. See this example if you need the code for that.
'this method retrieves all jobs from the adTempus server, |
'then retrieves the history for the last 30 days for each job. |
Private Sub ProcessJobRuns(ByVal scheduler As IScheduler) |
Dim startDateTime As DateTime |
Dim endDateTime As DateTime |
Dim jobs As IADTObjects |
Dim job As IJob |
|
endDateTime = DateTime.Now |
startDateTime = endDateTime.AddDays(-30) |
|
'get all jobs |
jobs = scheduler.GetObjectsForClass(ClassIDEnum.CID_Job) |
|
'process each job |
For Each job In jobs |
ProcessJobHistory(scheduler, job, startDateTime, endDateTime) |
Next |
|
|
End Sub |
|
Private Sub ProcessJobHistory(ByVal scheduler As IScheduler, ByVal job As IJob, ByVal startDate As DateTime, ByVal endDate As DateTime) |
Dim filter As New JobHistoryFilter |
Dim instances As IADTObjects |
Dim recordCount As Integer |
|
filter.AddJobOID(job.OID) |
filter.EndDate = endDate |
filter.StartDate = startDate |
|
'Option A: if you only want the count of instances, use this: |
|
scheduler.GetObjectsWhere(CType(filter, IObjectRequestFilter), 1, True, recordCount) |
|
'this will only fetch one instance from the database, but the recordCount will indicate |
'the total number of instances in the date range. |
|
|
|
'Option B: if you want to process each instance (e.g., to get execution times), use the following line instead. |
'it will get all instances for the time period. |
|
'instances = scheduler.GetObjectsWhere(CType(filter, IObjectRequestFilter), 0, True, recordCount) |
|
'you can then iterate through the instances. |
|
End Sub |
|