/** * Checks if given date is within a batch window. Batch window start time is checked inclusively. * @param date * @return */ public static boolean isWithinBatchWindow(Date date, ProcessEngineConfigurationImpl configuration) { if (configuration.getBatchWindowManager().isBatchWindowConfigured(configuration)) { BatchWindow batchWindow = configuration.getBatchWindowManager().getCurrentOrNextBatchWindow(date, configuration); if (batchWindow == null) { return false; } return batchWindow.isWithin(date); } else { return false; } }
/** * Checks if given date is within a batch window. Batch window start time is checked inclusively. * @param date * @return */ public static boolean isWithinBatchWindow(Date date, ProcessEngineConfigurationImpl configuration) { if (configuration.getBatchWindowManager().isBatchWindowConfigured(configuration)) { BatchWindow batchWindow = configuration.getBatchWindowManager().getCurrentOrNextBatchWindow(date, configuration); if (batchWindow == null) { return false; } return batchWindow.isWithin(date); } else { return false; } }
public static boolean isBatchWindowConfigured(CommandContext commandContext) { return commandContext.getProcessEngineConfiguration().getBatchWindowManager().isBatchWindowConfigured(commandContext.getProcessEngineConfiguration()); } }
public static boolean isBatchWindowConfigured(CommandContext commandContext) { return commandContext.getProcessEngineConfiguration().getBatchWindowManager().isBatchWindowConfigured(commandContext.getProcessEngineConfiguration()); } }
private Date getNextRunWithinBatchWindow(Date currentTime) { return processEngineConfiguration.getBatchWindowManager().getNextBatchWindow(currentTime, processEngineConfiguration).getStart(); }
private Date resolveDueDate(boolean isImmediatelyDue) { CommandContext commandContext = Context.getCommandContext(); if (isImmediatelyDue) { return ClockUtil.getCurrentTime(); } else { final BatchWindow currentOrNextBatchWindow = commandContext.getProcessEngineConfiguration().getBatchWindowManager() .getCurrentOrNextBatchWindow(ClockUtil.getCurrentTime(), commandContext.getProcessEngineConfiguration()); if (currentOrNextBatchWindow != null) { return currentOrNextBatchWindow.getStart(); } else { return null; } } } }
@Test public void testHistoryConfigurationWhenBatchNotDefined() { ProcessEngineConfigurationImpl processEngineConfigurationImplMock = mock(ProcessEngineConfigurationImpl.class); when(processEngine.getProcessEngineConfiguration()).thenReturn(processEngineConfigurationImplMock); when(processEngineConfigurationImplMock.getHistoryCleanupBatchWindowStartTime()).thenReturn(null); when(processEngineConfigurationImplMock.getHistoryCleanupBatchWindowEndTime()).thenReturn(null); when(processEngineConfigurationImplMock.getBatchWindowManager()).thenReturn(new DefaultBatchWindowManager()); given() .contentType(ContentType.JSON) .then().expect() .statusCode(Status.OK.getStatusCode()) .body("batchWindowStartTime", equalTo(null)) .body("batchWindowEndTime", equalTo(null)) .when() .get(CONFIGURATION_URL); }
private Date resolveDueDate(boolean isImmediatelyDue) { CommandContext commandContext = Context.getCommandContext(); if (isImmediatelyDue) { return ClockUtil.getCurrentTime(); } else { final BatchWindow currentOrNextBatchWindow = commandContext.getProcessEngineConfiguration().getBatchWindowManager() .getCurrentOrNextBatchWindow(ClockUtil.getCurrentTime(), commandContext.getProcessEngineConfiguration()); if (currentOrNextBatchWindow != null) { return currentOrNextBatchWindow.getStart(); } else { return null; } } } }
public HistoryCleanupConfigurationDto getHistoryCleanupConfiguration() { HistoryCleanupConfigurationDto configurationDto = new HistoryCleanupConfigurationDto(); final ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration(); Date now = ClockUtil.getCurrentTime(); final BatchWindow batchWindow = processEngineConfiguration.getBatchWindowManager() .getCurrentOrNextBatchWindow(now, processEngineConfiguration); if (batchWindow == null) { return configurationDto; } configurationDto.setBatchWindowStartTime(batchWindow.getStart()); configurationDto.setBatchWindowEndTime(batchWindow.getEnd()); return configurationDto; } }
@Test public void testHistoryConfigurationOutsideBatchWindow() throws ParseException { ProcessEngineConfigurationImpl processEngineConfigurationImplMock = mock(ProcessEngineConfigurationImpl.class); Date startDate = HistoryCleanupHelper.parseTimeConfiguration("23:59+0200"); Date endDate = HistoryCleanupHelper.parseTimeConfiguration("00:00+0200"); when(processEngine.getProcessEngineConfiguration()).thenReturn(processEngineConfigurationImplMock); when(processEngineConfigurationImplMock.getHistoryCleanupBatchWindowStartTime()).thenReturn("23:59+0200"); when(processEngineConfigurationImplMock.getHistoryCleanupBatchWindowEndTime()).thenReturn("00:00+0200"); when(processEngineConfigurationImplMock.getBatchWindowManager()).thenReturn(new DefaultBatchWindowManager()); SimpleDateFormat sdf = new SimpleDateFormat(JacksonConfigurator.dateFormatString); Date now = sdf.parse("2017-09-01T22:00:00.000+0200"); ClockUtil.setCurrentTime(now); Calendar today = Calendar.getInstance(); today.setTime(now); Calendar tomorrow = Calendar.getInstance(); tomorrow.setTime(DateTimeUtils.addDays(now, 1)); Date dateToday = DateTimeUtils.updateTime(today.getTime(), startDate); Date dateTomorrow = DateTimeUtils.updateTime(tomorrow.getTime(), endDate); given() .contentType(ContentType.JSON) .then().expect() .statusCode(Status.OK.getStatusCode()) .body("batchWindowStartTime", containsString(sdf.format(dateToday))) .body("batchWindowEndTime", containsString(sdf.format(dateTomorrow))) .when() .get(CONFIGURATION_URL); }
public HistoryCleanupConfigurationDto getHistoryCleanupConfiguration() { HistoryCleanupConfigurationDto configurationDto = new HistoryCleanupConfigurationDto(); final ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration(); Date now = ClockUtil.getCurrentTime(); final BatchWindow batchWindow = processEngineConfiguration.getBatchWindowManager() .getCurrentOrNextBatchWindow(now, processEngineConfiguration); if (batchWindow == null) { return configurationDto; } configurationDto.setBatchWindowStartTime(batchWindow.getStart()); configurationDto.setBatchWindowEndTime(batchWindow.getEnd()); return configurationDto; } }
@Test public void testHistoryConfigurationWithinBatchWindow() throws ParseException { ProcessEngineConfigurationImpl processEngineConfigurationImplMock = mock(ProcessEngineConfigurationImpl.class); Date startDate = HistoryCleanupHelper.parseTimeConfiguration("22:00+0200"); Date endDate = HistoryCleanupHelper.parseTimeConfiguration("23:00+0200"); when(processEngine.getProcessEngineConfiguration()).thenReturn(processEngineConfigurationImplMock); when(processEngineConfigurationImplMock.getHistoryCleanupBatchWindowStartTime()).thenReturn("22:00+0200"); when(processEngineConfigurationImplMock.getHistoryCleanupBatchWindowEndTime()).thenReturn("23:00+0200"); when(processEngineConfigurationImplMock.getBatchWindowManager()).thenReturn(new DefaultBatchWindowManager()); SimpleDateFormat sdf = new SimpleDateFormat(JacksonConfigurator.dateFormatString); Date now = sdf.parse("2017-09-01T22:00:00.000+0200"); ClockUtil.setCurrentTime(now); Calendar today = Calendar.getInstance(); today.setTime(now); Date dateToday = DateTimeUtils.updateTime(today.getTime(), startDate); Date dateTomorrow = DateTimeUtils.updateTime(today.getTime(), endDate); given() .contentType(ContentType.JSON) .then().expect() .statusCode(Status.OK.getStatusCode()) .body("batchWindowStartTime", containsString(sdf.format(dateToday))) .body("batchWindowEndTime", containsString(sdf.format(dateTomorrow))) .when() .get(CONFIGURATION_URL); }
protected void rescheduleRegularCall(CommandContext commandContext, JobEntity jobEntity) { final BatchWindow nextBatchWindow = commandContext.getProcessEngineConfiguration().getBatchWindowManager() .getNextBatchWindow(ClockUtil.getCurrentTime(), commandContext.getProcessEngineConfiguration()); if (nextBatchWindow != null) { commandContext.getJobManager().reschedule(jobEntity, nextBatchWindow.getStart()); } else { LOG.warnHistoryCleanupBatchWindowNotFound(); suspendJob(jobEntity); } }
protected void rescheduleRegularCall(CommandContext commandContext, JobEntity jobEntity) { final BatchWindow nextBatchWindow = commandContext.getProcessEngineConfiguration().getBatchWindowManager() .getNextBatchWindow(ClockUtil.getCurrentTime(), commandContext.getProcessEngineConfiguration()); if (nextBatchWindow != null) { commandContext.getJobManager().reschedule(jobEntity, nextBatchWindow.getStart()); } else { LOG.warnHistoryCleanupBatchWindowNotFound(); suspendJob(jobEntity); } }
@Test public void testHistoryCleanupJobScheduled() throws ParseException { final ProcessEngineConfigurationImpl standaloneInMemProcessEngineConfiguration = (ProcessEngineConfigurationImpl)ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration(); standaloneInMemProcessEngineConfiguration.setHistoryCleanupBatchWindowStartTime("23:00"); standaloneInMemProcessEngineConfiguration.setHistoryCleanupBatchWindowEndTime("01:00"); standaloneInMemProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:camunda" + getClass().getSimpleName() + "testHistoryCleanupJobScheduled"); ProcessEngine engine = standaloneInMemProcessEngineConfiguration .buildProcessEngine(); final List<Job> historyCleanupJobs = engine.getHistoryService().findHistoryCleanupJobs(); assertFalse(historyCleanupJobs.isEmpty()); final ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) engine.getProcessEngineConfiguration(); for (Job historyCleanupJob : historyCleanupJobs) { assertEquals(processEngineConfiguration.getBatchWindowManager().getCurrentOrNextBatchWindow(ClockUtil.getCurrentTime(), processEngineConfiguration).getStart(), historyCleanupJob.getDuedate()); } closeProcessEngine(engine); }
public static boolean isBatchWindowConfigured(CommandContext commandContext) { return commandContext.getProcessEngineConfiguration().getBatchWindowManager().isBatchWindowConfigured(commandContext.getProcessEngineConfiguration()); } }
private Date getNextRunWithinBatchWindow(Date currentTime) { return processEngineConfiguration.getBatchWindowManager().getNextBatchWindow(currentTime, processEngineConfiguration).getStart(); }
private Date resolveDueDate(boolean isImmediatelyDue) { CommandContext commandContext = Context.getCommandContext(); if (isImmediatelyDue) { return ClockUtil.getCurrentTime(); } else { final BatchWindow currentOrNextBatchWindow = commandContext.getProcessEngineConfiguration().getBatchWindowManager() .getCurrentOrNextBatchWindow(ClockUtil.getCurrentTime(), commandContext.getProcessEngineConfiguration()); if (currentOrNextBatchWindow != null) { return currentOrNextBatchWindow.getStart(); } else { return null; } } } }
public HistoryCleanupConfigurationDto getHistoryCleanupConfiguration() { HistoryCleanupConfigurationDto configurationDto = new HistoryCleanupConfigurationDto(); final ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration(); Date now = ClockUtil.getCurrentTime(); final BatchWindow batchWindow = processEngineConfiguration.getBatchWindowManager() .getCurrentOrNextBatchWindow(now, processEngineConfiguration); if (batchWindow == null) { return configurationDto; } configurationDto.setBatchWindowStartTime(batchWindow.getStart()); configurationDto.setBatchWindowEndTime(batchWindow.getEnd()); return configurationDto; } }
protected void rescheduleRegularCall(CommandContext commandContext, JobEntity jobEntity) { final BatchWindow nextBatchWindow = commandContext.getProcessEngineConfiguration().getBatchWindowManager() .getNextBatchWindow(ClockUtil.getCurrentTime(), commandContext.getProcessEngineConfiguration()); if (nextBatchWindow != null) { commandContext.getJobManager().reschedule(jobEntity, nextBatchWindow.getStart()); } else { LOG.warnHistoryCleanupBatchWindowNotFound(); suspendJob(jobEntity); } }