1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- //同步七猫免费的发布时间
- const config = require("../etc/config.json");
- const mysql = require('mysql2/promise');
- 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
- });
- //先获取100本没有发布时间的七猫免费书籍
- let sql = `SELECT * FROM video_product WHERE book_platform = ${config.platform_qmmf} AND publish_time IS NULL LIMIT 500`
- console.log("sql:",sql)
- const [rows] = await connection.execute(
- sql
- );
- 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/qm_mf/qm_mf_search_book').search_id_new(video_product_info.product_id)
- if(data!=null){
- let publish_time = data.publish_time
- await connection.execute(
- `UPDATE video_product SET publish_time = ? WHERE id = ${video_product_info.id} `,[publish_time]
- );
- }else{
- await connection.execute(
- ` UPDATE video_product SET status = 0 , publish_time = '2000-01-01 01:01:01' 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, 2000);
- }
- }
- CMD.init = async function(){
- redis_help.connect((results)=>{
- if(results){
- processTask();
- }
- })
- }
- CMD.init()
|