Click or drag to resize

JobFailIfPreconditionsNotSatisfied Property

Gets or sets a value indicating whether to fail all tasks immediately of this Job if the precondition is not satisfied.

Namespace:  AGI.Parallel.Client
Assembly:  AGI.Parallel.Client (in AGI.Parallel.Client.dll) Version: 2.9.0.1601 (2.9.0.1601)
Syntax
public bool FailIfPreconditionsNotSatisfied { get; set; }

Property Value

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

Implements

IJobFailIfPreconditionsNotSatisfied
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
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

STK Parallel Computing Server 2.9 API for .NET