/// <summary> /// Adds tasks to a job. /// </summary> /// <param name="tasksToAdd">The <see cref="CloudTask"/>s to add.</param> /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param> /// <param name="parallelOptions"> /// Controls the number of simultaneous parallel AddTaskCollection requests issued to the Batch service. Each AddTaskCollection request contains at most /// <see cref="Constants.MaxTasksInSingleAddTaskCollectionRequest"/> tasks in it. /// Also controls the cancellation token for the operation. /// If omitted, the default is used (see <see cref="BatchClientParallelOptions"/>.) /// </param> /// <param name="fileStagingArtifacts">An optional collection to receive information about the file staging process (see <see cref="CloudTask.FilesToStage"/>). /// An entry is added to the <see cref="ConcurrentBag{T}"/> for each set of tasks grouped for submission to the Batch service. /// Unlike single-task adds, you cannot use this parameter to customize the file staging process. /// For more information about the format of each entry, see <see cref="IFileStagingArtifact"/>.</param> /// <param name="timeout">The amount of time after which the operation times out.</param> /// <remarks> /// <para>This is a blocking operation; for a non-blocking equivalent, see <see cref="AddTaskAsync(IEnumerable{CloudTask}, BatchClientParallelOptions, ConcurrentBag{ConcurrentDictionary{Type, IFileStagingArtifact}}, TimeSpan?, IEnumerable{BatchClientBehavior})"/>.</para> /// <para>This method is not atomic; that is, it is possible for the method to start adding tasks and /// then fail. The collection of tasks to add is broken down into chunks of size at most <see cref="Constants.MaxTasksInSingleAddTaskCollectionRequest"/>, /// and an AddTaskCollection request is issued for each chunk. Requests may be issued in parallel according to /// the <paramref name="parallelOptions"/>.</para> /// <para>Issuing a large number of simultaneous requests to the Batch service can incur HTTP connection restrictions. /// If you are performing many of these operations in parallel (or have specified a large MaxDegreeOfParallelism in /// the parallelOptions) and are seeing client side timeouts (a <see cref="TaskCanceledException"/>), please see /// http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit%28v=vs.110%29.aspx .</para> /// <para>The progress of the operation in the face of errors is determined by <see cref="AddTaskCollectionResultHandler"/> behavior. /// You do not normally need to specify this behavior, as the Batch client uses a default which works in normal circumstances. /// If you do want to customize this behavior, specify an AddTaskCollectionResultHandler in the <see cref="CustomBehaviors"/> /// or <paramref name="additionalBehaviors"/> collections.</para> /// </remarks> /// <exception cref="ParallelOperationsException">Thrown if one or more requests to the Batch service fail.</exception> public void AddTask( IEnumerable <CloudTask> tasksToAdd, BatchClientParallelOptions parallelOptions = null, ConcurrentBag <ConcurrentDictionary <Type, IFileStagingArtifact> > fileStagingArtifacts = null, TimeSpan?timeout = null, IEnumerable <BatchClientBehavior> additionalBehaviors = null) { UtilitiesInternal.ThrowOnUnbound(this.propertyContainer.BindingState); Task asyncTask = this.AddTaskAsync(tasksToAdd, parallelOptions, fileStagingArtifacts, timeout, additionalBehaviors); asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors); }
/// <summary> /// Adds tasks to a job. /// </summary> /// <param name="tasksToAdd">The <see cref="CloudTask"/>s to add.</param> /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param> /// <param name="parallelOptions"> /// Controls the number of simultaneous parallel AddTaskCollection requests issued to the Batch service. Each AddTaskCollection request contains at most /// <see cref="Constants.MaxTasksInSingleAddTaskCollectionRequest"/> tasks in it. /// Also controls the cancellation token for the operation. /// If omitted, the default is used (see <see cref="BatchClientParallelOptions"/>.) /// </param> /// <param name="fileStagingArtifacts">An optional collection to receive information about the file staging process (see <see cref="CloudTask.FilesToStage"/>). /// An entry is added to the <see cref="ConcurrentBag{T}"/> for each set of tasks grouped for submission to the Batch service. /// Unlike single-task adds, you cannot use this parameter to customize the file staging process. /// For more information about the format of each entry, see <see cref="IFileStagingArtifact"/>.</param> /// <param name="timeout">The amount of time after which the operation times out.</param> /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns> /// <remarks> /// <para>The add task operation runs asynchronously.</para> /// <para>This method is not atomic; that is, it is possible for the method to start adding tasks and /// then fail. The collection of tasks to add is broken down into chunks of size at most <see cref="Constants.MaxTasksInSingleAddTaskCollectionRequest"/>, /// and an AddTaskCollection request is issued for each chunk. Requests may be issued in parallel according to /// the <paramref name="parallelOptions"/>.</para> /// <para>Issuing a large number of simultaneous requests to the Batch service can incur HTTP connection restrictions. /// If you are performing many of these operations in parallel (or have specified a large MaxDegreeOfParallelism in /// the parallelOptions) and are seeing client side timeouts (a <see cref="TaskCanceledException"/>), please see /// http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit%28v=vs.110%29.aspx .</para> /// <para>The progress of the operation in the face of errors is determined by <see cref="AddTaskCollectionResultHandler"/> behavior. /// You do not normally need to specify this behavior, as the Batch client uses a default which works in normal circumstances. /// If you do want to customize this behavior, specify an AddTaskCollectionResultHandler in the <see cref="CustomBehaviors"/> /// or <paramref name="additionalBehaviors"/> collections.</para> /// </remarks> /// <exception cref="ParallelOperationsException">Thrown if one or more requests to the Batch service fail.</exception> public async Task AddTaskAsync( IEnumerable <CloudTask> tasksToAdd, BatchClientParallelOptions parallelOptions = null, ConcurrentBag <ConcurrentDictionary <Type, IFileStagingArtifact> > fileStagingArtifacts = null, TimeSpan?timeout = null, IEnumerable <BatchClientBehavior> additionalBehaviors = null) { UtilitiesInternal.ThrowOnUnbound(this.propertyContainer.BindingState); // craft the behavior manager for this call BehaviorManager behaveMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors); Task asyncTask = this.parentBatchClient.JobOperations.AddTaskAsyncImpl(this.Id, tasksToAdd, parallelOptions, fileStagingArtifacts, timeout, behaveMgr); await asyncTask.ConfigureAwait(continueOnCapturedContext : false); }
/// <summary> /// Creates the AddTasks workflow manager with the specified arguments. /// </summary> /// <param name="jobOperations"></param> /// <param name="jobId"></param> /// <param name="parallelOptions">The parallel options associated with this operation. If this is null, the default is used.</param> /// <param name="fileStagingArtifacts">File staging artifacts associated with this operation. If the customer does not set this, it is unviewable by them.</param> /// <param name="bhMgr">The behavior manager.</param> internal AddTasksWorkflowManager( JobOperations jobOperations, string jobId, BatchClientParallelOptions parallelOptions, ConcurrentBag <ConcurrentDictionary <Type, IFileStagingArtifact> > fileStagingArtifacts, BehaviorManager bhMgr) { // // Setup some defaults for the parameters if they were null // if (parallelOptions == null) { parallelOptions = new BatchClientParallelOptions(); } // // Set up the data structures associated with this workflow // this._jobOperations = jobOperations; this._jobId = jobId; this._remainingTasksToAdd = new ConcurrentQueue <TrackedCloudTask>(); this._addTaskResultHandlerCollection = new List <Func <AddTaskResult, CancellationToken, AddTaskResultStatus> >(); this._parallelOptions = parallelOptions; this._pendingAsyncOperations = new List <Task>(); this._customerVisibleFileStagingArtifacts = fileStagingArtifacts ?? new ConcurrentBag <ConcurrentDictionary <Type, IFileStagingArtifact> >(); this._behaviorManager = bhMgr; this._maxTasks = Constants.MaxTasksInSingleAddTaskCollectionRequest; this._hasRun = HasNotRun; //Has not run by default //Read the behavior manager and populate the collection List <AddTaskCollectionResultHandler> behaviorList = this._behaviorManager.GetBehaviors <AddTaskCollectionResultHandler>(); foreach (AddTaskCollectionResultHandler handler in behaviorList) { this._addTaskResultHandlerCollection.Add(handler.ResultHandler); } //Validation that there is a handler for AddTaskResult if (this._addTaskResultHandlerCollection.Count == 0) { throw new BatchClientException( string.Format(CultureInfo.InvariantCulture, BatchErrorMessages.GeneralBehaviorMissing, typeof(AddTaskCollectionResultHandler))); } }