Retrieve all Jobs in AdTempus 4

User5099 (22 posts)
May 8, 2017 08:02 AM
Accepted Answer

Hi Bill,

I migrated from AdTempus 3 to 4.4. Could you please help me know, in order to retrieve all jobs and loop through them do I need to retrieve ADTObjects and do explicit type casting like in Adtempus 3 or can I directly use GetJobs() (Member of DataContext) method directly?. Could you also please provide an example for the same.

 

 

Bill Staff (601 posts)
May 8, 2017 09:22 AM
Accepted Answer

Yes, you would use GetJobs. There is no casting to be done because it returns a collection of Job objects.

For the fastest fetch you want to use the ObjectFecthOptions.StubsOnly option as shown below. This tells the server to return only skeletal information for the job rather than the full object (which would include all its steps, conditions, triggers, etc.). If you plan to access any of those, you should do a full fetch so everything is returned.

The FullyQualifiedName property returns the job name plus the full name of the group the job is in.


	using (var session = Scheduler.Connect(ServerName, LoginAuthenticationType.Windows, "", ""))
	{
		using (var context = session.NewDataContext())
		{
			bool restartPaging=false;
			var jobs = context.GetJobs("*", ObjectFetchOptions.StubsOnly, 0, ref restartPaging);
			foreach(var job in jobs)
			{
				var status=job.GetStatus(false);
				var groupName=job.Group.FullyQualifiedName;
				var queueName=job.Queue.Name;
				Debug.WriteLine(job.FullyQualifiedName + ": " + status.StatusDescription);
			}
		}
	}

 

User5099 (22 posts)
May 8, 2017 09:31 AM
Accepted Answer
Thanks a lot Bill.
User5099 (22 posts)
May 9, 2017 07:31 AM
Accepted Answer

Hi Bill,

I have to get Execution History of each Job. I saw there is a method Job.getExecutionHistory(InstanceQueryParameters parameters). I was not able to figure out what is an InstanceQueryParameters and how its used. Could you please help me know what are InstanceQueryParameters  and how its used?

Bill Staff (601 posts)
May 9, 2017 03:29 PM
Accepted Answer

The InstanceQueryParameters class is documented. This is how you tell adTempus which instances to return.

If you are calling GetExecutionHistory for a single job, you want something like this:

	var options=new InstanceQueryParameters();
	options.SortOrder.Add( ArcanaDevelopment.adTempus.Shared.InstanceQueryParameters.HistorySortOrder.RecordIDDescending);
	options.PageSize=20;	//get most recent 20 instances
	options.FetchOptions= ObjectFetchOptions.StubsOnly;
	
	var history=job.GetExecutionHistory(options);

This will return the most recent 20 instances of the job. If you need more you can adjust the PageSize and/or play around with paging. Depending on what you're going to do with the history once you get it, setting the FetchOptions as shown may improve performance.

Replies are disabled for this topic.