10.1 简单示例
10.2 使用活动迁移映射进行迁移
10.3 支持的流程实例迁移案例
10.4 即将提供的流程实例迁移支持
《Flowable文档大全》
When process definitions are updated with new versions, the question arises what should be done with already running process instances that are using older versions of the process definition. In case running process instances should be migrated to another process definition version, you can use the process instance migration features on the Flowable Engine.
当流程定义升级为新版本时,问题就出现了,即应如何处理使用旧版本流程定义的已运行流程实例。如果要将正在运行的流程实例迁移到另一个流程定义版本,则可以采用Flowable引擎的流程实例迁移功能。
Let’s start with a simple example to explain the basics of process instance migration in the Flowable Engine. In this simple example we use the following use case:
让我们从一个简单的示例开始,来解释流程实例在Flowable引擎中迁移的基础知识。在这个简单的示例中,我们使用以下用例:
To test if the process instance can be migrated without issues the following code can be used:
要测试流程实例是否可以无问题地迁移,可以使用以下代码:
ProcessInstanceMigrationValidationResult validationResult = runtimeService.createProcessInstanceMigrationBuilder()
.migrateToProcessDefinition(version2ProcessDef.getId())
.validateMigration(processInstanceToMigrate.getId());
boolean isMigrationValid = validationResult.isMigrationValid();
The process instance migration builder can be used to validate and, as we will see later on, migrate one or more process instances. In this case we test if the running process instance can be migrated to the new process definition version with 2 user tasks. Because the user task id didn’t change between the two process definition versions, the process instance can be migrated without any additional mapping configuration. Therefore the migration will have a migration valid boolean value of true. This means we can run the actual migration without to be expected issues.
流程实例迁移构建器可用于验证和迁移一个或多个流程实例,我们将在后面介绍。在本例中,我们测试正在运行的流程实例是否可以迁移到包含2个用户任务的新流程定义版本。由于用户任务id在两个流程定义版本之间没有变化,因此可以迁移流程实例,而无需任何其他映射配置。因此,迁移的有效布尔值为true。这意味着我们可以运行实际的迁移,而不会出现预期的问题。
ProcessInstanceMigrationValidationResult validationResult = runtimeService.createProcessInstanceMigrationBuilder()
.migrateToProcessDefinition(version2ProcessDef.getId())
.migrate(processInstanceToMigrate.getId());
After executing the migrate method, the running process instance is migrated to the new process definition (including the historic information). This means that when user task 1 is completed, user task 2 will be the next active state for the running process instance.
在执行migrate方法之后,正在运行的流程实例将迁移到新的流程定义(包括历史信息)。这意味着当用户任务1完成时,用户任务2将是正在运行的流程实例的下一个活动状态。