const video_product_controllers = require('./src/data_manager/Controllers/video_product_controllers');
const config = require("./etc/config.json")
const redis_help = require('./src/use_redis');
const CMD = {}

async function processTask(){
    try{
        const result = await video_product_controllers.getProductDataByBookPlatformAndWordsZero({book_platform:config.platform_qmmf})
        console.log("result:",result)
        if(result.success){
            const product_item =  result.data;
            let qm_book_data = await require('./src/api/qm_mf/qm_mf_search_book').search_id(product_item.product_id)
            let words = 1
            if(qm_book_data==null){
                
            }else{
                words = qm_book_data.words
            }
             await video_product_controllers.updateData({id:product_item.id},{
                                 words:words
                            })
        }
    }catch(e){
        console.error("processTask error:",e)
    } finally{
        global.setTimeout(processTask, 100);
        console.log("finish all!!!!!")
    }

}

CMD.init = async function(){
    redis_help.connect((results)=>{
        if(results){
            processTask();
        }
    })
}
CMD.init()