public override ExitCodeType Run(GracefulCancellationToken loadCancellationToken, object payload = null)
        {
            // single job, so grab the first available LoadProgress and lock it
            var loadProgresses = LoadProgressSelectionStrategy.GetAllLoadProgresses();

            if (!loadProgresses.Any())
            {
                return(ExitCodeType.OperationNotRequired);
            }

            var loadProgress = loadProgresses.First();

            // we don't need any other schedules the strategy may have given us
            loadProgresses.Remove(loadProgress);

            // Create the job factory
            if (_scheduledJobFactory != null)
            {
                throw new Exception("Job factory should only be created once");
            }

            _scheduledJobFactory = new SingleScheduledJobFactory(loadProgress, JobDateGenerationStrategyFactory.Create(loadProgress, DataLoadEventListener), OverrideNumberOfDaysToLoad ?? loadProgress.DefaultNumberOfDaysToLoadEachTime, LoadMetadata, LogManager);

            // If the job factory won't produce any jobs we can bail out here
            if (!_scheduledJobFactory.HasJobs())
            {
                return(ExitCodeType.OperationNotRequired);
            }

            // Run the data load
            JobProvider = _scheduledJobFactory;

            return(base.Run(loadCancellationToken, payload));
        }
예제 #2
0
        public void LoadProgress_JobFactory_NoDates()
        {
            var lp = WhenIHaveA <LoadProgress>();



            lp.OriginDate = new DateTime(2001, 1, 1);

            // We are fully up-to-date
            lp.DataLoadProgress = DateTime.Now;

            lp.Check(new ThrowImmediatelyCheckNotifier());

            var stratFactory = new JobDateGenerationStrategyFactory(new AnyAvailableLoadProgressSelectionStrategy(lp.LoadMetadata));
            var strat        = stratFactory.Create(lp, new ThrowImmediatelyDataLoadEventListener());

            var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.WorkDirectory), "LoadProgress_JobFactory_NoDates", true);

            var lmd = lp.LoadMetadata;

            lmd.LocationOfFlatFiles = dir.RootPath.FullName;

            foreach (var cata in lmd.GetAllCatalogues())
            {
                cata.LoggingDataTask = "ff";
                cata.SaveToDatabase();
            }


            lmd.SaveToDatabase();


            var jobFactory = new SingleScheduledJobFactory(lp, strat, 999, lp.LoadMetadata, null);
            var ex         = Assert.Throws <Exception>(() => jobFactory.Create(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), null));

            Assert.AreEqual("DatesToRetrieve was empty for load 'MyLoad'.  Possibly the load is already up to date?", ex.Message);

            // We have 1 day to load (date is the last fully loaded date)
            lp.DataLoadProgress = DateTime.Now.AddDays(-2);
            lp.SaveToDatabase();

            strat      = stratFactory.Create(lp, new ThrowImmediatelyDataLoadEventListener());
            jobFactory = new SingleScheduledJobFactory(lp, strat, 999, lp.LoadMetadata, null);

            var job = jobFactory.Create(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), null);

            Assert.AreEqual(1, ((ScheduledDataLoadJob)job).DatesToRetrieve.Count);
        }