Gets or sets a value indicating whether to fail all tasks immediately of this Job if the precondition is not satisfied.
Namespace: AGI.Parallel.Infrastructure
Assembly: AGI.Parallel.Infrastructure (in AGI.Parallel.Infrastructure.dll) Version: 1.2.0.275 (1.2.0.275)

Syntax

C#
bool FailIfPreconditionsNotSatisfied { get; set; }
Visual Basic
Property FailIfPreconditionsNotSatisfied As Boolean
        Get
        Set

Field Value

true if tasks should be canceled if precondition is not matched; otherwise, false.

Remarks

FailIfPreconditionsNotSatisfied ensures that a task does not remain in the coordinator's task queue if there are currently no agents which meet the preconditions. This is useful for applications which would rather fail fast if a job can't be run rather than wait for certain conditions to become true in the future.

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();

                // This should normally never be true. If it is true, count yourself lucky.
                job.TaskPreconditions.Add(CommonResources.AvailableCores, Operator.GreaterThan, 100);

                // Setting FailIfPreconditionsNotSatisfied to true ensures that the task fails immediately
                // if the precondition is not met. This prevents a task to be "stuck" in the task queue.
                job.FailIfPreconditionsNotSatisfied = true;

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

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

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

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

        [Serializable]
        class TaskThatRequiresPrecondition : Task
        {
            public override void Execute()
            {
            }
        }
    }
}

See Also