update - 添加异步任务执行前的记录
This commit is contained in:
parent
f7779c0ab5
commit
6dae134aad
@ -0,0 +1,50 @@
|
||||
package cn.axzo.workflow.core.engine.job;
|
||||
|
||||
import org.flowable.job.service.JobHandler;
|
||||
import org.flowable.job.service.impl.persistence.entity.JobEntity;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 记录每个 JOB 是否被多台机器同时处理
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2024/6/28 10:28
|
||||
*/
|
||||
public abstract class AbstractJobHandler implements JobHandler {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AbstractJobHandler.class);
|
||||
|
||||
protected final void log(JobEntity job) {
|
||||
try {
|
||||
// 获取所有网络接口
|
||||
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
||||
while (interfaces.hasMoreElements()) {
|
||||
NetworkInterface iface = interfaces.nextElement();
|
||||
|
||||
// 如果是活动的,并且不是回环接口(即非本地接口)
|
||||
if (iface.isUp() && !iface.isLoopback()) {
|
||||
List<InetAddress> addresses = Collections.list(iface.getInetAddresses());
|
||||
|
||||
// 遍历每个接口上的 IP 地址
|
||||
for (InetAddress address : addresses) {
|
||||
// 检查地址是否是 IPv4 类型的,并且不是回环地址
|
||||
if (address instanceof Inet4Address && !address.isLoopbackAddress()) {
|
||||
log.warn(" current job ID: {} will be execution by IP:{}", job.getId(), address.getHostAddress());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -13,7 +13,7 @@ import org.flowable.job.service.impl.persistence.entity.JobEntity;
|
||||
import org.flowable.variable.api.delegate.VariableScope;
|
||||
|
||||
@Slf4j
|
||||
public class AsyncAbortProcessInstanceHandler implements JobHandler {
|
||||
public class AsyncAbortProcessInstanceHandler extends AbstractJobHandler implements JobHandler {
|
||||
|
||||
public static final String TYPE = "async-abort-instance";
|
||||
|
||||
@ -31,9 +31,11 @@ public class AsyncAbortProcessInstanceHandler implements JobHandler {
|
||||
@Override
|
||||
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
|
||||
log.info("AsyncAbortProcessInstanceHandler executing...,jobInfo:{}", JSONUtil.toJsonStr(job));
|
||||
log(job);
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
|
||||
BpmnProcessInstanceCancelDTO dto = JSONUtil.toBean(job.getCustomValues(), BpmnProcessInstanceCancelDTO.class);
|
||||
processEngineConfiguration.getCommandExecutor().execute(new CustomAbortProcessInstanceCmd(dto.getProcessInstanceId(), dto.getTenantId(),
|
||||
dto.getReason(), extAxHiTaskInstService));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,13 @@ import org.flowable.job.service.impl.persistence.entity.JobEntity;
|
||||
import org.flowable.task.api.Task;
|
||||
import org.flowable.variable.api.delegate.VariableScope;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.axzo.workflow.common.enums.BpmnFlowNodeType.NODE_STARTER;
|
||||
@ -23,7 +30,7 @@ import static cn.axzo.workflow.common.enums.BpmnFlowNodeType.NODE_STARTER;
|
||||
* @since 2024/4/15 22:41
|
||||
*/
|
||||
@Slf4j
|
||||
public class AsyncApproveTaskJobHandler implements JobHandler {
|
||||
public class AsyncApproveTaskJobHandler extends AbstractJobHandler implements JobHandler {
|
||||
public static final String TYPE = "async-approve-task";
|
||||
|
||||
@Override
|
||||
@ -34,6 +41,7 @@ public class AsyncApproveTaskJobHandler implements JobHandler {
|
||||
@Override
|
||||
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
|
||||
log.info("AsyncApproveTaskJobHandler executing...");
|
||||
log(job);
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration =
|
||||
CommandContextUtil.getProcessEngineConfiguration(commandContext);
|
||||
BpmnTaskAuditDTO dto = JSONUtil.toBean(job.getCustomValues(), BpmnTaskAuditDTO.class);
|
||||
@ -47,4 +55,5 @@ public class AsyncApproveTaskJobHandler implements JobHandler {
|
||||
}
|
||||
processEngineConfiguration.getCommandExecutor().execute(command);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import org.flowable.job.service.impl.persistence.entity.JobEntity;
|
||||
import org.flowable.variable.api.delegate.VariableScope;
|
||||
|
||||
@Slf4j
|
||||
public class AsyncBpmnProcessActivityJobHandler implements JobHandler {
|
||||
public class AsyncBpmnProcessActivityJobHandler extends AbstractJobHandler implements JobHandler {
|
||||
|
||||
public static final String TYPE = "async-bpmn-process-activity";
|
||||
|
||||
@ -25,6 +25,7 @@ public class AsyncBpmnProcessActivityJobHandler implements JobHandler {
|
||||
|
||||
@Override
|
||||
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
|
||||
log(job);
|
||||
activityService.executeAsyncJob(job);
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ import org.flowable.job.service.impl.persistence.entity.JobEntity;
|
||||
import org.flowable.variable.api.delegate.VariableScope;
|
||||
|
||||
@Slf4j
|
||||
public class AsyncCancelProcessInstanceHandler implements JobHandler {
|
||||
public class AsyncCancelProcessInstanceHandler extends AbstractJobHandler implements JobHandler {
|
||||
|
||||
public static final String TYPE = "async-cancel-process";
|
||||
|
||||
@ -31,6 +31,7 @@ public class AsyncCancelProcessInstanceHandler implements JobHandler {
|
||||
@Override
|
||||
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
|
||||
log.info("AsyncCancelProcessInstanceHandler executing...,jobInfo:{}", JSONUtil.toJsonStr(job));
|
||||
log(job);
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
|
||||
BpmnProcessInstanceCancelDTO dto = JSONUtil.toBean(job.getCustomValues(), BpmnProcessInstanceCancelDTO.class);
|
||||
processEngineConfiguration.getCommandExecutor().execute(new CustomCancelProcessInstanceCmd(dto.getProcessInstanceId(), dto.getTenantId(),
|
||||
|
||||
@ -14,7 +14,7 @@ import org.flowable.job.service.impl.persistence.entity.JobEntity;
|
||||
import org.flowable.variable.api.delegate.VariableScope;
|
||||
|
||||
@Slf4j
|
||||
public class AsyncCountersignUserTaskJobHandler implements JobHandler {
|
||||
public class AsyncCountersignUserTaskJobHandler extends AbstractJobHandler implements JobHandler {
|
||||
|
||||
public static final String TYPE = "async-countersign-task";
|
||||
|
||||
@ -32,6 +32,7 @@ public class AsyncCountersignUserTaskJobHandler implements JobHandler {
|
||||
@Override
|
||||
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
|
||||
log.info("AsyncCountersignUserTaskJobHandler executing...");
|
||||
log(job);
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration =
|
||||
CommandContextUtil.getProcessEngineConfiguration(commandContext);
|
||||
BpmnTaskCountersignDTO dto = JSONUtil.toBean(job.getCustomValues(), BpmnTaskCountersignDTO.class);
|
||||
|
||||
@ -23,7 +23,7 @@ import static cn.axzo.workflow.core.common.code.AsyncJobRespCode.DATA_NOT_EXISTS
|
||||
* @since 2024/4/29 20:22
|
||||
*/
|
||||
@Slf4j
|
||||
public class AsyncExtTaskInstJobHandler implements JobHandler {
|
||||
public class AsyncExtTaskInstJobHandler extends AbstractJobHandler implements JobHandler {
|
||||
public static final String TYPE = "async-update-ext-task-inst";
|
||||
private final ExtAxHiTaskInstService extAxHiTaskInstService;
|
||||
|
||||
@ -38,6 +38,7 @@ public class AsyncExtTaskInstJobHandler implements JobHandler {
|
||||
|
||||
@Override
|
||||
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
|
||||
log(job);
|
||||
ExtTaskInstUpdateEvent event = JSONObject.parseObject(job.getCustomValues(), ExtTaskInstUpdateEvent.class);
|
||||
String taskId = event.getTaskId();
|
||||
String processInstanceId = event.getProcessInstanceId();
|
||||
|
||||
@ -19,7 +19,7 @@ import org.flowable.variable.api.delegate.VariableScope;
|
||||
* @since 2024/4/16 11:11
|
||||
*/
|
||||
@Slf4j
|
||||
public class AsyncRejectTaskJobHandler implements JobHandler {
|
||||
public class AsyncRejectTaskJobHandler extends AbstractJobHandler implements JobHandler {
|
||||
public static final String TYPE = "async-reject-task";
|
||||
private final ExtAxHiTaskInstService extAxHiTaskInstService;
|
||||
|
||||
@ -35,6 +35,7 @@ public class AsyncRejectTaskJobHandler implements JobHandler {
|
||||
@Override
|
||||
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
|
||||
log.info("AsyncRejectTaskJobHandler executing...");
|
||||
log(job);
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration =
|
||||
CommandContextUtil.getProcessEngineConfiguration(commandContext);
|
||||
BpmnTaskAuditDTO dto = JSONUtil.toBean(job.getCustomValues(), BpmnTaskAuditDTO.class);
|
||||
|
||||
@ -12,7 +12,7 @@ import org.flowable.job.service.impl.persistence.entity.JobEntity;
|
||||
import org.flowable.variable.api.delegate.VariableScope;
|
||||
|
||||
@Slf4j
|
||||
public class AsyncTransferUserTaskJobHandler implements JobHandler {
|
||||
public class AsyncTransferUserTaskJobHandler extends AbstractJobHandler implements JobHandler {
|
||||
|
||||
public static final String TYPE = "async-transfer-task";
|
||||
|
||||
@ -24,6 +24,7 @@ public class AsyncTransferUserTaskJobHandler implements JobHandler {
|
||||
@Override
|
||||
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
|
||||
log.info("AsyncTransferUserTaskJobHandler executing...");
|
||||
log(job);
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration =
|
||||
CommandContextUtil.getProcessEngineConfiguration(commandContext);
|
||||
BpmnTaskTransferDTO dto = JSONUtil.toBean(job.getCustomValues(), BpmnTaskTransferDTO.class);
|
||||
|
||||
@ -32,7 +32,7 @@ public class CustomAsyncRunnableExceptionExceptionHandler implements AsyncRunnab
|
||||
|
||||
// Finally, Throw the exception to indicate the ExecuteAsyncJobCmd failed
|
||||
String message = "Job " + job.getId() + " failed";
|
||||
log.info(message, exception);
|
||||
log.warn(message, exception);
|
||||
|
||||
if (job instanceof AbstractRuntimeJobEntity) {
|
||||
AbstractRuntimeJobEntity runtimeJob = (AbstractRuntimeJobEntity) job;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user