const config = require("../etc/config.json"); const mysql = require('mysql2/promise'); const dbConfig = config.isDebug?config.debug_mysql:config.release_mysql const taskdbConfig = config.isDebug?config.debug_task_mysql:config.release_task_mysql const redis_help = require('../src/use_redis'); const CMD = {} async function processTask(){ let right_status = true let connection = null try{ connection = await mysql.createConnection({ ...taskdbConfig, multipleStatements: true }); //先获取所有没有父id的七猫免费书籍 const [rows] = await connection.execute( `SELECT * FROM video_product WHERE book_platform = 4 AND totalChapterNum =0 LIMIT 500` ); if(rows.length<=0){ throw 0 } for (let index = 0; index < rows.length; index++) { let video_product_info = rows[index] let data = await require('../src/api/dz/dz_search_book').search_id(video_product_info.product_id) console.log("data:",data.rows[0]) let totalWordSize = data.rows[0].totalWordSize let totalChapterNum = data.rows[0].totalChapterNum await connection.execute( `UPDATE video_product SET totalChapterNum = "${totalChapterNum}" , words = "${totalWordSize}" WHERE id = ${video_product_info.id} ` ); } }catch(e){ if(e==0){ right_status = false } console.error("processTask error:",e) } finally{ if(right_status){ global.setTimeout(processTask, 1000); } } } CMD.init = async function(){ redis_help.connect((results)=>{ if(results){ processTask(); } }) } CMD.init()