List of usage examples for org.springframework.batch.core JobExecution getExecutionContext
public ExecutionContext getExecutionContext()
From source file:br.com.postalis.folhapgto.steps.consultarLog.ConsultarLogImportacaoDecider.java
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) { dtReferencia = (Date) jobExecution.getJobParameters().getParameters().get("dtReferencia").getValue(); qtdErro = (Integer) jobExecution.getExecutionContext().get("qtdErro"); LOGGER.info("Verificando se ainda existem registros a processar..."); long qtdFaltam = consignacaoPopulisRepository.countEnvNaoIncorpByDtReferencia(dtReferencia); if (qtdFaltam > 0) { loop++;// w ww .ja v a 2 s . c om if (loop <= 5) { LOGGER.warn( "Encontrou " + qtdFaltam + " registros a processar, voltando para procesar o que falta!!!"); return new FlowExecutionStatus("LOOP"); } else { LOGGER.warn("ATENO!!!ATENO!!!ATENO!!!"); LOGGER.warn("AINDA FALTAM: " + qtdFaltam + " LANAMENTOS PARA SEREM ENVIADOS. "); LOGGER.warn("O SISTEMA RE-EXECUTA AUTOMTICAMENTE APENAS 5 VEZES. "); LOGGER.warn( "CASO QUEIRA ENVIAR OS LANAMENTOS PENDENTES, EXECUTE NOVAMENTE O SISTEMA MANUALMENTE!!! "); return FlowExecutionStatus.COMPLETED; } } else { if (qtdErro > 0) { LOGGER.warn("ATENO!!!ATENO!!!ATENO!!!"); LOGGER.warn("ALGUMAS RUBRICAS FORAM CRITICADAS PELA ECT. FAVOR, VERIFICAR NA BASE!!! "); } return FlowExecutionStatus.COMPLETED; } }
From source file:br.com.postalis.folhapgto.steps.consultarIncorporados.ConsultarRubIncorporadasDecider.java
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) { dtReferencia = (Date) jobExecution.getJobParameters().getParameters().get("dtReferencia").getValue(); qtdErro = (Integer) jobExecution.getExecutionContext().get("qtdErro"); LOGGER.info("Verificando se ainda existem registros a processar..."); long qtdFaltam = consignacaoPopulisRepository .countRubricaFPByDtReferenciaAndIdIncorporadaIsNull(dtReferencia); if (qtdFaltam > 0) { loop++;/*from w w w .j av a2 s. co m*/ if (loop <= 5) { LOGGER.warn( "Encontrou " + qtdFaltam + " registros a processar, voltando para procesar o que falta!!!"); return new FlowExecutionStatus("LOOP"); } else { LOGGER.warn("ATENO!!!ATENO!!!ATENO!!!"); LOGGER.warn("AINDA FALTAM: " + qtdFaltam + " LANAMENTOS PARA SEREM ENVIADOS. "); LOGGER.warn("O SISTEMA RE-EXECUTA AUTOMTICAMENTE APENAS 5 VEZES. "); LOGGER.warn( "CASO QUEIRA ENVIAR OS LANAMENTOS PENDENTES, EXECUTE NOVAMENTE O SISTEMA MANUALMENTE!!! "); return FlowExecutionStatus.COMPLETED; } } else { if (qtdErro > 0) { LOGGER.warn("ATENO!!!ATENO!!!ATENO!!!"); LOGGER.warn("ALGUMAS RUBRICAS FORAM CRITICADAS PELA ECT. FAVOR, VERIFICAR NA BASE!!! "); } return FlowExecutionStatus.COMPLETED; } }
From source file:trionsoft.test.StepRunner.java
/** * Launch just the specified step as its own job. An IllegalStateException * is thrown if there is no Step with the given name. * /* w w w.j a va2s. co m*/ * @param stepName The name of the step to launch * @param jobParameters The JobParameters to use during the launch * @param jobExecutionContext An ExecutionContext whose values will be * loaded into the Job ExecutionContext prior to launching the step. * @return JobExecution */ public JobExecution launchStep(Step step, JobParameters jobParameters, final ExecutionContext jobExecutionContext) { // // Create a fake job // SimpleJob job = new SimpleJob(); job.setName("TestJob"); job.setJobRepository(this.jobRepository); List<Step> stepsToExecute = new ArrayList<Step>(); stepsToExecute.add(step); job.setSteps(stepsToExecute); // // Dump the given Job ExecutionContext using a listener // if (jobExecutionContext != null && !jobExecutionContext.isEmpty()) { job.setJobExecutionListeners(new JobExecutionListener[] { new JobExecutionListenerSupport() { public void beforeJob(JobExecution jobExecution) { ExecutionContext jobContext = jobExecution.getExecutionContext(); for (Map.Entry<String, Object> entry : jobExecutionContext.entrySet()) { jobContext.put(entry.getKey(), entry.getValue()); } } } }); } // // Launch the job // return this.launchJob(job, jobParameters); }
From source file:br.com.postalis.folhapgto.steps.importarRubricas.ImportarRubricasFolhaPgtoDecider.java
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) { dtReferencia = (Date) jobExecution.getJobParameters().getParameters().get("dtReferencia").getValue(); controle = (PosGpxConsignacaoPopulisControle) jobExecution.getExecutionContext().get("controle"); qtdErro = (Integer) jobExecution.getExecutionContext().get("qtdErro"); LOGGER.info("Verificando se ainda existem registros a processar..."); long qtdFaltam = consignacaoPopulisRepository .countByDtReferenciaAndVlVerbaGreaterThanAndCsFuncionarioCdEmpresa(dtReferencia); if (qtdFaltam > 0) { loop++;/* w w w.ja v a 2s . c o m*/ if (loop <= 5) { LOGGER.warn( "Encontrou " + qtdFaltam + " registros a processar, voltando para procesar o que falta!!!"); return new FlowExecutionStatus("LOOP"); } else { LOGGER.warn("ATENO!!!ATENO!!!ATENO!!!"); LOGGER.warn("AINDA FALTAM: " + qtdFaltam + " LANAMENTOS PARA SEREM ENVIADOS. "); LOGGER.warn("O SISTEMA RE-EXECUTA AUTOMTICAMENTE APENAS 5 VEZES. "); LOGGER.warn( "CASO QUEIRA ENVIAR OS LANAMENTOS PENDENTES, EXECUTE NOVAMENTE O SISTEMA MANUALMENTE!!! "); return FlowExecutionStatus.COMPLETED; } } else { controle.setIdExportado('S'); controleRepository.save(controle); if (qtdErro > 0) { LOGGER.warn("ATENO!!!ATENO!!!ATENO!!!"); LOGGER.warn("ALGUMAS RUBRICAS FORAM CRITICADAS PELA ECT. FAVOR, VERIFICAR NA BASE!!! "); } return FlowExecutionStatus.COMPLETED; } }
From source file:br.com.postalis.folhapgto.steps.posFolha.ConsultarDescPosFolhaDecider.java
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) { dtReferencia = (Date) jobExecution.getJobParameters().getParameters().get("dtReferencia").getValue(); listaControle = (List<PosGpxConsignacaoPopulisControle>) jobExecution.getExecutionContext() .get("listaControle"); qtdErro = (Integer) jobExecution.getExecutionContext().get("qtdErro"); LOGGER.info("Verificando se ainda existem registros a processar..."); long qtdFaltam = consignacaoPopulisRepository.countByDtReferenciaAndEnviados(dtReferencia); if (qtdFaltam > 0) { loop++;/*from ww w .j av a2 s . c o m*/ if (loop <= 5) { LOGGER.warn( "Encontrou " + qtdFaltam + " registros a processar, voltando para procesar o que falta!!!"); return new FlowExecutionStatus("LOOP"); } else { LOGGER.warn("ATENO!!!ATENO!!!ATENO!!!"); LOGGER.warn("AINDA FALTAM: " + qtdFaltam + " LANAMENTOS PARA SEREM ENVIADOS. "); LOGGER.warn("O SISTEMA RE-EXECUTA AUTOMTICAMENTE APENAS 5 VEZES. "); LOGGER.warn( "CASO QUEIRA ENVIAR OS LANAMENTOS PENDENTES, EXECUTE NOVAMENTE O SISTEMA MANUALMENTE!!! "); return FlowExecutionStatus.COMPLETED; } } else { for (PosGpxConsignacaoPopulisControle controle : listaControle) { controle.setIdExportado('S'); controleRepository.save(controle); } if (qtdErro > 0) { LOGGER.warn("ATENO!!!ATENO!!!ATENO!!!"); LOGGER.warn("ALGUMAS RUBRICAS FORAM CRITICADAS PELA ECT. FAVOR, VERIFICAR NA BASE!!! "); } return FlowExecutionStatus.COMPLETED; } }
From source file:org.appverse.web.framework.backend.batch.services.business.impl.live.JobRunnerServiceImpl.java
private boolean skipExecution(String jobName, int postExecutionSleepTime) { Date startDate = null;// w w w . j a va 2 s .c o m List<JobInstance> jobInstances = jobExplorer.getJobInstances(jobName, 0, 1); if (CollectionUtils.isNotEmpty(jobInstances)) { // This will retrieve the latest job execution: List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstances.get(0)); if (CollectionUtils.isNotEmpty(jobExecutions)) { JobExecution jobExecution = jobExecutions.get(0); startDate = jobExecution.getStartTime(); Long lastExecutionOffsetAsString = (Long) jobExecution.getExecutionContext().get("offset"); long lastExecutionOffset = 0; if (lastExecutionOffsetAsString != null) { lastExecutionOffset = lastExecutionOffsetAsString.longValue(); } else { lastExecutionOffset = TimeZone.getDefault().getOffset(new Date().getTime()); } Date currentDate = new Date(); long offset = TimeZone.getDefault().getOffset(new Date().getTime()); if (startDate != null && currentDate.getTime() - offset - (startDate.getTime() - lastExecutionOffset) < postExecutionSleepTime * 1000) { logger.debug("Current date offset " + offset); logger.debug("Current date with offset " + (currentDate.getTime() - offset)); logger.debug("Last execution date offset " + lastExecutionOffset); logger.debug("Last execution date with offset " + (startDate.getTime() - lastExecutionOffset)); logger.debug("Current date with offset - start date with offset " + (currentDate.getTime() - offset - (startDate.getTime() - lastExecutionOffset))); logger.info("Batch executed " + (currentDate.getTime() - offset - (startDate.getTime() - lastExecutionOffset)) / 60000 + " minutes before"); logger.info("Batch run skipped "); return true; } } } logger.info("Batch run started "); return false; }
From source file:org.jasig.ssp.util.importer.job.BatchPartialUploadTest.java
@SuppressWarnings("unchecked") @Test/*from w w w. jav a 2 s. c om*/ public void testNoDirectory() throws Exception { deleteDirectory(inputDirectoryPath); Assert.assertTrue(!directoryExists(inputDirectoryPath)); JobExecution jobExecution = jobLauncherTestUtils.launchJob(); BatchStatus exitStatus = jobExecution.getStatus(); Map<String, ReportEntry> report = (Map<String, ReportEntry>) jobExecution.getExecutionContext() .get("report"); Assert.assertNull(report); Assert.assertEquals(BatchStatus.FAILED, exitStatus); Assert.assertTrue(!directoryExists(inputDirectoryPath)); }
From source file:org.jasig.ssp.util.importer.job.BatchPartialUploadTest.java
@SuppressWarnings("unchecked") @Test//from w w w . ja v a 2 s .c o m public void testDirectoryNoFiles() throws Exception { deleteDirectory(inputDirectoryPath); createDirectory(inputDirectoryPath); Assert.assertTrue(directoryExists(inputDirectoryPath)); JobExecution jobExecution = jobLauncherTestUtils.launchJob(); BatchStatus exitStatus = jobExecution.getStatus(); Map<String, ReportEntry> report = (Map<String, ReportEntry>) jobExecution.getExecutionContext() .get("report"); Assert.assertNull(report); Assert.assertEquals(BatchStatus.STOPPED, exitStatus); Assert.assertTrue(directoryExists(inputDirectoryPath)); }
From source file:org.jasig.ssp.util.importer.job.BatchPartialUploadTest.java
@SuppressWarnings("unchecked") @Test/*from w ww. j av a 2s . c om*/ public void testPartialUploadGuard() throws Exception { deleteDirectory(inputDirectoryPath); createFiles(inputDirectoryPath); Assert.assertTrue(directoryContainsFiles(inputDirectoryPath, 3, csvFilter)); JobExecution jobExecution = jobLauncherTestUtils.launchJob(); BatchStatus exitStatus = jobExecution.getStatus(); Map<String, ReportEntry> report = (Map<String, ReportEntry>) jobExecution.getExecutionContext() .get("report"); Assert.assertNull(report); Assert.assertEquals(BatchStatus.STOPPED, exitStatus); Assert.assertTrue(directoryExists(inputDirectoryPath)); Assert.assertTrue(directoryContainsFiles(inputDirectoryPath, 3, csvFilter)); }
From source file:org.jasig.ssp.util.importer.job.BatchInitializerHeaderFailTest.java
@Test public void testHeaderFailTest() throws Exception { deleteDirectory(processDirectoryPath); deleteDirectory(upsertDirectoryPath); Assert.assertTrue(!directoryExists(processDirectoryPath)); Assert.assertTrue(!directoryExists(upsertDirectoryPath)); JobExecution jobExecution = jobLauncherTestUtils.launchJob(); Assert.assertEquals(BatchStatus.FAILED, jobExecution.getStatus()); @SuppressWarnings("unchecked") Map<String, ReportEntry> report = (Map<String, ReportEntry>) jobExecution.getExecutionContext() .get("report"); Assert.assertNull(report);/* ww w. j a v a 2s. com*/ @SuppressWarnings("unchecked") List<ErrorEntry> errors = (List<ErrorEntry>) jobExecution.getExecutionContext().get("errors"); Assert.assertNull(errors); List<Throwable> failureExceptions = jobExecution.getAllFailureExceptions(); Assert.assertEquals(new Integer(1), new Integer(failureExceptions.size())); Assert.assertEquals(PartialUploadGuardException.class, failureExceptions.get(0).getClass()); }