jobParameters = jobParametersExtractor.getJobParameters(job, stepExecution); executionContext.put(JOB_PARAMETERS_KEY, jobParameters);
@Override public JobParameters getJobParameters(Job job, StepExecution stepExecution) { Map<String, JobParameter> jobParametersMap = new HashMap<>(); for (JobParametersExtractor delegate : delegates) { jobParametersMap.putAll(delegate.getJobParameters(job, stepExecution).getParameters()); } return new JobParameters(jobParametersMap); }
private static void startMainJob(BatchStartAndRecoveryService service, JobParametersExtractor propertiesExtractor, Date date) throws JobInstanceAlreadyExistsException, NoSuchJobException, JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException { JobParameters jobParameters = propertiesExtractor.getJobParameters(null, null); JobParametersBuilder builder = new JobParametersBuilder(jobParameters); builder.addDate("date", date); try { service.start("mainJob", builder.toJobParameters()); } catch (JobInstanceAlreadyCompleteException e) { LOGGER.warn("Job already completed for this date " + new SimpleDateFormat("dd/MM/yyyy").format(date), e); } }
@Override public void execute(JobExecutionContext context) throws JobExecutionException { try { List<LocalDate> dates = ExcelFileUtils.generateListOfDates(); for (LocalDate date : dates) { JobParameters jobParameters = jobParametersExtractor.getJobParameters(null, null); JobParametersBuilder builder = new JobParametersBuilder(jobParameters); builder.addDate("date", Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant())); JobExecution jobExecution = service.startNewInstance("mainJob", builder.toJobParameters()); if (jobExecution.getStatus().isUnsuccessful()) { throw new JobExecutionException("Job 'mainJob' has FAILED!"); } } } catch (Exception e) { LOGGER.error("Error when starting the job: ", e); } } }
@Override public void execute(JobExecutionContext context) throws JobExecutionException { try { List<LocalDate> dates = ExcelFileUtils.generateListOfDates(); for (LocalDate date : dates) { JobParameters jobParameters = jobParametersExtractor.getJobParameters(null, null); JobParametersBuilder builder = new JobParametersBuilder(jobParameters); builder.addDate("date", Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant())); JobExecution jobExecution = service.startNewInstance("loadGtfsIntoDatabaseJob", builder.toJobParameters()); if (jobExecution.getStatus().isUnsuccessful()) { throw new JobExecutionException("Job 'mainJob' has FAILED!"); } } } catch (Exception e) { LOGGER.error("Error when starting the job: ", e); } }
jobParameters = jobParametersExtractor.getJobParameters(job, stepExecution); executionContext.put(JOB_PARAMETERS_KEY, jobParameters);
/** * Execute the job provided by delegating to the {@link JobLauncher} to * prevent duplicate executions. The job parameters will be generated by the * {@link JobParametersExtractor} provided (if any), otherwise empty. On a * restart, the job parameters will be the same as the last (failed) * execution. * * @see AbstractStep#doExecute(StepExecution) */ @Override protected void doExecute(StepExecution stepExecution) throws Exception { ExecutionContext executionContext = stepExecution.getExecutionContext(); JobParameters jobParameters; if (executionContext.containsKey(JOB_PARAMETERS_KEY)) { jobParameters = (JobParameters) executionContext.get(JOB_PARAMETERS_KEY); } else { jobParameters = jobParametersExtractor.getJobParameters(job, stepExecution); executionContext.put(JOB_PARAMETERS_KEY, jobParameters); } JobExecution jobExecution = jobLauncher.run(job, jobParameters); if (jobExecution.getStatus().isUnsuccessful()) { // AbstractStep will take care of the step execution status throw new UnexpectedJobExecutionException("Step failure: the delegate Job failed in JobStep."); } }
/** * Execute the job provided by delegating to the {@link JobLauncher} to * prevent duplicate executions. The job parameters will be generated by the * {@link JobParametersExtractor} provided (if any), otherwise empty. On a * restart, the job parameters will be the same as the last (failed) * execution. * * @see AbstractStep#doExecute(StepExecution) */ @Override protected void doExecute(StepExecution stepExecution) throws Exception { ExecutionContext executionContext = stepExecution.getExecutionContext(); JobParameters jobParameters; if (executionContext.containsKey(JOB_PARAMETERS_KEY)) { jobParameters = (JobParameters) executionContext.get(JOB_PARAMETERS_KEY); } else { jobParameters = jobParametersExtractor.getJobParameters(job, stepExecution); executionContext.put(JOB_PARAMETERS_KEY, jobParameters); } JobExecution jobExecution = jobLauncher.run(job, jobParameters); if (jobExecution.getStatus().isUnsuccessful()) { // AbstractStep will take care of the step execution status throw new UnexpectedJobExecutionException("Step failure: the delegate Job failed in JobStep."); } }
jobParameters = jobParametersExtractor.getJobParameters(job, stepExecution); executionContext.put(JOB_PARAMETERS_KEY, jobParameters);