package com.engine.kq.timer;

import com.engine.kq.log.KQLog;
import com.engine.kq.wfset.util.SplitActionUtil;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;
import java.util.TimerTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 拆分action数据的任务
 */
public class KQTask extends TimerTask {

    private static Logger logger = LoggerFactory.getLogger(KQTask.class);
    private KQLog kqLog = new KQLog();

    @Override
    public void run() {
        boolean flag = true;
        while (flag) {
            List<KQTaskBean> list = KQQueue.pollLimitList();
            if (list == null) {
//                kqLog.info("KQTask:list is null");
                break;
            }
            try {
              SplitActionUtil splitActionUtil = new SplitActionUtil();
              splitActionUtil.handleOverTime(list);
              Thread.sleep(2000);
            } catch (Exception e) {
                StringWriter errorsWriter = new StringWriter();
                new Exception().printStackTrace(new PrintWriter(errorsWriter));
                kqLog.info(errorsWriter.toString());
                logger.error("加班数据生成失败", e);
//                break;
            }
            if (list.size() < KQQueue.getLimitNum()) {
                flag = false;
            }
        }
    }
}
