package com.docus.server.common.event;

import com.docus.log.executor.TrackRetrySpringExecutor;
import com.docus.log.handler.IJobHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class FlowEventListener {

    @EventListener
    @Async("threadPoolExecutor")
    public void flowListen(FlowEvent fileEvent) throws Exception {

        FlowEvent.FlowTypeEnum flowTypeEnum = fileEvent.getFlowTypeEnum();

        IJobHandler jobHandler = TrackRetrySpringExecutor.loadJobHandler(flowTypeEnum.name());

        jobHandler.execute(fileEvent.getPatientId());

    }

}
