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