Example #1
0
 public IList<BatchRunResult> GetResults(BatchRun batchRun)
 {
     return GetResultsQuery(batchRun)
         .OrderBy(result => result.ExecutionOrder)
         .Asc.Cacheable()
         .List();
 }
Example #2
0
 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);
 }
Example #5
0
        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")
            };
        }
Example #6
0
        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 };
        }
Example #7
0
        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;
            });
        }
Example #8
0
 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;
 }
Example #9
0
 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;
 }
Example #10
0
        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;
        }
Example #11
0
 public void Paused(BatchRun batchRun)
 {
     SetStatus(batchRun, BatchRunStatus.Paused);
 }
Example #12
0
 public async Task<int?> ExecuteNextTask(BatchRun run)
 {
     return await _executeNextBatchJob.Execute(run) ? run.Id : (int?)null;
 }
Example #13
0
 public ActionResult Row(BatchRun batchRun)
 {
     ViewData["completion-status"] = _batchRunUIService.GetCompletionStatus(batchRun);
     return PartialView(batchRun);
 }
Example #14
0
 public void Complete(BatchRun batchRun)
 {
     SetStatus(batchRun, BatchRunStatus.Complete);
 }
Example #15
0
 public JsonResult Pause(BatchRun run)
 {
     return Json(_batchRunUIService.Pause(run));
 }
Example #16
0
 public JsonResult ExecuteNext(BatchRun run)
 {
     return Json(_batchRunUIService.ExecuteNextTask(run));
 }
Example #17
0
 public PartialViewResult ShowPartial(BatchRun batchRun)
 {
     return PartialView("Show", batchRun);
 }
Example #18
0
 public JsonResult Start(BatchRun run)
 {
     return Json(_batchRunUIService.Start(run));
 }
Example #19
0
 private BatchRun GetBatchRunFromThisSession(BatchRun batchRun)
 {
     return _session.Get<BatchRun>(batchRun.Id);
 }
Example #20
0
 public ViewResult Show(BatchRun batchRun)
 {
     return View(batchRun);
 }
Example #21
0
 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);
 }
Example #22
0
 public int? Start(BatchRun run)
 {
     return _controlBatchRun.Start(run) ? run.Id : (int?)null;
 }
Example #23
0
 public bool Pause(BatchRun run)
 {
     return _controlBatchRun.Pause(run);
 }
Example #24
0
 public void ExecuteRequestForNextTask(BatchRun run)
 {
     _executeRequestForNextTask.Execute(run);
 }
Example #25
0
 public BatchCreationResult(Batch batch, BatchRun initialBatchRun)
 {
     Batch = batch;
     InitialBatchRun = initialBatchRun;
 }