package cn.axzo.workflow.core.engine.job;

import cn.axzo.workflow.core.service.BpmnProcessActivityService;
import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.job.service.JobHandler;
import org.flowable.job.service.impl.persistence.entity.JobEntity;
import org.flowable.variable.api.delegate.VariableScope;

@Slf4j
public class AsyncBpmnProcessActivityJobHandler implements JobHandler {

    public static final String TYPE = "async-bpmn-process-activity";

    private final BpmnProcessActivityService activityService;

    public AsyncBpmnProcessActivityJobHandler(BpmnProcessActivityService activityService) {
        this.activityService = activityService;
    }

    @Override
    public String getType() {
        return TYPE;
    }

    @Override
    public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
        activityService.executeAsyncJob(job);
    }
}
