public void Initialize(IExecutionLogLogger executionLogLogger, int feedId, bool isIncremental, DateTime?fromTime, DateTime?effectiveFromTime, DateTime executionTime) { _executionLogLogger = executionLogLogger; _isIncrementalRun = isIncremental; _ratingsImportRepository = new RatingsImportRepository(Log); }
private void RecordSuccessfulFeedRun(IFeedRun feedRun, IExecutionLogLogger executionLogLogger) { feedRun.DateCompleted = _effectiveExecutionEndTime; feedRun.LastExecutionStartDate = executionLogLogger.GetExecutionStartTime(); feedRun.LastExecutionCompletedDate = executionLogLogger.GetExecutionEndTime(); feedRun.ExecutionLog = executionLogLogger.GetExecutionLog(); FeedRunService.EndFeedRun(feedRun, true); }
public void Build(string[] args) { try { //check if another instance is running - if so exit ExecutionLogLogger.SetExecutionStartTime(DateTime.Now); var isProcessRunning = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)).Length > 1; if (isProcessRunning) { Log.Info("Another instance was running, so exiting the application without any processing."); return; } // First check if the "done" file is there. If so, skip job execution and move to file-related steps if (HasDoneFile()) { Log.Info("Done file exists at the drop folder. Skipping job execution and moving to file operations."); ExecuteFileOperations(); return; } Log.Info("Execution started!"); var feed = FeedService.GetFeed(FeedId); var allowPrimary = !feed.IsPaused; if (!allowPrimary) { Log.InfoFormat("{0} feeds are paused. Exiting application without any processing.", feed.Name); return; } // First clean all the files inside the output folder (in case the previous run failed and left out old files behind.) RemoveOldFiles(); _currentRun = FeedRunService.GetOrCreateActiveFeedRun(feed.FeedId, true, false); _effectiveExecutionEndTime = DateTime.Now; Runner.Initialize(ExecutionLogLogger, _currentRun.FeedId); ExecutionLogLogger = Runner.Execute(); if (ExecutionLogLogger.HasError) { Log.Error("Execution failed!!! Exiting application without moving any files."); HandleExit(); return; } HandleSuccess(); var elapsedTime = DateTime.Now - ExecutionLogLogger.GetExecutionStartTime(); Log.InfoFormat("Execution completed in {0}", elapsedTime.ToString(@"dd\.hh\:mm\:ss")); } catch (Exception e) { Log.Error("Execution failed!!!", e); HandleExit(); } }
private void RecordFailedFeedRun(int feedId, IExecutionLogLogger executionLogLogger) { var feedRun = FeedRunService.GetLatestRun(feedId); feedRun.LastExecutionStartDate = executionLogLogger.GetExecutionStartTime(); executionLogLogger.AddCustomMessage("This execution failed. Terminating execution."); feedRun.ExecutionLog = executionLogLogger.GetExecutionLog(); FeedRunService.EndFeedRun(feedRun, false); }
public void Initialize(IExecutionLogLogger executionLogLogger, int feedId) { _executionLogLogger = executionLogLogger; // Instantiate the IFeedGeneratorIndigoCategoryService _feedGeneratorCategoryService = new FeedGeneratorIndigoCategoryService(_indigoCategoryService, _googleCategoryService, Log); // First get rules associated with this feed _runnerFeed = new GooglePlaFeedRuleHelper(_feedRuleService, _feedGeneratorCategoryService, _feedCmsProductArciveEntryService, Log, AllowRuleOptimizations, AllowRuleEntryRemovals, AllowIEnumerableRuleEvaluations); _runnerFeed.Initialize(GooglePlaFeedId, false, null, executionLogLogger.GetExecutionStartTime(), GoogleRunFeedType.Google); }
public void Initialize(IExecutionLogLogger executionLogLogger, int plaFeedId, bool isIncremental, DateTime?fromTime, DateTime?effectiveFromTime, DateTime executionTime) { _executionLogLogger = executionLogLogger; _isIncrementalRun = isIncremental; _effectiveFromTime = effectiveFromTime; // Instantiate the IFeedGeneratorIndigoCategoryService _feedGeneratorCategoryService = new FeedGeneratorIndigoCategoryService(_indigoCategoryService, _googleCategoryService, Log); // First get rules associated with this feed _runnerFeedRulesHelper = new GooglePlaFeedRuleHelper(_feedRuleService, _feedGeneratorCategoryService, _feedCmsProductArchiveEntryService, Log, AllowRuleOptimizations, AllowRuleEntryRemovals, AllowIEnumerableRuleEvaluations); _runnerFeedRulesHelper.Initialize(plaFeedId, isIncremental, fromTime, executionTime, GoogleRunFeedType.Google); }
public void Initialize(IExecutionLogLogger executionLogLogger, int feedId, bool isIncremental, DateTime?fromTime, DateTime?effectiveFromTime, DateTime executionTime) { _executionLogLogger = executionLogLogger; _isIncrementalRun = isIncremental; _fromTime = fromTime; _effectiveFromTime = effectiveFromTime; _feedId = feedId; // Instantiate the IFeedGeneratorIndigoCategoryService _feedGeneratorCategoryService = new FeedGeneratorIndigoCategoryService(_indigoCategoryService, _googleCategoryService, Log); _runnerHelper = new RunnerHelper(_feedRuleService, _feedGeneratorCategoryService, _feedCmsProductArciveEntryService, Log, AllowRuleOptimizations, AllowRuleEntryRemovals, AllowIEnumerableRuleEvaluations); _runnerHelper.Initialize(feedId, _isIncrementalRun, _fromTime, executionTime); }
public void Initialize(IExecutionLogLogger executionLogLogger, int plaFeedId, bool isIncremental, DateTime?fromTime, DateTime?effectiveFromTime, DateTime executionTime, bool isPseudoFullRun) { _executionLogLogger = executionLogLogger; _isIncrementalRun = isIncremental; _isPseudoFullRun = isPseudoFullRun; _effectiveFromTime = effectiveFromTime; // Instantiate the IFeedGeneratorIndigoCategoryService _feedGeneratorCategoryService = new FeedGeneratorIndigoCategoryService(_indigoCategoryService, _googleCategoryService, Log); // Instantiate the "caching" cms data services _feedCmsProductArchiveEntryService = new FeedGeneratorCmsDataService(_feedCmsProductArchiveEntryServiceShared, null); _pastFeedCmsProductArchiveEntryService = new FeedGeneratorCmsDataService(_feedCmsProductArchiveEntryServiceShared, fromTime); // First get rules associated with this feed _productDataService = new ProductDataService(null, _feedGeneratorCategoryService, _feedRuleService, _feedCmsProductArchiveEntryService, _feedGeneratorCategoryService, _pastFeedCmsProductArchiveEntryService); }
public void Initialize(IExecutionLogLogger executionLogLogger, IExecutionLogLogger secondaryExecutionLogger, int feedId, int?secondaryRunId) { _executionLogLogger = executionLogLogger; _executionLogLoggerSecondary = secondaryExecutionLogger; _feedId = feedId; // Instantiate the IFeedGeneratorIndigoCategoryService _feedGeneratorCategoryService = new FeedGeneratorIndigoCategoryService(_indigoCategoryService, _googleCategoryService, Log); // First get rules associated with this feed _runnerFeed = new GooglePlaFeedRuleHelper(_feedRuleService, _feedGeneratorCategoryService, _feedCmsProductArciveEntryService, Log, AllowRuleOptimizations, AllowRuleEntryRemovals, AllowIEnumerableRuleEvaluations); _runnerFeed.Initialize(feedId, false, null, executionLogLogger.GetExecutionStartTime(), GoogleRunFeedType.Google); if (secondaryRunId.HasValue) { _runMode = RunMode.PrimaryAndSecondary; _runnerFeedSecondary = new GooglePlaFeedRuleHelper(_feedRuleService, _feedGeneratorCategoryService, _feedCmsProductArciveEntryService, Log, AllowRuleOptimizations, AllowRuleEntryRemovals, AllowIEnumerableRuleEvaluations); _runnerFeedSecondary.Initialize(secondaryRunId.Value, false, null, executionLogLogger.GetExecutionStartTime(), GoogleRunFeedType.Yahoo); } }
public void Build(string[] args) { try { //check if another instance is running - if so exit ExecutionLogLogger.SetExecutionStartTime(DateTime.Now); var isProcessRunning = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)).Length > 1; if (isProcessRunning) { Log.Info("Another instance was running, so exiting the application without any processing."); return; } // First check if the "done" file is there. If so, skip job execution and move to file-related steps if (HasDoneFile()) { Log.Info("Done file exists at the drop folder. Skipping job execution and moving to file operations."); ExecuteFileOperations(); return; } // Check if the target destination contains any files, if so exit. if (!IsTargetDestinationClean()) { Log.Info("Target destination has files. Exiting application without any processing."); return; } var enforceFullRun = args.ToList().Contains(FullRunParamName, StringComparer.InvariantCultureIgnoreCase); Log.Info("Execution started!"); var feed = FeedService.GetFeed(FeedId); // If the feed is paused, terminate execution if (feed.IsPaused) { Log.Info("This feed is in paused state. Exiting application without any processing"); return; } // First clean all the files inside the output folder (in case the previous run failed) RemoveOldFiles(); if (!enforceFullRun && !AllowIncrementalRuns) { enforceFullRun = true; } _currentRun = FeedRunService.GetOrCreateActiveFeedRun(feed.FeedId, enforceFullRun, AllowIncrementalRuns); _effectiveExecutionEndTime = DateTime.Now; var fromTime = _currentRun.DateStarted; var effectiveStartTime = fromTime.AddHours(-IncrementalRunBufferTimeLength); if (_currentRun.FeedRunType == FeedRunType.Incremental && !string.IsNullOrWhiteSpace(TestIncrementalRunFromDate)) { var time = DateTime.Parse(TestIncrementalRunFromDate); fromTime = time; effectiveStartTime = time.AddHours(-IncrementalRunBufferTimeLength); Log.InfoFormat("Found TestIncrementalRunFromDate. Using its value {0}", TestIncrementalRunFromDate); } if (_currentRun.FeedRunType == FeedRunType.Incremental) { Log.InfoFormat("Executing an incremental run with an effective start date of {0}", effectiveStartTime); } Runner.Initialize(ExecutionLogLogger, _currentRun.FeedId, _currentRun.FeedRunType == FeedRunType.Incremental, fromTime, effectiveStartTime, _effectiveExecutionEndTime); ExecutionLogLogger = Runner.Execute(); if (ExecutionLogLogger.HasError && (_currentRun.FeedRunType == FeedRunType.Incremental || !RRFeedGenerator.Execution.FileFeedWriter.Constants.AllowItemErrorsInFiles)) { Log.Error("Execution failed!!!"); HandleExit(); return; } HandleSuccess(); var elapsedTime = DateTime.Now - ExecutionLogLogger.GetExecutionStartTime(); Log.InfoFormat("Execution completed in {0}", elapsedTime.ToString(@"dd\.hh\:mm\:ss")); } catch (Exception e) { Log.Error("Execution failed!!!", e); HandleExit(); } }
public static bool Write(KeyValuePair <FeedGenerationFileLineItem, FeedGenerationFileItemRange[]> lineItemEntry, Action <FeedGenerationFileLineItem, FeedGenerationFileItemRange, IEnumerable <AbstractFileFeedWriter> > writeRangeFile, ILogger log, IExecutionLogLogger executionLogLogger, IFeedGeneratorIndigoCategoryService feedGeneratorIndigoCategoryService, bool isIncrementalRun) { Parallel.ForEach(lineItemEntry.Value, Constants.ParallelOptions, fileItemRange => { var commonContext = new FeedWriterContext.CommonContext { FeedGeneratorIndigoCategoryService = feedGeneratorIndigoCategoryService, FileItemRange = fileItemRange, LineItem = lineItemEntry.Key, Log = log, ExecutionLogLogger = executionLogLogger, IsIncrementalRun = isIncrementalRun }; var writerList = new List <AbstractFileFeedWriter>(); ((Language[])Enum.GetValues(typeof(Language))).ForEach( language => { var inputContext = new InputContext { CommonContext = commonContext, Language = language }; new AbstractFileFeedWriter[] { // Add new Writers here. new ProductFileFeedWriter(inputContext), new CustomAttributeFileFeedWriter(inputContext), new ProductToCategoryFileFeedWriter(inputContext) } .ForEach(writerList.Add); }); try { writeRangeFile(lineItemEntry.Key, fileItemRange, writerList); writerList.ForEach(writer => executionLogLogger.AddFileGenerationUpdate(writer.Context.Path, true)); } catch (Exception ex) { log.Error(string.Format("static AbstractFileFeedWriter.Write"), ex); _hasError = true; writerList.ForEach(writer => executionLogLogger.AddFileGenerationUpdate(writer.Context.Path, false)); if (isIncrementalRun || !Constants.AllowItemErrorsInFiles) { throw; } } finally { writerList.ForEach(writer => writer.Dispose()); writerList.ForEach(writer => writer.Context.Log.InfoFormat( "{0} completed. Processed record count {1}. Error record count {2}, deleted/skipped record count {3}", writer.Identifier, writer._processedRecordCount, writer._errorRecordCount, writer._skippedRecordCount)); } }); return(_hasError); }
public void Build(string[] args) { try { //check if another instance is running - if so exit ExecutionLogLogger.SetExecutionStartTime(DateTime.Now); var isProcessRunning = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)).Length > 1; if (isProcessRunning) { Log.Info("Another instance was running, so exiting the application without any processing."); return; } var enforceFullRun = args.ToList().Contains(FullRunParamName, StringComparer.InvariantCultureIgnoreCase); Log.Info("Execution started!"); var feed = FeedService.GetFeed(FeedId); // If the feed is paused, terminate execution if (feed.IsPaused) { Log.Info("This feed is in paused state. Exiting application without any processing"); return; } if (!enforceFullRun && !AllowIncrementalRuns) { enforceFullRun = true; } _currentRun = FeedRunService.GetOrCreateActiveFeedRun(feed.FeedId, enforceFullRun, AllowIncrementalRuns); // First clean all the files inside the download folder (in case the previous run failed) RemoveOldFiles(); // Download the file GetRatingsFileByFtp(); // Unzip the file UnzipRatingsFile(); _effectiveExecutionEndTime = DateTime.Now; var fromTime = _currentRun.DateStarted; var effectiveStartTime = fromTime.AddHours(-IncrementalRunBufferTimeLength); if (_currentRun.FeedRunType == FeedRunType.Incremental && !string.IsNullOrWhiteSpace(TestIncrementalRunFromDate)) { var time = DateTime.Parse(TestIncrementalRunFromDate); fromTime = time; effectiveStartTime = time.AddHours(-IncrementalRunBufferTimeLength); Log.InfoFormat("Found TestIncrementalRunFromDate. Using its value {0}", TestIncrementalRunFromDate); } if (_currentRun.FeedRunType == FeedRunType.Incremental) { Log.InfoFormat("Executing an incremental run with an effective start date of {0}", effectiveStartTime); } Runner.Initialize(ExecutionLogLogger, _currentRun.FeedId, _currentRun.FeedRunType == FeedRunType.Incremental, fromTime, effectiveStartTime, _effectiveExecutionEndTime); ExecutionLogLogger = Runner.Execute(); if (ExecutionLogLogger.HasError) { Log.Error("Execution failed!!!"); HandleExit(); return; } HandleSuccess(); var elapsedTime = DateTime.Now - ExecutionLogLogger.GetExecutionStartTime(); Log.InfoFormat("Execution completed in {0}", elapsedTime.ToString(@"dd\.hh\:mm\:ss")); } catch (Exception e) { Log.Error("Execution failed!!!", e); HandleExit(); } }
public void Build(string[] args) { try { //check if another instance is running - if so exit ExecutionLogLogger.SetExecutionStartTime(DateTime.Now); ExecutionLogLoggerSecondary.SetExecutionStartTime(DateTime.Now); var isProcessRunning = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)).Length > 1; if (isProcessRunning) { Log.Info("Another instance was running, so exiting the application without any processing."); return; } // First check if the "done" file is there. If so, skip job execution and move to file-related steps if (HasDoneFile()) { Log.Info("Done file exists at the drop folder. Skipping job execution and moving to file operations."); ExecuteFileOperations(); return; } Log.Info("Execution started!"); var feed = FeedService.GetFeed(FeedId); IFeed secondaryFeed = null; if (RunMode == RunMode.PrimaryAndSecondary) { secondaryFeed = FeedService.GetFeed(FeedIdSecondary); } var allowPrimary = !feed.IsPaused; var allowSecondary = secondaryFeed != null && !secondaryFeed.IsPaused; if (!allowPrimary && !allowSecondary) { Log.InfoFormat("Both primary {0} and secondary {1} feeds are paused. Exiting application without any processing.", feed.Name, secondaryFeed.Name); return; } // If one of the feeds is paused, notify the user and move on if (!allowPrimary) { Log.InfoFormat("The primary feed {0} is in paused state. Skipping primary feed.", feed.Name); } if (RunMode == RunMode.PrimaryAndSecondary && !allowSecondary) { Log.InfoFormat("The secondary feed {0} is in paused state. Skipping secondary feed.", secondaryFeed.Name); } // First clean all the files inside the output folder (in case the previous run failed and left out old files behind.) RemoveOldFiles(); _currentRun = FeedRunService.GetOrCreateActiveFeedRun(feed.FeedId, true, false); int?secondaryRunId = null; if (RunMode == RunMode.PrimaryAndSecondary) { _currentSecondaryRun = FeedRunService.GetOrCreateActiveFeedRun(secondaryFeed.FeedId, true, false); secondaryRunId = _currentSecondaryRun.FeedId; } _effectiveExecutionEndTime = DateTime.Now; Runner.Initialize(ExecutionLogLogger, ExecutionLogLoggerSecondary, _currentRun.FeedId, secondaryRunId); var results = Runner.Execute().ToList(); ExecutionLogLogger = results[0]; if (RunMode == RunMode.PrimaryAndSecondary) { ExecutionLogLoggerSecondary = results[1]; } if (ExecutionLogLogger.HasError || ExecutionLogLoggerSecondary.HasError) { Log.Error("Execution failed!!! Exiting application without moving any files."); HandleExit(); return; } HandleSuccess(); var elapsedTime = DateTime.Now - ExecutionLogLogger.GetExecutionStartTime(); Log.InfoFormat("Execution completed in {0}", elapsedTime.ToString(@"dd\.hh\:mm\:ss")); } catch (Exception e) { Log.Error("Execution failed!!!", e); HandleExit(); } }
public void Build(string[] arguments) { try { //check if another instance is running - if so exit ExecutionLogLogger.SetExecutionStartTime(DateTime.Now); var isProcessRunning = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)).Length > 1; if (isProcessRunning) { Log.Info("Another instance was running, so exiting the application without any processing."); return; } // First check if the "done" file is there. If so, skip job execution and move to file-related steps if (HasDoneFile()) { Log.Info("Done file exists at the drop folder. Skipping job execution and moving to file operations."); ExecuteFileOperations(); return; } Log.Info("Execution started!"); var feed = FeedService.GetFeed(FeedId); if (feed.IsPaused) { Log.InfoFormat("{0} feed is paused. Exiting application without any processing.", feed.Name); return; } // First clean all the files inside the output folder (in case the previous run failed and left out old files behind.) RemoveOldFiles(); // First decide if a full run should be enforced. var lastSuccessfulPlaFeedRun = FeedRunService.GetLastSuccessfulRun(GooglePlaFeedId); var enforceFullRun = ShouldEnforceFullRun(arguments, lastSuccessfulPlaFeedRun); // Next, need to decide on the effective start time. If the previous successful run of the inventory feed // was more recent than the most recent successful run of the Google PLA feed, then use its end time. // Otherwise, use the end time of the most recent successful Google PLA feed run. _currentRun = FeedRunService.GetOrCreateActiveFeedRun(FeedId, enforceFullRun, AllowIncrementalRuns); var fromTime = GetFromTime(enforceFullRun, _currentRun, lastSuccessfulPlaFeedRun); // Effective start time is used for callibrating the fromTime to a previous point in time, in case this is needed due to the execution // sequence/timinig of other processes that impact the data that the inventory feed depends on. For example, if results of an inventory-related // process takes 2 hours to get replicated down to the catalogue/website, where as the inventory data has already been updated in Bronte at // the time of execution AND business has updated rules related to the feed in the past 15 minutes, then gathering the incremental data as // if the run started two hours ago but applying rule changes using "now" as the reference point will yield more "accurate" results. var effectiveStartTime = fromTime; if (_currentRun.FeedRunType == FeedRunType.Incremental) { effectiveStartTime = fromTime.AddHours(-IncrementalRunBufferTimeLength); } _effectiveExecutionEndTime = DateTime.Now; Runner.Initialize(ExecutionLogLogger, GooglePlaFeedId, _currentRun.FeedRunType == FeedRunType.Incremental, fromTime, effectiveStartTime, _effectiveExecutionEndTime); ExecutionLogLogger = Runner.Execute(); if (ExecutionLogLogger.HasError) { Log.Error("Execution failed!!! Exiting application without moving any files."); HandleExit(); return; } HandleSuccess(); var elapsedTime = DateTime.Now - ExecutionLogLogger.GetExecutionStartTime(); Log.InfoFormat("Execution completed in {0}", elapsedTime.ToString(@"dd\.hh\:mm\:ss")); } catch (Exception e) { Log.Error("Execution failed!!!", e); HandleExit(); } }