Java Code Examples for org.camunda.bpm.engine.runtime.Job#getRetries()

The following examples show how to use org.camunda.bpm.engine.runtime.Job#getRetries() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FoxJobRetryCmdTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void waitForExecutedJobWithRetriesLeft(int retriesLeft, String jobId) {
  JobQuery jobQuery = managementService.createJobQuery();

  if (jobId != null) {
    jobQuery.jobId(jobId);
  }

  Job job = jobQuery.singleResult();

  try {
    managementService.executeJob(job.getId());
  } catch (Exception e) {
  }

  // update job
  job = jobQuery.singleResult();

  if (job.getRetries() != retriesLeft) {
    waitForExecutedJobWithRetriesLeft(retriesLeft, jobId);
  }
}
 
Example 2
Source File: JobDto.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static JobDto fromJob(Job job) {
  JobDto dto = new JobDto();
  dto.id = job.getId();
  dto.jobDefinitionId = job.getJobDefinitionId();
  dto.processInstanceId = job.getProcessInstanceId();
  dto.processDefinitionId = job.getProcessDefinitionId();
  dto.processDefinitionKey = job.getProcessDefinitionKey();
  dto.executionId = job.getExecutionId();
  dto.exceptionMessage = job.getExceptionMessage();
  dto.failedActivityId = job.getFailedActivityId();
  dto.retries = job.getRetries();
  dto.dueDate = job.getDuedate();
  dto.suspended = job.isSuspended();
  dto.priority = job.getPriority();
  dto.tenantId = job.getTenantId();
  dto.createTime = job.getCreateTime();

  return dto;
}
 
Example 3
Source File: TestBPMModule.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public boolean areJobsAvailable() {
	List<Job> list = processEngineRule.getManagementService().createJobQuery().list();
	for (Job job : list) {
		if (!job.isSuspended() && job.getRetries() > 0
				&& (job.getDuedate() == null || ClockUtil.getCurrentTime().after(job.getDuedate()))) {
			return true;
		}
	}
	return false;
}
 
Example 4
Source File: AbstractProcessEngineTestCase.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public boolean areJobsAvailable() {
  List<Job> list = managementService.createJobQuery().list();
  for (Job job : list) {
    if (!job.isSuspended() && job.getRetries() > 0 && (job.getDuedate() == null || ClockUtil.getCurrentTime().after(job.getDuedate()))) {
      return true;
    }
  }
  return false;
}
 
Example 5
Source File: IncidentTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/IncidentTest.testShouldCreateIncidentOnFailedStartTimerEvent.bpmn"})
public void testShouldCreateIncidentOnFailedStartTimerEvent() {
  // After process start, there should be timer created
  JobQuery jobQuery = managementService.createJobQuery();
  assertEquals(1, jobQuery.count());

  Job job = jobQuery.singleResult();
  String jobId = job.getId();

  while(0 != job.getRetries()) {
    try {
      managementService.executeJob(jobId);
      fail();
    } catch (Exception e) {
      // expected
    }
    job = jobQuery.jobId(jobId).singleResult();

  }

  // job exists
  job = jobQuery.singleResult();
  assertNotNull(job);

  assertEquals(0, job.getRetries());

  // incident was created
  Incident incident = runtimeService.createIncidentQuery().configuration(job.getId()).singleResult();
  assertNotNull(incident);

  // manually delete job for timer start event
  managementService.deleteJob(job.getId());
}
 
Example 6
Source File: MigrationRemoveBoundaryEventsTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void executeJob(Job job) {
  ManagementService managementService = rule.getManagementService();

  while (job != null && job.getRetries() > 0) {
    try {
      managementService.executeJob(job.getId());
    }
    catch (Exception e) {
      // ignore
    }

    job = managementService.createJobQuery().jobId(job.getId()).singleResult();
  }
}
 
Example 7
Source File: MigrationBoundaryEventsTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void executeJob(Job job) {
  ManagementService managementService = rule.getManagementService();

  while (job != null && job.getRetries() > 0) {
    try {
      managementService.executeJob(job.getId());
    }
    catch (Exception e) {
      // ignore
    }

    job = managementService.createJobQuery().jobId(job.getId()).singleResult();
  }
}
 
Example 8
Source File: MigrationHistoricVariablesTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void executeJob(Job job) {
  ManagementService managementService = rule.getManagementService();

  while (job != null && job.getRetries() > 0) {
    try {
      managementService.executeJob(job.getId());
    }
    catch (Exception e) {
      // ignore
    }

    job = managementService.createJobQuery().jobId(job.getId()).singleResult();
  }
}
 
Example 9
Source File: ProcessInstanceModificationHistoryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void executeJob(Job job) {
  while (job != null && job.getRetries() > 0) {
    try {
      managementService.executeJob(job.getId());
    }
    catch (Exception e) {
      // ignore
    }

    job = managementService.createJobQuery().jobId(job.getId()).singleResult();
  }
}
 
Example 10
Source File: FailedJobListenerWithRetriesTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@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());
  }
}
 
Example 11
Source File: FailedJobListenerWithRetriesTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public Object execute(CommandContext commandContext) {
  Job job = getJob();
  //on last attempt the incident will be created, we imitate OLE
  if (job.getRetries() == 1) {
    countRuns++;
    if (countRuns <= failedRetriesNumber) {
      super.execute(commandContext);
      throw new OptimisticLockingException("OLE");
    }
  }
  return super.execute(commandContext);
}
 
Example 12
Source File: ProcessEngineTestRule.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected boolean areJobsAvailable() {
  List<Job> list = processEngine.getManagementService().createJobQuery().list();
  for (Job job : list) {
    if (!job.isSuspended() && job.getRetries() > 0 && (job.getDuedate() == null || ClockUtil.getCurrentTime().after(job.getDuedate()))) {
      return true;
    }
  }
  return false;
}
 
Example 13
Source File: RetryIntervalsConfigurationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private int executeJob(String processInstanceId) {
  Job job = fetchJob(processInstanceId);

  try {
    managementService.executeJob(job.getId());
  } catch (Exception e) {
    // ignore
  }

  job = fetchJob(processInstanceId);

  return job.getRetries();
}
 
Example 14
Source File: HistoricProcessInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void executeJob(Job job) {
  while (job != null && job.getRetries() > 0) {
    try {
      managementService.executeJob(job.getId());
    }
    catch (Exception e) {
      // ignore
    }

    job = managementService.createJobQuery().jobId(job.getId()).singleResult();
  }
}
 
Example 15
Source File: AbstractFoxPlatformIntegrationTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public boolean isJobAvailable(Job job) {
  return job.getRetries() > 0 && (job.getDuedate() == null || ClockUtil.getCurrentTime().after(job.getDuedate()));
}