예제 #1
0
        /// <summary>
        /// Enhances the given job with incrementer, validator and job execution listeners, if provided.
        /// </summary>
        /// <param name="target"></param>
        protected void Enhance(IJob target)
        {
            var job = target as AbstractJob;

            if (job != null)
            {
                job.Restartable   = Properties.Restartable;
                job.JobRepository = Properties.JobRepository;

                IJobParametersIncrementer jobParametersIncrementer = Properties.JobParametersIncrementer;
                if (jobParametersIncrementer != null)
                {
                    job.JobParametersIncrementer = jobParametersIncrementer;
                }

                IJobParametersValidator jobParametersValidator = Properties.JobParametersValidator;
                if (jobParametersValidator != null)
                {
                    job.JobParametersValidator = jobParametersValidator;
                }

                List <IJobExecutionListener> listeners = Properties.JobExecutionListeners;
                if (listeners.Any())
                {
                    job.SetJobExecutionListeners(listeners.ToArray());
                }
            }
        }
예제 #2
0
        /// <summary>
        /// @see IJobOperator#StartNextInstance .
        /// </summary>
        /// <param name="jobName"></param>
        /// <returns></returns>
        /// <exception cref="NoSuchJobException">&nbsp;</exception>
        /// <exception cref="JobParametersNotFoundException">&nbsp;</exception>
        /// <exception cref="UnexpectedJobExecutionException">&nbsp;</exception>
        /// <exception cref="JobParametersInvalidException">&nbsp;</exception>
        public long?StartNextInstance(string jobName)
        {
            _logger.Info("Locating parameters for next instance of job with name={0}", jobName);

            IJob job = JobRegistry.GetJob(jobName);
            IList <JobInstance> lastInstances = JobExplorer.GetJobInstances(jobName, 0, 1);

            IJobParametersIncrementer incrementer = job.JobParametersIncrementer;

            if (incrementer == null)
            {
                throw new JobParametersNotFoundException(
                          string.Format("No job parameters incrementer found for job={0}", jobName));
            }

            JobParameters parameters;

            if (!lastInstances.Any())
            {
                parameters = incrementer.GetNext(new JobParameters());
                if (parameters == null)
                {
                    throw new JobParametersNotFoundException(
                              string.Format("No bootstrap parameters found for job={0}", jobName));
                }
            }
            else
            {
                IList <JobExecution> lastExecutions = JobExplorer.GetJobExecutions(lastInstances.First());
                parameters = incrementer.GetNext(lastExecutions.First().JobParameters);
            }

            _logger.Info("Attempting to launch job with name={0} and parameters={1}", jobName, parameters);
            try
            {
                return(JobLauncher.Run(job, parameters).Id);
            }
            catch (JobExecutionAlreadyRunningException e)
            {
                throw new UnexpectedJobExecutionException(string.Format(IllegalStateMsg, "job already running", jobName, parameters), e);
            }
            catch (JobRestartException e)
            {
                throw new UnexpectedJobExecutionException(string.Format(IllegalStateMsg, "job not restartable", jobName, parameters), e);
            }
            catch (JobInstanceAlreadyCompleteException e)
            {
                throw new UnexpectedJobExecutionException(string.Format(IllegalStateMsg, "job instance already complete", jobName, parameters), e);
            }
        }
예제 #3
0
 /// <summary>
 /// Add a job parameters incrementer.
 /// </summary>
 /// <param name="jobParametersIncrementer"></param>
 /// <returns></returns>
 public JobBuilderHelper Incrementer(IJobParametersIncrementer jobParametersIncrementer)
 {
     Properties.JobParametersIncrementer = jobParametersIncrementer;
     return(this);
 }
예제 #4
0
 /// <summary>
 /// Add a job parameters incrementer.
 /// </summary>
 /// <param name="jobParametersIncrementer"></param>
 /// <returns></returns>
 public JobBuilderHelper Incrementer(IJobParametersIncrementer jobParametersIncrementer)
 {
     Properties.JobParametersIncrementer = jobParametersIncrementer;
     return this;
 }