Skip to content

Instantly share code, notes, and snippets.

@arcanadev
Last active May 7, 2021 21:15
Show Gist options
  • Save arcanadev/f9086f7601109e0fe1220ca46fc46a06 to your computer and use it in GitHub Desktop.
Save arcanadev/f9086f7601109e0fe1220ca46fc46a06 to your computer and use it in GitHub Desktop.
Delete a job that may be running #adtempus #api #version4

This sample demonstrates how to delete a job through the API.

If you attempt to delete a job that has running instances, you will get an exception. Before deleting a job you should terminate all running instances, as shown below.

public void DeleteJob(Job job)
{
// if you want to make sure the job doesn't get executed while you're waiting for executing instances to complete, put it on hold
job.UpdateHoldType(HoldType.DisableAll, MissedJobCheckOptions.NoCheck);
// get the latest status for the job and check to see if there are running instances
var status = job.GetStatus(true);
if (status.ActiveInstances > 0)
{
// if there are running instances, prompt for confirmation before terminating if appropriate
// if you want to continue deleting, terminate all active instances, and then wait until they have finished
job.Terminate(TerminationOptions.TerminateAllInstances, 0);
// refresh the status from the server once per second until all running jobs have been terminated
while (status.ActiveInstances > 0)
{
System.Threading.Thread.Sleep(timespan.FromSeconds(1));
status = job.GetStatus(true);
}
}
// then you can delete the job
job.Delete();
}
sub DeleteJob(job As Job)
'if you want to make sure the job doesn't get executed while you're waiting for executing instances to complete, put it on hold
job.UpdateHoldType(HoldType.DisableAll, MissedJobCheckOptions.NoCheck)
'get the latest status for the job and check to see if there are running instances
Dim status=job.GetStatus(true)
If status.ActiveInstances > 0 Then
'if there are running instances, prompt for confirmation before terminating if appropriate
'if you want to continue deleting, terminate all active instances, and then wait until they have finished
job.Terminate(TerminationOptions.TerminateAllInstances, 0)
'refresh the status from the server once per second until all running jobs have been terminated
While status.ActiveInstances>0
System.Threading.Thread.Sleep(timespan.FromSeconds(1))
status=job.GetStatus(True)
End While
End If
'then you can delete the job
job.Delete()
End sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment