Gets or sets a value indicating whether to cancel other tasks on this Job if another Task fails.
Namespace: AGI.Parallel.Client
Assembly: AGI.Parallel.Client (in AGI.Parallel.Client.dll) Version: 1.2.0.275 (1.2.0.275)

Syntax

C#
public bool CancelOnTaskFailure { get; set; }
Visual Basic
Public Property CancelOnTaskFailure As Boolean
        Get
        Set

Field Value

true if tasks of this job will be canceled when any task of this job fails; otherwise, false.

Implements

IJob..::..CancelOnTaskFailure

Remarks

CancelOnTaskFailure ensures that a task does not remain in the coordinator's task queue if the task fails. This is useful for jobs which are considered logically successful if all the tasks are successful. That is, if a single task fails, then the whole job should be considered a failure.

Examples

  Copy imageCopy
using System;
using System.Threading;
using AGI.Parallel.Client;
using AGI.Parallel.Infrastructure;

namespace CodeSamples
{
    class Program
    {
        static void Main(string[] args)
        {
            using (IJobScheduler scheduler = new ClusterJobScheduler("localhost"))
            {
                scheduler.Connect();
                Job job = scheduler.CreateJob();
                job.CancelOnTaskFailure = true;

                for (int i = 0; i < 3; ++i)
                {
                    job.AddTask(new WaitTask());
                }

                // This task will fail. Watch as the other tasks are canceled.
                job.AddTask(new FailureTask());

                job.Submit();
                job.WaitUntilDone();

                for (int i = 0; i < 4; ++i)
                {
                    Console.WriteLine("Task #{0} Status {1}", i + 1, job.Tasks[i].TaskStatus);
                }
            }

            /*
             * The output of the application should resemble:
             * Task #1 Status Canceled
             * Task #2 Status Canceled
             * Task #3 Status Canceled
             * Task #4 Status Failed
             */
        }

        [Serializable]
        class WaitTask : Task
        {
            public override void Execute()
            {
                for (int i = 0; i < 100; ++i)
                {
                    Thread.Sleep(100);
                }
            }
        }

        [Serializable]
        class FailureTask : Task
        {
            public override void Execute()
            {
                Thread.Sleep(100);
                throw new Exception("Failure");
            }
        }
    }
}

See Also