12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 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)
- if(data!=null){
- let totalWordSize = data.words
- let totalChapterNum = data.totalChapterNum
- await connection.execute(
- `UPDATE video_product SET totalChapterNum = "${totalChapterNum}" , words = "${totalWordSize}" WHERE id = ${video_product_info.id} `
- );
- }else{
- await connection.execute(
- ` delete from video_product where id = ${video_product_info.id}; `
- );
- }
- }
- }catch(e){
- if(e==0){
- right_status = false
- }
- console.error("processTask error:",e)
- } finally{
- if(connection!=null){
- connection.end()
- }
- global.setTimeout(processTask, 20000);
- }
- }
- CMD.init = async function(){
- redis_help.connect((results)=>{
- if(results){
- processTask();
- }
- })
- }
- CMD.init()
|