Example #1
0
        /// <summary>
        /// Monitors the progress of a job.
        /// </summary>
        public async Task <BuildProgress> MonitorProgressAsync(
            string classroomName,
            string projectName,
            int userId)
        {
            var project = await LoadProjectAsync(classroomName, projectName);

            var asyncEnumerable = GetCommitsDescending(project, userId).ToAsyncEnumerable();
            var asyncEnumerator = asyncEnumerable.GetEnumerator();

            while (await asyncEnumerator.MoveNext())
            {
                var commit = asyncEnumerator.Current;

                if (commit.Build != null)
                {
                    return(BuildProgress.CompletedBuild());
                }

                if (commit.BuildJobId != null)
                {
                    var jobStatus = await _jobQueueClient
                                    .GetJobStatusAsync(commit.BuildJobId);

                    if (jobStatus.State == JobState.NotStarted)
                    {
                        return(BuildProgress.EnqueuedBuild());
                    }
                    else if (jobStatus.State == JobState.InProgress)
                    {
                        var duration = _timeProvider.UtcNow - jobStatus.EnteredState;

                        return(BuildProgress.InProgressBuild(duration));
                    }
                    else
                    {
                        return(BuildProgress.UnknownBuild());
                    }
                }
            }

            return(null);
        }