2

每当我需要更改流程定义时,我都必须重新部署流程定义。似乎创建了流程定义的新版本。

有没有办法可以更新现有的流程定义,而不是一直创建新版本。

如果有新版本的流程定义到位,旧流程实例会发生什么。

对上述查询的任何帮助表示赞赏。

4

2 回答 2

5

我不认为 Activiti API 提供了一种在不部署新版本的情况下替换现有流程定义的方法。

当您部署流程的新版本时,旧版本上的任何现有流程实例都会继续在旧版本上运行。

但是,SetProcessDefinitionVersionCmd您可以使用一个类来更改流程实例上的流程版本。不过,它并不“聪明”。它只是更改版本号,不会更改任何其他运行时数据,因此如果您在流程定义中进行不兼容的更改,它可能会破坏流程实例。

于 2013-10-01T14:38:27.887 回答
0

正如马特所说,您可以使用org.activiti.engine.impl.cmd.SetProcessDefinitionVersionCmd.

以下代码用于更新最新的流程定义 ID。

String PROCESS_DEFINITION_NAME = processdefID; 
DesEncrypter de = new DesEncrypter();
String password = "yourpwd";

ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
 .setJdbcUrl("database.url")
 .setJdbcUsername("database.username").setJdbcPassword("database.password")
 .setJdbcDriver("database.driver")
 .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE);

ProcessEngine processEngine = cfg.buildProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
RuntimeService runtimeService = processEngine.getRuntimeService();

ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().latestVersion()
 .processDefinitionKey(PROCESS_DEFINITION_NAME).singleResult();

if (processDefinition == null) {
 System.out.println("Cannot find Process Def ID " + PROCESS_DEFINITION_NAME);
} else {
 System.out.println("Latest Process Definition Version: " + processDefinition.getVersion());
 long counter = runtimeService.createProcessInstanceQuery().active()
  .processDefinitionKey(PROCESS_DEFINITION_NAME).count();
 List < ProcessInstance > processInstanceList = runtimeService.createProcessInstanceQuery().active()
  .processDefinitionKey(PROCESS_DEFINITION_NAME).list();

 System.out.println(counter);

 System.out.println("Total process instances: " + counter);
 System.out.println("Total process instances retrieved: " + processInstanceList.size());

 int index = 1;
 for (ProcessInstance oneInstance: processInstanceList) {
  try {
   CommandConfig commandConfig = new CommandConfig();
   // Execute the command asynchronously to prevent that
   // one error updating a process instance stops the
   // entire batch
   cfg.getAsyncExecutor().getProcessEngineConfiguration().getCommandExecutor()
    .execute(commandConfig.transactionNotSupported(), new SetProcessDefinitionVersionCmd(
     oneInstance.getId(), processDefinition.getVersion()));
   System.out.println(index++ + " - Process instance UPDATED: " + oneInstance.getId() +
    ", previous definition ID: " + oneInstance.getProcessDefinitionVersion());

  } catch (Exception e) {
   System.out.println(index++ + " - Process instance FAILED: " + oneInstance.getId() +
    ", previous definition ID: " + oneInstance.getProcessDefinitionVersion() +
    ",  Cause: " + e.getMessage());
  }
 }

 System.out.println("********* Completed Successfully. *********");
 System.in.read();

}
于 2019-12-17T04:39:05.757 回答