package com.ms.biz.task;

import com.ms.biz.common.TaskBaseService;
import com.ms.biz.service.DsMessageConsumerQueueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

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

/**
 * @author elf
 */
@Configuration
@Component
@Slf4j
public class DsMessageMoveBufferTaskService extends TaskBaseService {
    @Autowired
    private DsMessageConsumerQueueService dsMessageConsumerQueueService;

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

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

    @Async("dsMessageMoveBufferTaskPool")
    @Scheduled(fixedRate = 10000)
    @Override
    public void runTask() {
        super.runTask();
    }

    @Override
    public int getCorePoolSiz() {
        return 3;
    }

    @Override
    public String getTaskExecutorName() {
        return "dsMessageMoveBufferTaskPool";
    }

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

    @Override
    public Object getTask() {
        return true;
    }

    @Override
    public Object processTask(Object params) {
        return dsMessageConsumerQueueService.moveBufferToSolidRedisQueue(2000);
    }

    @Override
    public void clearTask(Object params) {
    }
}
