clear-task.js 867 Bytes
const dayjs = require('dayjs');
const {logger} = require('../libs/logger');
const {mysqlPool} = require('../libs/mysql');
const {sendMessage} = require('../libs/influx-report');

module.exports = async() => {
  const endTime = dayjs().subtract(3, 'day').unix();

  try {
    const records = await mysqlPool.delete('DELETE FROM `channel_sku_compare_record` WHERE `create_time` < :endTime', {
      endTime
    });

    if (records <= 0) {
      sendMessage(1, new Date().getTime() * 1000000, 'ufo-clear-error');
      logger.error(`[clear-task]删除数据失败, endTime: ${endTime}`);
    } else {
      logger.info(`[clear-task]清理成功, endTime: ${endTime}, records: ${records}`);
    }
  } catch (error) {
    sendMessage(1, new Date().getTime() * 1000000, 'ufo-clear-error');
    logger.error(`[clear-task]删除数据错误, error: ${error.stack}`);
  }
};