public IList<BatchRunResult> GetResults(BatchRun batchRun) { return GetResultsQuery(batchRun) .OrderBy(result => result.ExecutionOrder) .Asc.Cacheable() .List(); }
private void SetStatus(BatchRun batchRun, BatchRunStatus status) { _session.Transact(session => { batchRun.Status = status; session.Update(batchRun); }); }
public async Task Execute(BatchRun run) { // ensure the run is from the current session run = _session.Get<BatchRun>(run.Id); run.Status = BatchRunStatus.Executing; while (await _executeNextBatchJob.Execute(run)) { } }
public void Execute(BatchRun run) { var cookieContainer = new CookieContainer(); var cookies = _context.Request.Cookies; HttpCookie cookie = cookies[".AspNet.ApplicationCookie"]; cookieContainer.Add(new Cookie(cookie.Name, cookie.Value, cookie.Path, _context.Request.Url.Host)); var httpClientHandler = new HttpClientHandler { UseCookies = true, CookieContainer = cookieContainer }; var httpClient = new HttpClient(httpClientHandler); var url = _urlHelper.Action("ExecuteNext", "BatchExecution", new { id = run.Guid }, "http"); httpClient.GetAsync(url); }
public BatchCompletionStatus GetCompletionStatus(BatchRun batchRun) { var timeTaken = GetResultsQuery(batchRun) .Where(result => result.MillisecondsTaken != null) .Select(Projections.Sum<BatchRunResult>(result => result.MillisecondsTaken)) .Cacheable() .FutureValue<decimal?>(); var averageTimeTaken = GetResultsQuery(batchRun) .Where(result => result.MillisecondsTaken != null) .Select(Projections.Avg<BatchRunResult>(result => result.MillisecondsTaken)) .Cacheable() .FutureValue<double?>(); var pending = GetResultsQuery(batchRun) .Where(result => result.Status == JobExecutionStatus.Pending) .Select(Projections.Count<BatchRunResult>(result => result.Id)) .Cacheable() .FutureValue<int>(); var failed = GetResultsQuery(batchRun) .Where(result => result.Status == JobExecutionStatus.Failed) .Select(Projections.Count<BatchRunResult>(result => result.Id)) .Cacheable() .FutureValue<int>(); var succeeded = GetResultsQuery(batchRun) .Where(result => result.Status == JobExecutionStatus.Succeeded) .Select(Projections.Count<BatchRunResult>(result => result.Id)) .Cacheable() .FutureValue<int>(); var total = GetResultsQuery(batchRun) .Select(Projections.Count<BatchRunResult>(result => result.Id)) .Cacheable() .FutureValue<int>(); return new BatchCompletionStatus { Total = total.Value, Failed = failed.Value, Pending = pending.Value, Succeeded = succeeded.Value, TimeTaken = TimeSpan.FromMilliseconds(Convert.ToDouble(timeTaken.Value.GetValueOrDefault())), AverageTimeTaken = averageTimeTaken.Value.GetValueOrDefault().ToString("0.00ms") }; }
public NextJobToRunResult Get(BatchRun batchRun) { if (batchRun.Status == BatchRunStatus.Pending) return new NextJobToRunResult(); if (batchRun.Status == BatchRunStatus.Complete) return new NextJobToRunResult { Complete = true }; if (batchRun.Status == BatchRunStatus.Paused) return new NextJobToRunResult { Paused = true }; var runResult = _session.QueryOver<BatchRunResult>() .Where(result => result.Status == JobExecutionStatus.Pending && result.BatchRun.Id == batchRun.Id) .OrderBy(result => result.ExecutionOrder).Asc .Take(1).SingleOrDefault(); return runResult == null ? new NextJobToRunResult { Complete = true } : new NextJobToRunResult { Result = runResult }; }
public BatchRun Create(Batch batch) { if (batch == null) return null; BatchJob jobAlias = null; var subQuery = QueryOver.Of<BatchRunResult>() .Where(result => result.Status != JobExecutionStatus.Failed && result.BatchJob.Id == jobAlias.Id) .Select(result => result.Id); var jobs = _statelessSession.QueryOver(() => jobAlias) .Where(job => job.Batch.Id == batch.Id) .WithSubquery.WhereNotExists(subQuery) .List(); // we need to make sure that the site is loaded from the correct session var site = _statelessSession.Get<Site>(batch.Site.Id); return _statelessSession.Transact(session => { var now = CurrentRequestData.Now; var batchRun = new BatchRun { Batch = batch, BatchRunResults = new List<BatchRunResult>(), Site = site, CreatedOn = now, UpdatedOn = now }; session.Insert(batchRun); for (int index = 0; index < jobs.Count; index++) { BatchJob batchJob = jobs[index]; var batchRunResult = new BatchRunResult { BatchJob = batchJob, Status = JobExecutionStatus.Pending, ExecutionOrder = index, BatchRun = batchRun, Site = site, CreatedOn = now, UpdatedOn = now }; batchRun.BatchRunResults.Add(batchRunResult); session.Insert(batchRunResult); } return batchRun; }); }
public bool Start(BatchRun batchRun) { batchRun = GetBatchRunFromThisSession(batchRun); if (batchRun == null || (batchRun.Status == BatchRunStatus.Executing || batchRun.Status == BatchRunStatus.Complete)) return false; _session.Transact(session => { batchRun.Status = BatchRunStatus.Executing; session.Update(batchRun); }); EventContext.Instance.Publish<IOnBatchRunStart, BatchRunStartArgs>(new BatchRunStartArgs { BatchRun = batchRun }); return true; }
public bool Pause(BatchRun batchRun) { batchRun = GetBatchRunFromThisSession(batchRun); if (batchRun == null || (batchRun.Status != BatchRunStatus.Executing)) return false; _session.Transact(session => { batchRun.Status = BatchRunStatus.Paused; session.Update(batchRun); }); EventContext.Instance.Publish<IOnBatchRunPause, BatchRunPauseArgs>(new BatchRunPauseArgs { BatchRun = batchRun }); return true; }
public async Task<bool> Execute(BatchRun batchRun) { var stopWatch = Stopwatch.StartNew(); var result = _getNextJobToRun.Get(batchRun); var runResult = result.Result; if (runResult == null) { if (result.Complete) _setRunStatus.Complete(batchRun); if (result.Paused) _setRunStatus.Paused(batchRun); return false; } if (runResult.BatchJob == null) _setBatchJobExecutionStatus.Complete(runResult, BatchJobExecutionResult.Failure("No job associated to result")); await _runBatchRunResult.Run(runResult, stopWatch); return true; }
public void Paused(BatchRun batchRun) { SetStatus(batchRun, BatchRunStatus.Paused); }
public async Task<int?> ExecuteNextTask(BatchRun run) { return await _executeNextBatchJob.Execute(run) ? run.Id : (int?)null; }
public ActionResult Row(BatchRun batchRun) { ViewData["completion-status"] = _batchRunUIService.GetCompletionStatus(batchRun); return PartialView(batchRun); }
public void Complete(BatchRun batchRun) { SetStatus(batchRun, BatchRunStatus.Complete); }
public JsonResult Pause(BatchRun run) { return Json(_batchRunUIService.Pause(run)); }
public JsonResult ExecuteNext(BatchRun run) { return Json(_batchRunUIService.ExecuteNextTask(run)); }
public PartialViewResult ShowPartial(BatchRun batchRun) { return PartialView("Show", batchRun); }
public JsonResult Start(BatchRun run) { return Json(_batchRunUIService.Start(run)); }
private BatchRun GetBatchRunFromThisSession(BatchRun batchRun) { return _session.Get<BatchRun>(batchRun.Id); }
public ViewResult Show(BatchRun batchRun) { return View(batchRun); }
private IQueryOver<BatchRunResult, BatchRunResult> GetResultsQuery(BatchRun batchRun) { IQueryOver<BatchRunResult, BatchRunResult> queryOver = _session.QueryOver<BatchRunResult>(); if (batchRun != null) return queryOver.Where(result => result.BatchRun.Id == batchRun.Id); // query to return 0; return queryOver.Where(result => result.Id < 0); }
public int? Start(BatchRun run) { return _controlBatchRun.Start(run) ? run.Id : (int?)null; }
public bool Pause(BatchRun run) { return _controlBatchRun.Pause(run); }
public void ExecuteRequestForNextTask(BatchRun run) { _executeRequestForNextTask.Execute(run); }
public BatchCreationResult(Batch batch, BatchRun initialBatchRun) { Batch = batch; InitialBatchRun = initialBatchRun; }