private void OutputSchedulingError(TaskSchedulingError se) { this.testOutputHelper.WriteLine("JP Scheduling Error:"); this.testOutputHelper.WriteLine(" category: " + se.Category.ToString()); this.testOutputHelper.WriteLine(" code: " + se.Code); this.testOutputHelper.WriteLine(" details:" + ((null == se) ? " <null>" : string.Empty)); if (null != se.Details) { foreach (NameValuePair curDetail in se.Details) { this.testOutputHelper.WriteLine(" name: " + curDetail.Name + ", value: " + curDetail.Value); } } this.testOutputHelper.WriteLine(" message: " + se.Message); }
/// <summary> /// Checks for a task's success or failure, and optionally dumps the output of the task. In the case that the task hit a scheduler or execution error, /// dumps that information as well. /// </summary> /// <param name="boundTask">The task.</param> /// <param name="dumpStandardOutOnTaskSuccess">True to log the standard output file of the task even if it succeeded. False to not log anything if the task succeeded.</param> /// <returns>The string containing the standard out of the file, or null if stdout could not be gathered.</returns> public static async Task <string> CheckForTaskSuccessAsync(CloudTask boundTask, bool dumpStandardOutOnTaskSuccess) { if (boundTask.State == TaskState.Completed) { string result = null; //Check to see if the task has execution information metadata. if (boundTask.ExecutionInformation != null) { //Dump the task scheduling error if there was one. if (boundTask.ExecutionInformation.SchedulingError != null) { TaskSchedulingError schedulingError = boundTask.ExecutionInformation.SchedulingError; Console.WriteLine("Task {0} hit scheduling error.", boundTask.Id); Console.WriteLine("SchedulingError Code: {0}", schedulingError.Code); Console.WriteLine("SchedulingError Message: {0}", schedulingError.Message); Console.WriteLine("SchedulingError Category: {0}", schedulingError.Category); Console.WriteLine("SchedulingError Details:"); foreach (NameValuePair detail in schedulingError.Details) { Console.WriteLine("{0} : {1}", detail.Name, detail.Value); } throw new TextSearchException(String.Format("Task {0} failed with a scheduling error", boundTask.Id)); } //Read the content of the output files if the task exited. if (boundTask.ExecutionInformation.ExitCode.HasValue) { Console.WriteLine("Task {0} exit code: {1}", boundTask.Id, boundTask.ExecutionInformation.ExitCode); if (dumpStandardOutOnTaskSuccess && boundTask.ExecutionInformation.ExitCode.Value == 0 || boundTask.ExecutionInformation.ExitCode.Value != 0) { //Dump the standard out file of the task. NodeFile taskStandardOut = await boundTask.GetNodeFileAsync(Batch.Constants.StandardOutFileName); Console.WriteLine("Task {0} StdOut:", boundTask.Id); Console.WriteLine("----------------------------------------"); string stdOutString = await taskStandardOut.ReadAsStringAsync(); result = stdOutString; Console.WriteLine(stdOutString); } //Check for nonzero exit code and dump standard error if there was a nonzero exit code. if (boundTask.ExecutionInformation.ExitCode.Value != 0) { NodeFile taskErrorFile = await boundTask.GetNodeFileAsync(Batch.Constants.StandardErrorFileName); Console.WriteLine("Task {0} StdErr:", boundTask.Id); Console.WriteLine("----------------------------------------"); string stdErrString = await taskErrorFile.ReadAsStringAsync(); Console.WriteLine(stdErrString); throw new TextSearchException(String.Format("Task {0} failed with a nonzero exit code", boundTask.Id)); } } } return(result); } else { throw new TextSearchException(String.Format("Task {0} is not completed yet. Current state: {1}", boundTask.Id, boundTask.State)); } }