Exemple #1
0
        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);
        }
Exemple #2
0
        protected override BatchJobExecutionResult OnExecute(CompleteMergeBatchJob batchJob)
        {
            using (new NotificationDisabler())
            {
                var webpage = _session.Get <Webpage>(batchJob.WebpageId);
                if (webpage == null)
                {
                    return(BatchJobExecutionResult.Failure("Could not find the webpage with id " + batchJob.WebpageId));
                }
                var mergeInto = _session.Get <Webpage>(batchJob.MergedIntoId);
                if (mergeInto == null)
                {
                    return(BatchJobExecutionResult.Failure("Could not find the webpage with id " + batchJob.MergedIntoId));
                }

                _session.Transact(session =>
                {
                    ApplyCustomMergeLogic(webpage, mergeInto);

                    var urlSegment = webpage.UrlSegment;
                    session.Delete(webpage);
                    var urlHistory = new UrlHistory
                    {
                        UrlSegment = urlSegment,
                        Webpage    = mergeInto,
                    };
                    mergeInto.Urls.Add(urlHistory);
                    session.Save(urlHistory);
                });


                return(BatchJobExecutionResult.Success());
            }
        }
        protected override BatchJobExecutionResult OnExecute(UpdateUrlBatchJob batchJob)
        {
            using (new NotificationDisabler())
            {
                var webpage = _session.Get <Webpage>(batchJob.WebpageId);
                if (webpage == null)
                {
                    return(BatchJobExecutionResult.Failure("Could not find the webpage with id " + batchJob.WebpageId));
                }

                _session.Transact(session =>
                {
                    var urlHistories = webpage.Urls.ToList();
                    foreach (var webpageUrl in urlHistories)
                    {
                        if (!batchJob.NewUrl.Equals(webpageUrl.UrlSegment, StringComparison.InvariantCultureIgnoreCase))
                        {
                            continue;
                        }

                        webpage.Urls.Remove(webpageUrl);
                        session.Delete(webpageUrl);
                    }

                    webpage.UrlSegment = batchJob.NewUrl;
                    session.Update(webpage);
                });

                return(BatchJobExecutionResult.Success());
            }
        }
        protected override BatchJobExecutionResult OnExecute(MoveWebpageBatchJob batchJob)
        {
            using (new NotificationDisabler())
            {
                var webpage = _session.Get <Webpage>(batchJob.WebpageId);
                if (webpage == null)
                {
                    return(BatchJobExecutionResult.Failure("Could not find the webpage with id " + batchJob.WebpageId));
                }

                var parent = batchJob.NewParentId.HasValue ? _session.Get <Webpage>(batchJob.NewParentId) : null;
                if (batchJob.NewParentId.HasValue && parent == null)
                {
                    return(BatchJobExecutionResult.Failure("Could not find the parent webpage with id " + batchJob.NewParentId));
                }

                _session.Transact(session =>
                {
                    webpage.Parent = parent;
                    session.Update(webpage);
                });

                return(BatchJobExecutionResult.Success());
            }
        }
 protected override BatchJobExecutionResult OnExecute(RebuildUniversalSearchIndex batchJob)
 {
     try
     {
         _universalSearchIndexManager.ReindexAll();
         return(BatchJobExecutionResult.Success());
     }
     catch (Exception exception)
     {
         CurrentRequestData.ErrorSignal.Raise(exception);
         return(BatchJobExecutionResult.Failure(exception.Message));
     }
 }
Exemple #6
0
 protected override BatchJobExecutionResult OnExecute(ImportProductBatchJob batchJob)
 {
     using (new NotificationDisabler())
     {
         try
         {
             _importProductsService.ImportProduct(batchJob.DTO);
             return(BatchJobExecutionResult.Success());
         }
         catch (Exception exception)
         {
             CurrentRequestData.ErrorSignal.Raise(exception);
             return(BatchJobExecutionResult.Failure(exception.Message));
         }
     }
 }