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));
        }
Ejemplo n.º 2
0
        public override ExitCodeType Run(GracefulCancellationToken loadCancellationToken, object payload = null)
        {
            // grab all the load schedules we can and lock them
            var loadProgresses = LoadProgressSelectionStrategy.GetAllLoadProgresses();

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

            // create job factory
            var progresses  = loadProgresses.ToDictionary(loadProgress => loadProgress, loadProgress => JobDateGenerationStrategyFactory.Create(loadProgress, DataLoadEventListener));
            var jobProvider = new MultipleScheduleJobFactory(progresses, OverrideNumberOfDaysToLoad, LoadMetadata, LogManager);

            // check if the factory will produce any jobs, if not we can stop here
            if (!jobProvider.HasJobs())
            {
                return(ExitCodeType.OperationNotRequired);
            }

            // Run the data load process
            JobProvider = jobProvider;

            //Do a data load
            ExitCodeType result;

            while ((result = base.Run(loadCancellationToken, payload)) == ExitCodeType.Success) //stop if it said not required
            {
                //or if between executions the token is set
                if (loadCancellationToken.IsAbortRequested)
                {
                    return(ExitCodeType.Abort);
                }

                if (loadCancellationToken.IsCancellationRequested)
                {
                    return(ExitCodeType.Success);
                }
            }

            //should be Operation Not Required or Error since the token inside handles stopping
            return(result);
        }