package cn.axzo.workflow.core.engine.tx.listener;

import cn.axzo.workflow.common.model.dto.TermNodeAddTimerJobDTO;
import cn.axzo.workflow.core.engine.cmd.CustomAddTimerJobCmd;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.impl.cfg.TransactionListener;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.util.CommandContextUtil;

/**
 * 删除业务节点长时间卡住的定时处理器
 *
 * @author wangli
 * @since 2025-03-12 15:02
 */
@Slf4j
@AllArgsConstructor
public class AddTimerJobTransactionListener implements TransactionListener {
    private final TermNodeAddTimerJobDTO dto;

    @Override
    public void execute(CommandContext commandContext) {
        log.info("add timer job listener. instanceId: {}, activityId: {}, delayTime: {}, timeUnit: {}", dto.getProcessInstanceId(), dto.getActivityId(), dto.getDelayTime(), dto.getTimeUnit());
        ProcessEngineConfigurationImpl processEngineConfiguration =
                CommandContextUtil.getProcessEngineConfiguration(commandContext);
        processEngineConfiguration.getCommandExecutor().execute(new CustomAddTimerJobCmd(dto));

    }
}
