sync_publish_time_qm_mf.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //同步七猫免费的发布时间
  2. const config = require("../etc/config.json");
  3. const mysql = require('mysql2/promise');
  4. const taskdbConfig = config.isDebug?config.debug_task_mysql:config.release_task_mysql
  5. const redis_help = require('../src/use_redis');
  6. const CMD = {}
  7. async function processTask(){
  8. let right_status = true
  9. let connection = null
  10. try{
  11. connection = await mysql.createConnection({
  12. ...taskdbConfig,
  13. multipleStatements: true
  14. });
  15. //先获取100本没有发布时间的七猫免费书籍
  16. let sql = `SELECT * FROM video_product WHERE book_platform = ${config.platform_qmmf} AND publish_time IS NULL LIMIT 500`
  17. console.log("sql:",sql)
  18. const [rows] = await connection.execute(
  19. sql
  20. );
  21. if(rows.length<=0){
  22. throw 0
  23. }
  24. for (let index = 0; index < rows.length; index++) {
  25. let video_product_info = rows[index]
  26. let data = await require('../src/api/qm_mf/qm_mf_search_book').search_id_new(video_product_info.product_id)
  27. if(data!=null){
  28. let publish_time = data.publish_time
  29. await connection.execute(
  30. `UPDATE video_product SET publish_time = ? WHERE id = ${video_product_info.id} `,[publish_time]
  31. );
  32. }else{
  33. await connection.execute(
  34. ` UPDATE video_product SET status = 0 , publish_time = '2000-01-01 01:01:01' WHERE id = ${video_product_info.id} `
  35. );
  36. }
  37. }
  38. }catch(e){
  39. if(e==0){
  40. right_status = false
  41. }
  42. console.error("processTask error:",e)
  43. } finally{
  44. if(connection!=null){
  45. connection.end()
  46. }
  47. global.setTimeout(processTask, 2000);
  48. }
  49. }
  50. CMD.init = async function(){
  51. redis_help.connect((results)=>{
  52. if(results){
  53. processTask();
  54. }
  55. })
  56. }
  57. CMD.init()