public BatchCreationResult Create(IEnumerable<BatchJob> jobs) { DateTime now = CurrentRequestData.Now; // we need to make sure that the site is loaded from the correct session var site = _statelessSession.Get<Site>(_site.Id); var batch = new Batch { BatchJobs = new List<BatchJob>(), BatchRuns = new List<BatchRun>(), Site = site, CreatedOn = now, UpdatedOn = now }; _statelessSession.Transact(session => session.Insert(batch)); _statelessSession.Transact(session => { foreach (BatchJob job in jobs) { job.CreatedOn = now; job.UpdatedOn = now; job.Site = site; job.Batch = batch; batch.BatchJobs.Add(job); session.Insert(job); } }); BatchRun batchRun = _createBatchRun.Create(batch); batch.BatchRuns.Add(batchRun); _statelessSession.Transact(session => session.Update(batch)); return new BatchCreationResult(batch, batchRun); }
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 BatchStatus Get(Batch batch) { if (batch == null) return new BatchStatus(); var anyRuns = _session.QueryOver<BatchRun>().Where(job => job.Batch.Id == batch.Id).Any(); if (!anyRuns) return BatchStatus.Pending; var anyPaused = _session.QueryOver<BatchRun>().Where(job => job.Batch.Id == batch.Id && job.Status == BatchRunStatus.Paused).Any(); if (anyPaused) return BatchStatus.Paused; var anyExecuting = _session.QueryOver<BatchRun>().Where(job => job.Batch.Id == batch.Id && job.Status == BatchRunStatus.Executing).Any(); if (anyExecuting) return BatchStatus.Executing; if (_session.QueryOver<BatchRun>().Where(job => job.Batch.Id == batch.Id && job.Status != BatchRunStatus.Complete).Any()) return BatchStatus.Pending; return BatchStatus.Complete; }
public int Get(Batch batch) { return batch == null ? 0 : _session.QueryOver<BatchJob>().Where(job => job.Batch.Id == batch.Id).RowCount(); }
public BatchCreationResult(Batch batch, BatchRun initialBatchRun) { Batch = batch; InitialBatchRun = initialBatchRun; }
public static ImportDocumentsResult Successful(Batch batch) { return new ImportDocumentsResult { Batch = batch }; }
public static ImportProductsResult Successful(Batch batch) { return new ImportProductsResult {Batch = batch}; }
public ActionResult ShowPartial(Batch batch) { return PartialView("Show", batch); }
public ViewResult Show(Batch batch) { return View(batch); }