当前位置:网站首页>Flowable source code comments (36) process instance migration status job processor, BPMN history cleanup job processor, external worker task completion job processor
Flowable source code comments (36) process instance migration status job processor, BPMN history cleanup job processor, external worker task completion job processor
2022-07-06 01:35:00 【jinyangjie0】
Flowable Source code address :https://github.com/flowable/flowable-engine
Flowable-6.7.2 Source code comment address :https://github.com/solojin/flowable-6.7.2-annotated
Package path :org.flowable.engine.impl.jobexecutor
ProcessInstanceMigrationStatusJobHandler Process instance migration status job processor
/** * Process instance migration status job processor */
public class ProcessInstanceMigrationStatusJobHandler extends AbstractProcessInstanceMigrationJobHandler {
// type : Process migration status
public static final String TYPE = "process-migration-status";
@Override
public String getType() {
return TYPE;
}
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
BatchService batchService = processEngineConfiguration.getBatchServiceConfiguration().getBatchService();
String batchId = getBatchIdFromHandlerCfg(configuration);
Batch batch = batchService.getBatch(batchId);
List<BatchPart> batchParts = batchService.findBatchPartsByBatchId(batchId);
int completedBatchParts = 0;
int failedBatchParts = 0;
for (BatchPart batchPart : batchParts) {
if (batchPart.getCompleteTime() != null) {
completedBatchParts++;
if (ProcessInstanceBatchMigrationResult.RESULT_FAIL.equals(batchPart.getStatus())) {
failedBatchParts++;
}
}
}
if (completedBatchParts == batchParts.size()) {
batchService.completeBatch(batch.getId(), ProcessInstanceBatchMigrationResult.STATUS_COMPLETED);
job.setRepeat(null);
} else {
if (batchParts.size() == 0) {
updateBatchStatus(batch, "No batch parts", batchService);
job.setRepeat(null);
} else {
int completedPercentage = completedBatchParts / batchParts.size() * 100;
updateBatchStatus(batch, completedPercentage + "% completed, " + failedBatchParts + " failed", batchService);
}
}
}
protected void updateBatchStatus(Batch batch, String status, BatchService batchService) {
((BatchEntity) batch).setStatus(ProcessInstanceBatchMigrationResult.STATUS_COMPLETED);
batchService.updateBatch(batch);
}
}
BpmnHistoryCleanupJobHandler BPMN History cleanup job processor
package org.flowable.engine.impl.jobexecutor;
import org.flowable.batch.api.BatchQuery;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.history.HistoricProcessInstanceQuery;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.job.service.JobHandler;
import org.flowable.job.service.impl.persistence.entity.JobEntity;
import org.flowable.variable.api.delegate.VariableScope;
/** * BPMN History cleanup job processor */
public class BpmnHistoryCleanupJobHandler implements JobHandler {
// type :BPMN History clear
public static final String TYPE = "bpmn-history-cleanup";
private static final String DEFAULT_BATCH_NAME = "Flowable BPMN History Cleanup";
@Override
public String getType() {
return TYPE;
}
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
int batchSize = processEngineConfiguration.getCleanInstancesBatchSize();
// Query the history process instance information that can be cleared , And get rid of BPMN history
HistoricProcessInstanceQuery query = processEngineConfiguration.getHistoryCleaningManager().createHistoricProcessInstanceCleaningQuery();
if (processEngineConfiguration.isCleanInstancesSequentially()) {
query.deleteSequentiallyUsingBatch(batchSize, DEFAULT_BATCH_NAME);
} else {
query.deleteInParallelUsingBatch(batchSize, DEFAULT_BATCH_NAME);
}
// Batch query , Query batch erasable information , Clear associated data
BatchQuery batchCleaningQuery = processEngineConfiguration.getHistoryCleaningManager().createBatchCleaningQuery();
if (batchCleaningQuery != null) {
batchCleaningQuery.deleteWithRelatedData();
}
}
}
ExternalWorkerTaskCompleteJobHandler External worker task completion job processor
package org.flowable.engine.impl.jobexecutor;
import java.util.List;
import org.flowable.common.engine.api.scope.ScopeTypes;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.bpmn.helper.ErrorPropagation;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.CountingEntityUtil;
import org.flowable.job.service.JobHandler;
import org.flowable.job.service.impl.persistence.entity.JobEntity;
import org.flowable.variable.api.delegate.VariableScope;
import org.flowable.variable.service.VariableService;
import org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntity;
/** * External worker task completion job processor * * @author Filip Hrisafov */
public class ExternalWorkerTaskCompleteJobHandler implements JobHandler {
// type : External workers complete
public static final String TYPE = "external-worker-complete";
@Override
public String getType() {
return TYPE;
}
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
ExecutionEntity executionEntity = (ExecutionEntity) variableScope;
// Mark external worker completion status , And clear the runtime variable information
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
VariableService variableService = processEngineConfiguration.getVariableServiceConfiguration().getVariableService();
List<VariableInstanceEntity> jobVariables = variableService.findVariableInstanceBySubScopeIdAndScopeType(executionEntity.getId(), ScopeTypes.BPMN_EXTERNAL_WORKER);
for (VariableInstanceEntity jobVariable : jobVariables) {
executionEntity.setVariable(jobVariable.getName(), jobVariable.getValue());
CountingEntityUtil.handleDeleteVariableInstanceEntityCount(jobVariable, false);
variableService.deleteVariableInstance(jobVariable);
}
if (configuration != null && configuration.startsWith("error:")) {
String errorCode;
if (configuration.length() > 6) {
errorCode = configuration.substring(6);
} else {
errorCode = null;
}
ErrorPropagation.propagateError(errorCode, executionEntity);
} else {
CommandContextUtil.getAgenda(commandContext).planTriggerExecutionOperation(executionEntity);
}
}
}
边栏推荐
- 3D视觉——4.手势识别(Gesture Recognition)入门——使用MediaPipe含单帧(Singel Frame)和实时视频(Real-Time Video)
- VMware Tools installation error: unable to automatically install vsock driver
- Cookie concept, basic use, principle, details and Chinese transmission
- Une image! Pourquoi l'école t'a - t - elle appris à coder, mais pourquoi pas...
- A Cooperative Approach to Particle Swarm Optimization
- MCU lightweight system core
- PHP error what is an error?
- A Cooperative Approach to Particle Swarm Optimization
- 3D model format summary
- General operation method of spot Silver
猜你喜欢
Idea sets the default line break for global newly created files
ORA-00030
【详细】快速实现对象映射的几种方式
Initialize MySQL database when docker container starts
[detailed] several ways to quickly realize object mapping
Electrical data | IEEE118 (including wind and solar energy)
500 lines of code to understand the principle of mecached cache client driver
[flask] official tutorial -part1: project layout, application settings, definition and database access
Redis-列表
Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
随机推荐
Force buckle 9 palindromes
A glimpse of spir-v
Mongodb problem set
Docker compose configures MySQL and realizes remote connection
[detailed] several ways to quickly realize object mapping
Flutter Doctor:Xcode 安装不完整
Netease smart enterprises enter the market against the trend, and there is a new possibility for game industrialization
[flask] obtain request information, redirect and error handling
500 lines of code to understand the principle of mecached cache client driver
DOM introduction
[flask] official tutorial -part3: blog blueprint, project installability
Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
SPIR-V初窺
基於DVWA的文件上傳漏洞測試
Basic operations of databases and tables ----- primary key constraints
Leetcode 208. Implement trie (prefix tree)
UE4 unreal engine, editor basic application, usage skills (IV)
Huawei Hrbrid interface and VLAN division based on IP
3D视觉——4.手势识别(Gesture Recognition)入门——使用MediaPipe含单帧(Singel Frame)和实时视频(Real-Time Video)
Basic operations of databases and tables ----- unique constraints