package cn.axzo.msg.center.notices.client.task;

import cn.axzo.msg.center.notices.common.constans.CommonConstants;
import org.slf4j.MDC;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * 任务日志模板类
 *
 * @author zhaoyong_sh
 * @see JobLoggerTemplate
 * @since 2021-05-20 19:19
 */
@Component("jobLoggerTemplate")
public class JobLoggerTemplate {

    public <T> T execute(JobLoggerCallback<T> action){
        String uuid = UUID.randomUUID().toString();
        MDC.put(CommonConstants.CTX_LOG_ID_MDC, uuid);
        try {
            return action.doInExecute();
        } finally {
            MDC.clear();
        }
    }

}
