I'm trying to cancel all the tasks in a job that are currently queued (have not run and are not running). In order to do this I'm creating a filter collection and grabbing all the Task IDs that match the filter, then finally looping through those IDs
and cancelling the individual tasks. This works fine, except for the fact that this if approach is fairly slow. So if there are a lot of tasks to cancel, sometimes the queued tasks that weren't running at the start of the loop are running by the
time I try to cancel them.
Is there any way to cancel queued tasks faster? Either at the Job level, cancel everything that is not running (let the running jobs finish). Or at the task level pass a IFilterCollection to a CancelTasks method?
Here is my existing code:
// define a filter for status
IFilterCollection filters = scheduler.CreateFilterCollection();
filters.Add(FilterOperator.Equal, PropId.Task_State, TaskState.Queued);
// define a sort order to cancel child dependent tasks before parents (task id desc)
ISortCollection sorts = scheduler.CreateSortCollection();
sorts.Add(SortProperty.SortOrder.Descending, Microsoft.Hpc.Scheduler.PropId.Task_Name);
// loop through all the tasks that are queued (not running) and cancel them
foreach (ITaskId taskId in hpcJob.GetTaskIdList(filters, sorts, true))
{
hpcJob.CancelTask(taskId, "Cancelling all queued tasks.");
}
Scott