protected void decrementRetries(JobEntity job) { if (exception == null || shouldDecrementRetriesFor(exception)) { job.setRetries(job.getRetries() - 1); } }
protected void decrementRetries(JobEntity job) { if (exception == null || shouldDecrementRetriesFor(exception)) { job.setRetries(job.getRetries() - 1); } }
protected void executeCustomStrategy(CommandContext commandContext, JobEntity job, ActivityImpl activity) throws Exception { FailedJobRetryConfiguration retryConfiguration = getFailedJobRetryConfiguration(job, activity); if (retryConfiguration == null) { executeStandardStrategy(commandContext); } else { if (isFirstJobExecution(job)) { // then change default retries to the ones configured initializeRetries(job, retryConfiguration.getRetries()); } else { LOG.debugDecrementingRetriesForJob(job.getId()); } List<String> intervals = retryConfiguration.getRetryIntervals(); int intervalsCount = intervals.size(); int indexOfInterval = Math.max(0, Math.min(intervalsCount - 1, intervalsCount - (job.getRetries() - 1))); DurationHelper durationHelper = getDurationHelper(intervals.get(indexOfInterval)); job.setLockExpirationTime(durationHelper.getDateAfter()); logException(job); decrementRetries(job); notifyAcquisition(commandContext); } }
protected void executeCustomStrategy(CommandContext commandContext, JobEntity job, ActivityImpl activity) throws Exception { FailedJobRetryConfiguration retryConfiguration = getFailedJobRetryConfiguration(job, activity); if (retryConfiguration == null) { executeStandardStrategy(commandContext); } else { if (isFirstJobExecution(job)) { // then change default retries to the ones configured initializeRetries(job, retryConfiguration.getRetries()); } else { LOG.debugDecrementingRetriesForJob(job.getId()); } List<String> intervals = retryConfiguration.getRetryIntervals(); int intervalsCount = intervals.size(); int indexOfInterval = Math.max(0, Math.min(intervalsCount - 1, intervalsCount - (job.getRetries() - 1))); DurationHelper durationHelper = getDurationHelper(intervals.get(indexOfInterval)); job.setLockExpirationTime(durationHelper.getDateAfter()); logException(job); decrementRetries(job); notifyAcquisition(commandContext); } }
protected void setJobRetriesByJobId(String jobId, int retries, CommandContext commandContext) { JobEntity job = commandContext .getJobManager() .findJobById(jobId); if (job != null) { for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) { checker.checkUpdateRetriesJob(job); } if (job.isInInconsistentLockState()) { job.resetLock(); } int oldRetries = job.getRetries(); job.setRetries(retries); PropertyChange propertyChange = new PropertyChange(RETRIES, oldRetries, job.getRetries()); commandContext.getOperationLogManager().logJobOperation(getLogEntryOperation(), job.getId(), job.getJobDefinitionId(), job.getProcessInstanceId(), job.getProcessDefinitionId(), job.getProcessDefinitionKey(), propertyChange); } else { throw new ProcessEngineException("No job found with id '" + jobId + "'."); } }
protected void setJobRetriesByJobId(String jobId, int retries, CommandContext commandContext) { JobEntity job = commandContext .getJobManager() .findJobById(jobId); if (job != null) { for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) { checker.checkUpdateRetriesJob(job); } if (job.isInInconsistentLockState()) { job.resetLock(); } int oldRetries = job.getRetries(); job.setRetries(retries); PropertyChange propertyChange = new PropertyChange(RETRIES, oldRetries, job.getRetries()); commandContext.getOperationLogManager().logJobOperation(getLogEntryOperation(), job.getId(), job.getJobDefinitionId(), job.getProcessInstanceId(), job.getProcessDefinitionId(), job.getProcessDefinitionKey(), propertyChange); } else { throw new ProcessEngineException("No job found with id '" + jobId + "'."); } }
protected void decrementRetries(JobEntity job) { if (exception == null || shouldDecrementRetriesFor(exception)) { job.setRetries(job.getRetries() - 1); } }
@Test public void testHistoryCleanupJobResolveIncident() { //given String jobId = historyService.cleanUpHistoryAsync(true).getId(); imitateFailedJob(jobId); assertEquals(5, processEngineConfiguration.getDefaultNumberOfRetries()); //when //call to cleanup history means that incident was resolved jobId = historyService.cleanUpHistoryAsync(true).getId(); //then JobEntity jobEntity = getJobEntity(jobId); assertEquals(5, jobEntity.getRetries()); assertEquals(null, jobEntity.getExceptionByteArrayId()); assertEquals(null, jobEntity.getExceptionMessage()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/ManagementServiceTest.testGetJobExceptionStacktrace.bpmn20.xml"}) public void testSetJobRetriesByDefinitionUnlocksInconsistentJobs() { // given a job definition final JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult(); // and an inconsistent job that is never again picked up by a job executor CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired(); commandExecutor.execute(new Command<Void>() { @Override public Void execute(CommandContext commandContext) { JobManager jobManager = commandContext.getJobManager(); MessageEntity job = new MessageEntity(); job.setJobDefinitionId(jobDefinition.getId()); job.setJobHandlerType("any"); job.setLockOwner("owner"); job.setLockExpirationTime(ClockUtil.getCurrentTime()); job.setRetries(0); jobManager.send(job); return null; } }); // when the job retries are reset managementService.setJobRetriesByJobDefinitionId(jobDefinition.getId(), 3); // then the job can be picked up again JobEntity job = (JobEntity) managementService.createJobQuery().singleResult(); assertNotNull(job); assertNull(job.getLockOwner()); assertNull(job.getLockExpirationTime()); assertEquals(3, job.getRetries()); deleteJobAndIncidents(job); }
assertNull(job.getLockOwner()); assertNull(job.getLockExpirationTime()); assertEquals(3, job.getRetries()); assertNull(job.getLockOwner()); assertNull(job.getLockExpirationTime()); assertEquals(3, job.getRetries()); assertNotNull(job.getLockOwner()); assertNotNull(job.getLockExpirationTime()); assertEquals(3, job.getRetries());
@Test @org.camunda.bpm.engine.test.Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/IncidentTest.testShouldCreateOneIncident.bpmn"}) public void testFailedJobListenerRetries() { //given runtimeService.startProcessInstanceByKey("failingProcess"); //when the job is run several times till the incident creation Job job = getJob(); while (job.getRetries() > 0 && ((JobEntity)job).getLockOwner() == null ) { try { lockTheJob(job.getId()); engineRule.getManagementService().executeJob(job.getId()); } catch (Exception ex) { } job = getJob(); } //then JobEntity jobFinalState = (JobEntity)engineRule.getManagementService().createJobQuery().jobId(job.getId()).list().get(0); assertEquals(jobRetries, jobFinalState.getRetries()); if (jobLocked) { assertNotNull(jobFinalState.getLockOwner()); assertNotNull(jobFinalState.getLockExpirationTime()); } else { assertNull(jobFinalState.getLockOwner()); assertNull(jobFinalState.getLockExpirationTime()); } }
protected void executeCustomStrategy(CommandContext commandContext, JobEntity job, ActivityImpl activity) throws Exception { FailedJobRetryConfiguration retryConfiguration = getFailedJobRetryConfiguration(job, activity); if (retryConfiguration == null) { executeStandardStrategy(commandContext); } else { if (isFirstJobExecution(job)) { // then change default retries to the ones configured initializeRetries(job, retryConfiguration.getRetries()); } else { LOG.debugDecrementingRetriesForJob(job.getId()); } List<String> intervals = retryConfiguration.getRetryIntervals(); int intervalsCount = intervals.size(); int indexOfInterval = Math.max(0, Math.min(intervalsCount - 1, intervalsCount - (job.getRetries() - 1))); DurationHelper durationHelper = getDurationHelper(intervals.get(indexOfInterval)); job.setLockExpirationTime(durationHelper.getDateAfter()); logException(job); decrementRetries(job); notifyAcquisition(commandContext); } }
evt.setJobId(jobEntity.getId()); evt.setJobDueDate(jobEntity.getDuedate()); evt.setJobRetries(jobEntity.getRetries()); evt.setJobPriority(jobEntity.getPriority());
evt.setJobId(jobEntity.getId()); evt.setJobDueDate(jobEntity.getDuedate()); evt.setJobRetries(jobEntity.getRetries()); evt.setJobPriority(jobEntity.getPriority());
protected void setJobRetriesByJobId(String jobId, int retries, CommandContext commandContext) { JobEntity job = commandContext .getJobManager() .findJobById(jobId); if (job != null) { for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) { checker.checkUpdateJob(job); } if (job.isInInconsistentLockState()) { job.resetLock(); } int oldRetries = job.getRetries(); job.setRetries(retries); PropertyChange propertyChange = new PropertyChange(RETRIES, oldRetries, job.getRetries()); commandContext.getOperationLogManager().logJobOperation(getLogEntryOperation(), job.getId(), job.getJobDefinitionId(), job.getProcessInstanceId(), job.getProcessDefinitionId(), job.getProcessDefinitionKey(), propertyChange); } else { throw new ProcessEngineException("No job found with id '" + jobId + "'."); } }
@Test public void testHistoryCleanupJobResolveIncident() { //given String jobId = historyService.cleanUpHistoryAsync(true).getId(); imitateFailedJob(jobId); assertEquals(5, processEngineConfiguration.getDefaultNumberOfRetries()); //when //call to cleanup history means that incident was resolved jobId = historyService.cleanUpHistoryAsync(true).getId(); //then JobEntity jobEntity = getJobEntity(jobId); assertEquals(5, jobEntity.getRetries()); assertEquals(null, jobEntity.getExceptionByteArrayId()); assertEquals(null, jobEntity.getExceptionMessage()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/ManagementServiceTest.testGetJobExceptionStacktrace.bpmn20.xml"}) public void testSetJobRetriesByDefinitionUnlocksInconsistentJobs() { // given a job definition final JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult(); // and an inconsistent job that is never again picked up by a job executor CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired(); commandExecutor.execute(new Command<Void>() { @Override public Void execute(CommandContext commandContext) { JobManager jobManager = commandContext.getJobManager(); MessageEntity job = new MessageEntity(); job.setJobDefinitionId(jobDefinition.getId()); job.setJobHandlerType("any"); job.setLockOwner("owner"); job.setLockExpirationTime(ClockUtil.getCurrentTime()); job.setRetries(0); jobManager.send(job); return null; } }); // when the job retries are reset managementService.setJobRetriesByJobDefinitionId(jobDefinition.getId(), 3); // then the job can be picked up again JobEntity job = (JobEntity) managementService.createJobQuery().singleResult(); assertNotNull(job); assertNull(job.getLockOwner()); assertNull(job.getLockExpirationTime()); assertEquals(3, job.getRetries()); deleteJobAndIncidents(job); }
@Test @org.camunda.bpm.engine.test.Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/IncidentTest.testShouldCreateOneIncident.bpmn"}) public void testFailedJobListenerRetries() { //given runtimeService.startProcessInstanceByKey("failingProcess"); //when the job is run several times till the incident creation Job job = getJob(); while (job.getRetries() > 0 && ((JobEntity)job).getLockOwner() == null ) { try { lockTheJob(job.getId()); engineRule.getManagementService().executeJob(job.getId()); } catch (Exception ex) { } job = getJob(); } //then JobEntity jobFinalState = (JobEntity)engineRule.getManagementService().createJobQuery().jobId(job.getId()).list().get(0); assertEquals(jobRetries, jobFinalState.getRetries()); if (jobLocked) { assertNotNull(jobFinalState.getLockOwner()); assertNotNull(jobFinalState.getLockExpirationTime()); } else { assertNull(jobFinalState.getLockOwner()); assertNull(jobFinalState.getLockExpirationTime()); } }
assertNull(job.getLockOwner()); assertNull(job.getLockExpirationTime()); assertEquals(3, job.getRetries()); assertNull(job.getLockOwner()); assertNull(job.getLockExpirationTime()); assertEquals(3, job.getRetries()); assertNotNull(job.getLockOwner()); assertNotNull(job.getLockExpirationTime()); assertEquals(3, job.getRetries());
evt.setJobId(jobEntity.getId()); evt.setJobDueDate(jobEntity.getDuedate()); evt.setJobRetries(jobEntity.getRetries()); evt.setJobPriority(jobEntity.getPriority());