package com.fdkankan.scene.download.service.impl;

import com.fdkankan.scene.download.service.ISceneDownLoadService;
import com.fdkankan.redis.constant.RedisKey;
import com.fdkankan.redis.util.RedisUtil;
import java.util.concurrent.ExecutorCompletionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author dengsixing
 * @since 2022/2/22
 **/
@Service
public class SceneDownLoadServiceImpl implements ISceneDownLoadService {

    @Value("${scene.download.threadMax:3}")
    private Integer downloadThreadMax;

    @Autowired
    RedisUtil redisUtil;

//    @Autowired
//    ExecutorCompletionService completionService;

    @Autowired
    SceneDownloadHandlerServiceImpl handlerService;


    @Override
    public void process() throws Exception {

        long downloadIngCnt = redisUtil.lGetSize(RedisKey.SCENE_DOWNLOAD_ING);
        //如果正在下载的场景大于最大线程数，不往下执行
        if(downloadIngCnt >= downloadThreadMax){
            return;
        }

        for(int i = 0; i < downloadThreadMax - downloadIngCnt; i++){
            handlerService.download();
        }

    }



}
