/// <summary>
        /// The default result handler for the <see cref="AddTaskCollectionResultHandler"/> behavior. This handler
        /// treats success and 'TaskExists' errors as successful, retries server errors (HTTP 5xx), and throws
        /// <see cref="AddTaskCollectionTerminatedException"/> on client error (HTTP 4xx).
        /// </summary>
        /// <param name="addTaskResult">The result of a single Add Task operation.</param>
        /// <param name="cancellationToken">The cancellation token associated with the AddTaskCollection operation.</param>
        /// <returns>An <see cref="AddTaskResultStatus"/> which indicates whether the <paramref name="addTaskResult"/>
        /// is classified as a success or as requiring a retry.</returns>
        public static AddTaskResultStatus DefaultAddTaskCollectionResultHandler(AddTaskResult addTaskResult, CancellationToken cancellationToken)
        {
            if (addTaskResult == null)
            {
                throw new ArgumentNullException("addTaskResult");
            }

            AddTaskResultStatus status = AddTaskResultStatus.Success;

            if (addTaskResult.Error != null)
            {
                //Check status code
                if (addTaskResult.Status == AddTaskStatus.ServerError)
                {
                    status = AddTaskResultStatus.Retry;
                }
                else if (addTaskResult.Status == AddTaskStatus.ClientError && addTaskResult.Error.Code == BatchErrorCodeStrings.TaskExists)
                {
                    status = AddTaskResultStatus.Success; //Count TaskExists as a success always
                }
                else
                {
                    //Anything else is a failure -- abort the work flow
                    throw new AddTaskCollectionTerminatedException(addTaskResult);
                }
            }
            return(status);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Processes a set AddTaskResults from the protocol and groups them according to the results of the AddTaskResultHandler
        /// </summary>
        /// <param name="addTaskResults"></param>
        /// <param name="taskMap">Dictionary of task name to task object instance for the specific protocol response.</param>
        private void ProcessProtocolAddTaskResults(
            IEnumerable <Protocol.Models.TaskAddResult> addTaskResults,
            IReadOnlyDictionary <string, TrackedCloudTask> taskMap)
        {
            foreach (Protocol.Models.TaskAddResult protoAddTaskResult in addTaskResults)
            {
                string           taskId      = protoAddTaskResult.TaskId;
                TrackedCloudTask trackedTask = taskMap[taskId];

                AddTaskResult omResult = new AddTaskResult(trackedTask.Task, trackedTask.RetryCount, protoAddTaskResult);

                //We know that there must be at least one AddTaskResultHandler so the below ForEach will always be called
                //at least once.
                AddTaskResultStatus status = AddTaskResultStatus.Success; //The default is success to avoid infinite retry

                //Call the customer defined result handler
                foreach (var resultHandlerFunction in this._addTaskResultHandlerCollection)
                {
                    status = resultHandlerFunction(omResult, this._parallelOptions.CancellationToken);
                }

                if (status == AddTaskResultStatus.Retry)
                {
                    //Increment retry count
                    trackedTask.IncrementRetryCount();

                    //TODO: There is nothing stopping the user from marking all tasks as Retry and never exiting this work flow...
                    //TODO: In that case maybe we should forcibly abort them after some # of attempts?
                    this._remainingTasksToAdd.Enqueue(trackedTask);
                }
            }
        }
 internal PSAddTaskResult(Microsoft.Azure.Batch.AddTaskResult omObject)
 {
     if ((omObject == null))
     {
         throw new System.ArgumentNullException("omObject");
     }
     this.omObject = omObject;
 }
Exemplo n.º 4
0
 private static string GenerateMessageString(AddTaskResult result)
 {
     return(string.Format(BatchErrorMessages.AddTaskCollectionTerminated, result));
 }
Exemplo n.º 5
0
 internal AddTaskCollectionTerminatedException(AddTaskResult result, Exception inner = null) :
     base(GenerateMessageString(result), inner)
 {
     this.AddTaskResult = result;
 }
 private static string GenerateMessageString(AddTaskResult result)
 {
     return(string.Format(System.Globalization.CultureInfo.InvariantCulture, BatchErrorMessages.AddTaskCollectionTerminated, result));
 }