private Build CreateBuild(TFSAdvanced.Updater.Models.Builds.Build build) { var buildDto = new Build { Id = build.id, Name = build.definition.name, Folder = build.definition.path, Url = build._links.web.href, SourceCommit = build.sourceVersion, QueuedDate = build.queueTime, StartedDate = build.startTime, FinishedDate = build.finishTime, Creator = new User { Name = build.requestedFor.displayName, IconUrl = build.requestedFor.imageUrl } }; if (build.definition != null) { if (build.definition.repository == null) { BuildDefinition buildDefinitionDto = buildDefinitionRepository.GetBuildDefinition(build.definition.id); buildDto.Repository = buildDefinitionDto.Repository; } else { buildDto.Repository = repositoryRepository.GetById(build.definition.repository.id); } } switch (build.status) { case TFSAdvanced.Updater.Models.Builds.BuildStatus.notStarted: buildDto.BuildStatus = BuildStatus.NotStarted; break; case TFSAdvanced.Updater.Models.Builds.BuildStatus.inProgress: buildDto.BuildStatus = BuildStatus.Building; break; default: switch (build.result) { case BuildResult.abandoned: buildDto.BuildStatus = BuildStatus.Abandonded; break; case BuildResult.canceled: buildDto.BuildStatus = BuildStatus.Cancelled; break; case BuildResult.expired: buildDto.BuildStatus = BuildStatus.Expired; break; case BuildResult.failed: case BuildResult.partiallySucceeded: buildDto.BuildStatus = BuildStatus.Failed; break; case BuildResult.succeeded: buildDto.BuildStatus = BuildStatus.Succeeded; break; default: buildDto.BuildStatus = BuildStatus.NoBuild; break; } break; } return(buildDto); }
protected override void Update() { var jobRequests = new ConcurrentBag <QueueJob>(); Parallel.ForEach(poolRepository.GetAll(), new ParallelOptions { MaxDegreeOfParallelism = AppSettings.MAX_DEGREE_OF_PARALLELISM }, pool => { List <JobRequest> poolJobRequests = GetAsync.FetchResponseList <JobRequest>(requestData, $"{requestData.BaseAddress}/_apis/distributedtask/pools/{pool.id}/jobrequests?api-version=1.0", Logger).Result; if (poolJobRequests != null) { foreach (JobRequest poolJobRequest in poolJobRequests) { var queueJob = new QueueJob { RequestId = poolJobRequest.requestId, QueuedTime = poolJobRequest.queueTime, AssignedTime = poolJobRequest.assignTime, FinishedTime = poolJobRequest.finishTime, Name = poolJobRequest.definition.name, Url = poolJobRequest.definition._links.web.href }; if (poolJobRequest.planType == PlanTypes.Build) { queueJob.JobType = JobType.Build; Build build = buildRepository.GetBuild(poolJobRequest.owner.id); if (build != null) { queueJob.LaunchedBy = build.Creator; queueJob.StartedTime = build.StartedDate; queueJob.FinishedTime = build.FinishedDate; queueJob.BuildFolder = build.Folder; switch (build.BuildStatus) { case BuildStatus.NotStarted: queueJob.QueueJobStatus = QueueJobStatus.Queued; break; case BuildStatus.Abandonded: queueJob.QueueJobStatus = QueueJobStatus.Abandonded; break; case BuildStatus.Building: queueJob.QueueJobStatus = QueueJobStatus.Building; break; case BuildStatus.Cancelled: queueJob.QueueJobStatus = QueueJobStatus.Cancelled; break; case BuildStatus.Expired: case BuildStatus.Failed: queueJob.QueueJobStatus = QueueJobStatus.Failed; break; case BuildStatus.Succeeded: queueJob.QueueJobStatus = QueueJobStatus.Succeeded; break; } } BuildDefinition buildDefinition = buildDefinitionRepository.GetBuildDefinition(poolJobRequest.definition.id); if (buildDefinition?.Repository != null) { Project project = projectRepository.GetProject(buildDefinition.Repository.Project.Id); if (project != null) { queueJob.Project = new Project { Id = project.Id, Name = project.Name, Url = project.Url }; } else { queueJob.Project = new Project { Name = "Unknown Project" }; } } else { queueJob.Project = new Project { Name = "Unknown Build Definition" }; } } else if (poolJobRequest.planType == PlanTypes.Release) { queueJob.JobType = JobType.Release; if (poolJobRequest.finishTime.HasValue) { switch (poolJobRequest.result) { case BuildResult.succeeded: queueJob.QueueJobStatus = QueueJobStatus.Succeeded; break; case BuildResult.abandoned: queueJob.QueueJobStatus = QueueJobStatus.Abandonded; break; case BuildResult.canceled: queueJob.QueueJobStatus = QueueJobStatus.Cancelled; break; case BuildResult.failed: case BuildResult.partiallySucceeded: queueJob.QueueJobStatus = QueueJobStatus.Failed; break; } } ReleaseDefinition releaseDefinition = releaseDefinitionRepository.GetReleaseDefinition(poolJobRequest.scopeId.ToString(), poolJobRequest.definition.id); if (releaseDefinition != null) { queueJob.Project = releaseDefinition.Project; } else { queueJob.Project = new Project { Name = "Unknown Release Definition" }; } } jobRequests.Add(queueJob); } } }); jobRequestRepository.Update(jobRequests); updateStatusRepository.UpdateStatus(new UpdateStatus { LastUpdate = DateTime.Now, UpdatedRecords = jobRequests.Count, UpdaterName = nameof(JobRequestUpdater) }); }