Ejemplo n.º 1
0
        public async Task <TaskResult> Execute(CancellationToken cancellationToken)
        {
            using (var taskClient = new TaskClient(taskProperties))
            {
                var taskResult = TaskResult.Failed;
                try
                {
                    // create timelinerecord if not provided
                    await CreateTaskTimelineRecordIfRequired(taskClient, cancellationToken).ConfigureAwait(false);

                    taskLogger = new TaskLogger(taskProperties, taskClient);

                    // report task started
                    await taskLogger.Log("Task started").ConfigureAwait(false);

                    await taskClient.ReportTaskStarted(taskProperties.TaskInstanceId, cancellationToken).ConfigureAwait(false);

                    await taskClient.ReportTaskProgress(taskProperties.TaskInstanceId, cancellationToken).ConfigureAwait(false);

                    // start client handler execute
                    var executeTask = taskExecutionHandler.ExecuteAsync(taskMessage, taskLogger, cancellationToken).ConfigureAwait(false);
                    taskResult = await executeTask;

                    // report task completed with status
                    await taskLogger.Log("Task completed").ConfigureAwait(false);

                    await taskClient.ReportTaskCompleted(taskProperties.TaskInstanceId, taskResult, cancellationToken).ConfigureAwait(false);

                    return(taskResult);
                }
                catch (Exception e)
                {
                    if (taskLogger != null)
                    {
                        await taskLogger.Log(e.ToString()).ConfigureAwait(false);
                    }

                    await taskClient.ReportTaskCompleted(taskProperties.TaskInstanceId, taskResult, cancellationToken).ConfigureAwait(false);

                    throw;
                }
                finally
                {
                    if (taskLogger != null)
                    {
                        await taskLogger.End().ConfigureAwait(false);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public async void Execute(CancellationToken cancellationToken)
        {
            // create timelinerecord if not provided
            await CreateTaskTimelineRecordIfRequired(cancellationToken);

            // initialize status report helper
            var jobStatusReportingHelper = new JobStatusReportingHelper(taskMessage);
            // report job started
            await jobStatusReportingHelper.ReportJobStarted("Job has started", cancellationToken);

            var planHelper  = new PlanHelper(taskMessage.PlanUri, new VssBasicCredential(string.Empty, taskMessage.AuthToken), taskMessage.ProjectId, taskMessage.HubName, taskMessage.PlanId);
            var taskLogger  = new TaskLogger(planHelper, taskMessage.TimelineId, taskMessage.JobId, taskMessage.TaskInstanceId);
            var executeTask = taskExecutionHandler.ExecuteAsync(taskLogger, cancellationToken);
            await jobStatusReportingHelper.ReportJobProgress("Job is in progress...", cancellationToken).ConfigureAwait(false);

            // start client handler execute
            var taskResult = await executeTask;
            // report job completed with status
            await jobStatusReportingHelper.ReportJobCompleted("Job completed", taskResult, cancellationToken);

            taskLogger.End();
        }