Java Code Examples for org.camunda.bpm.engine.ManagementService#executeJob()

The following examples show how to use org.camunda.bpm.engine.ManagementService#executeJob() . 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: 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 2
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 3
Source File: TimerEventFactory.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void trigger(String processInstanceId) {
  ManagementService managementService = engine.getManagementService();
  Job timerJob = managementService.createJobQuery().processInstanceId(processInstanceId).activityId(activityId).singleResult();

  if (timerJob == null) {
    throw new ProcessEngineException("No job for this event found in context of process instance " + processInstanceId);
  }

  managementService.executeJob(timerJob.getId());
}
 
Example 4
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 5
Source File: SetVariablesScenario.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@DescribesScenario("setVariablesScenario")
public static ScenarioSetup createUserOperationLogEntries() {
  return new ScenarioSetup() {
    @Override
    public void execute(ProcessEngine engine, String scenarioName) {
      RuntimeService runtimeService = engine.getRuntimeService();
      ProcessInstance processInstanceWithInitialVariables = runtimeService.createProcessInstanceQuery()
          .processDefinitionKey("asyncBeforeStartProcess_712")
          .processInstanceBusinessKey("712_ProcessIntanceExecuted")
          .singleResult();
      ManagementService managementService = engine.getManagementService();
      Job firstJob = managementService.createJobQuery()
          .processDefinitionKey("asyncBeforeStartProcess_712")
          .processInstanceId(processInstanceWithInitialVariables.getId())
          .singleResult();
      try {
        managementService.executeJob(firstJob.getId());
      } catch (Exception e) {
        // ignore
      }

      ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
          .processDefinitionKey("asyncBeforeStartProcess_712")
          .processInstanceBusinessKey("7120_ProcessIntanceWithoutExecute")
          .singleResult();
      runtimeService.setVariable(processInstance.getId(), "foo", "value");
      runtimeService.setVariableLocal(processInstance.getId(), "local", "foo1");
    }
  };
}
 
Example 6
Source File: MigrationBoundaryEventsTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testMigrateTimerBoundaryEventKeepTrigger() {
  // given
  BpmnModelInstance sourceProcess = modify(ProcessModels.ONE_TASK_PROCESS)
      .activityBuilder(USER_TASK_ID)
        .boundaryEvent(BOUNDARY_ID).timerWithDuration("PT5S")
        .userTask(AFTER_BOUNDARY_TASK)
        .endEvent()
      .done();
  BpmnModelInstance targetProcess = modify(ProcessModels.ONE_TASK_PROCESS)
    .activityBuilder(USER_TASK_ID)
      .boundaryEvent(BOUNDARY_ID).timerWithDuration("PT10M")
      .userTask(AFTER_BOUNDARY_TASK)
      .endEvent()
    .done();

  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(sourceProcess);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(targetProcess);

  Map<String, String> activities = new HashMap<String, String>();
  activities.put(USER_TASK_ID, USER_TASK_ID);
  activities.put(BOUNDARY_ID, BOUNDARY_ID);

  MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
      .mapActivities(USER_TASK_ID, USER_TASK_ID)
      .mapActivities(BOUNDARY_ID, BOUNDARY_ID)
      .build();


  // when
  testHelper.createProcessInstanceAndMigrate(migrationPlan);

  // then
  testHelper.assertJobMigrated(BOUNDARY_ID, BOUNDARY_ID, TimerExecuteNestedActivityJobHandler.TYPE);

  // and it is possible to trigger the event and successfully complete the migrated instance
  ManagementService managementService = rule.getManagementService();
  Job job = managementService.createJobQuery().singleResult();

  managementService.executeJob(job.getId());
  testHelper.completeTask(AFTER_BOUNDARY_TASK);
  testHelper.assertProcessEnded(testHelper.snapshotBeforeMigration.getProcessInstanceId());
}
 
Example 7
Source File: RestartProcessIntanceWithInitialVariablesTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldRestartWithInitialVariablesJobExecutedAndSetVariablesIn713() {
  // given
  String businessKey = "7120_ProcessIntanceWithoutExecuteAndSetVariables";
  ProcessInstance processInstanceWithInitialVariables = runtimeService.createProcessInstanceQuery()
      .processInstanceBusinessKey(businessKey)
      .active()
      .singleResult();

  runtimeService.setVariable(processInstanceWithInitialVariables.getId(), "varIn713", "value");

  ManagementService managementService = engineRule.getManagementService();
  Job asyncJob = managementService.createJobQuery()
      .processDefinitionKey("asyncBeforeStartProcess_712")
      .processInstanceId(processInstanceWithInitialVariables.getId())
      .singleResult();
  try {
    managementService.executeJob(asyncJob.getId());
  } catch (Exception e) {
    // ignore
  }

  // assume
  HistoricVariableUpdateEventEntity detail = (HistoricVariableUpdateEventEntity) historyService
      .createHistoricDetailQuery()
      .processInstanceId(processInstanceWithInitialVariables.getId())
      .activityInstanceId(processInstanceWithInitialVariables.getId())
      .singleResult();

  assertTrue(detail.isInitial());

  runtimeService.deleteProcessInstance(processInstanceWithInitialVariables.getId(), "test");

  // when
  runtimeService.restartProcessInstances(processInstanceWithInitialVariables.getProcessDefinitionId())
    .startBeforeActivity("theTask")
    .processInstanceIds(processInstanceWithInitialVariables.getId())
    .initialSetOfVariables()
    .execute();

  ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery()
      .processInstanceBusinessKey(businessKey)
      .active()
      .singleResult();

  // then
  VariableInstance variableInstance = runtimeService.createVariableInstanceQuery()
      .processInstanceIdIn(restartedProcessInstance.getId()).singleResult();
  assertNotNull(variableInstance);
  assertEquals("initial3", variableInstance.getName());
  assertEquals("value1", variableInstance.getValue());

  HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery()
      .processInstanceId(restartedProcessInstance.getId())
      .singleResult();
  assertNotNull(historicVariable);
  assertEquals(restartedProcessInstance.getId(), historicVariable.getActivityInstanceId());

  detail = (HistoricVariableUpdateEventEntity) historyService.createHistoricDetailQuery()
      .processInstanceId(restartedProcessInstance.getId())
      .singleResult();

  assertFalse(detail.isInitial());
}