package com.ms.biz.task;

import com.ms.biz.common.TaskBaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.Executor;

@Configuration
@Component
@Slf4j
public class TestTaskService extends TaskBaseService {

    /**
     * 同时开启任务处理数量
     */
    public int getCorePoolSiz() {
        return 3;
    }

    /**
     * 任务管理器名称
     */
    public String getTaskExecutorName() {
        return "testTaskPool";
    }

    @Resource(name = "testTaskPool")
    protected Executor taskPool;

    @Override
    protected Executor getTaskPool() {
        return taskPool;
    }

    @Bean(name = "testTaskPool")
    @Override
    public Executor getAsyncExecutor() {
        return super.getAsyncExecutor();
    }

    @Async("testTaskPool")
    @Override
    public void runTask() {
        super.runTask();
    }

    @Override
    public Object getTask() {
        log.info("handle getTask");
        return null;
    }

    @Override
    public Object processTask(Object params) {
        log.info("handle processTask");
        try {
            Thread.sleep(1000 * 60 * 5);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return null;
    }

    @Override
    public void clearTask(Object params) {
        log.info("handle clearTask");
    }

}
