public async Task <bool> Execute(BatchRun batchRun) { Stopwatch stopWatch = Stopwatch.StartNew(); NextJobToRunResult result = _getNextJobToRun.Get(batchRun); BatchRunResult 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 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 } } ; BatchRunResult 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 async Task <BatchJobExecutionResult> Run(BatchRunResult runResult, Stopwatch stopWatch = null) { stopWatch = stopWatch ?? Stopwatch.StartNew(); _setBatchJobExecutionStatus.Starting(runResult); var batchJobExecutionResult = await _batchJobExecutionService.Execute(runResult.BatchJob); runResult.MillisecondsTaken = Convert.ToDecimal(stopWatch.Elapsed.TotalMilliseconds); _setBatchJobExecutionStatus.Complete(runResult, batchJobExecutionResult); return(batchJobExecutionResult); }
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 PartialViewResult Show(BatchRunResult result) { return(PartialView(result)); }