Exemplo n.º 1
0
        private async Task <List <JobHistoryViewModel> > GetRepoJobHistory(string selectedOwnerId, string selectedRepoId, string checkJobIds = "")
        {
            try
            {
                var jobs = await _jobStore.GetJobsForRepository(selectedOwnerId, selectedRepoId);

                var jobHistoriesHistoryViewModels = jobs.Select(j => new JobHistoryViewModel(j)).ToList();
                if (!string.IsNullOrEmpty(checkJobIds))
                {
                    var currentJobIds = checkJobIds.Split(",");
                    foreach (var cjid in currentJobIds)
                    {
                        //check current job has been loaded
                        var currentJob = jobs.FirstOrDefault(j => j.JobId.Equals(cjid));
                        if (currentJob == null)
                        {
                            try
                            {
                                currentJob = await _jobStore.GetJobInfoAsync(cjid);

                                var cjvm = new JobHistoryViewModel(currentJob);
                                jobHistoriesHistoryViewModels.Add(cjvm);
                            }
                            catch (JobNotFoundException)
                            {
                                // do nothing except log
                                Log.Warning($"Unable to load specific job ID '{cjid}' as it could not be found in the database.");
                            }
                        }
                    }
                }
                return(jobHistoriesHistoryViewModels.OrderByDescending(j => j.QueuedAt).ToList());
            }
            catch (JobNotFoundException)
            {
                return(new List <JobHistoryViewModel>());
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Get(string ownerId, string repoId = "")
        {
            try
            {
                if (string.IsNullOrEmpty(ownerId))
                {
                    return(BadRequest("Missing argument: ownerId"));
                }

                try
                {
                    // get jobs
                    if (string.IsNullOrEmpty(repoId))
                    {
                        //by owner
                        var ownerJobs = await _jobStore.GetJobsForOwner(ownerId);

                        return(new ObjectResult(ownerJobs));
                    }

                    var repoJobs = await _jobStore.GetJobsForRepository(ownerId, repoId);

                    return(new ObjectResult(repoJobs));
                }
                catch (JobNotFoundException)
                {
                    var empty = new List <JobInfo>();
                    return(new ObjectResult(empty));
                }
            }
            catch (Exception ex)
            {
                Log.Error($"Error retrieving jobs for owner '{ownerId}' and repo '{repoId}' (optional)", ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, ex));
            }
        }