public static void MarkJobAsFailed(Job job, string error) { using (var repo = new JobRepository()) { repo.UpdateStateForJob(job, JobState.Failed, error); } }
public ActionResult ViewLog(int id) { Job job; using (var repo = new JobRepository()) { job = repo.GetJobById(id); } if (job == null) { return Content("Job not found."); } string logFileName = "Deploy_" + job.Name + "_" + job.Id + ".log"; string logFile = Path.Combine(_logDirectory, logFileName); if (System.IO.File.Exists(logFile)) { string allText = System.IO.File.ReadAllText(logFile); var viewModel = new DeploymentLogViewModel { JobId = job.Id.ToString(), DeploymentLog = allText, LogName = job.Name }; return View(viewModel); } return Content("File not found."); }
public static void MarkJobAsCompleteWithError(Job job) { using (var repo = new JobRepository()) { repo.UpdateStateForJob(job, JobState.CompletedWithError); } }
public static Job GetJob(int jobId, Logger defaultLogger) { Job currentJob; using (var repo = new JobRepository()) { defaultLogger.Info("Passed job with ID of {0}", jobId); currentJob = repo.GetJobById(jobId); if (currentJob == null) { defaultLogger.Warn("Job not found"); return null; } defaultLogger.Info("Job found. URL is {0} and branch is {1}", currentJob.Url, currentJob.Branch); if (currentJob.State != JobState.Pending) { defaultLogger.Warn("Cannot start job. Current state is {0}", currentJob.State); return null; } repo.UpdateStateForJob(currentJob, JobState.Running); } return currentJob; }
public string Create(string url, string branch) { using (var repo = new JobRepository()) { repo.AddNewJob(url, branch); } return "Job Queued."; }
public ActionResult MoreCompleted() { var viewModel = new CompletedJobsViewModel(); using (var repo = new JobRepository()) { IList<Job> completedJobs = repo.GetCompletedJobs(100); viewModel.CompletedDeployments = completedJobs.Select(GetViewModelForJob).ToList(); } return View(viewModel); }
public ActionResult Index() { var viewModel = new DeploymentDashboardViewModel(); using (var repo = new JobRepository()) { IList<Job> allRunningJobs = repo.GetCurrentlyRunningJobs(); viewModel.RunningDeployments = allRunningJobs.Select(GetViewModelForJob).ToList(); IList<Job> pendingJobs = repo.GetPendingJobs(); viewModel.PendingDeployments = pendingJobs.Select(GetViewModelForJob).ToList(); IList<Job> completedJobs = repo.GetCompletedJobs(10); viewModel.CompletedDeployments = completedJobs.Select(GetViewModelForJob).ToList(); } return View(viewModel); }
private void TimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs) { Job latestJob; IList<Job> currentlyRunningJobs; using (var jobRepo = new JobRepository()) { currentlyRunningJobs = jobRepo.GetCurrentlyRunningJobs(); latestJob = jobRepo.GetOldestUnstartedJob(); } if (currentlyRunningJobs.Count >= MaxRunningJobs) { Logger.Debug("There are currently {0} running job(s). The max job count is {1}", currentlyRunningJobs.Count, MaxRunningJobs); return; } if (latestJob != null) { StartRunningJob(latestJob); } }
public DeploymentStatusUpdater(DeploymentContext context) { _context = context; _taskRepository = new JobRepository(); }