Holding jobs and waiting until nothing is running

Janco (9 posts)
May 28, 2014 01:44 AM
Accepted Answer

The following applies to adTempus 4: 

As part of our regular deployments, we need to ensure that no adTempus jobs are running, and won't be started until deployment is complete.

Our current strategy is to hold an entire job group, and then to continually check the status of all jobs until nothing is running before continuing. I have noticed that jobs that are in a "WaitingForPreviousInstance" state will start once the previous instance has completed, even if the job group is held. So it seems I would need to take this into account when waiting until no jobs are running.

What other states do we need to keep in mind when doing this, or is there potentially a better strategy that I'm not aware of?

Bill Staff (599 posts)
May 28, 2014 06:57 AM
Accepted Answer

Your approach is good--I can't think of a better way.

The ArcanaDevelopment.adTempus.Shared.JobStatusHelpers static class has lists of JobState values for various categories (e.g., all JobState values that indicate an active instance). (Unfortunately there's no detailed documentation for this class at the moment; hopefully we can get that updated for you shortly.)

You want to look for anything that has a status that's included in ActiveStatuses or WaitingStatuses. Write your code to get the lists from JobStatusHelpers rather than hard-coding a list of values; that way you won't need to change your code if we add or reclassify values.

ActiveStatuses includes:

  • JobState.Starting
  • JobState.Running
  • JobState.Killing
  • JobState.Aborting
  • JobState.WaitingForCondition
  • JobState.WaitingForResource
  • JobState.Queued
  • JobState.AgentQueued
  • JobState.AgentDispatched

WaitingStatuses includes:

  • JobState.WaitingForCondition
  • JobState.WaitingForResource
  • JobState.WaitingForPreviousInstance
  • JobState.WaitingForRestart
  • JobState.Queued
  • JobState.AgentQueued

You can use DataContext.GetJobHistory to fetch the instances, by setting the InstanceQueryParameters.Statuses to the list of statuses you want to query for (i.e., the combination of ActiveStatuses and WaitingStatuses).

To query within a particular group, add that group's OID to InstanceQueryParameters.TargetObjects. To query for all groups, use ArcanaDevelopment.adTempus.Shared.WellKnownOIDs.RootGroup.

Once you have fetched the instances, you can use ExecutionHistoryItem.IsRunning and IsWaiting to distinguish states easily. JobStatusHelpers also has a set of methods corresponding to the ActiveStatuses, WaitingStatuses, etc.

If you want to stop those "waiting" instances from running, you can use ExecutionHistoryItem.Terminate, which will cancel their wait so they don't execute.

Note that GetJobHistory only returns instances for jobs that you have permission for, so make sure your API client is connecting under a login that has permission on all jobs; otherwise there could be active jobs that you're not seeing.

Replies are disabled for this topic.