zoukankan      html  css  js  c++  java
  • node定时任务

    1.新建一个schedule文件

    2.如下代码举例

    const Subscription = require('egg').Subscription;
    const report = require('../utils/report');
    
    class SendMail extends Subscription {
      // 通过 schedule 属性来设置定时任务的执行间隔等配置
      static get schedule() {
        return {
          // interval: '1h', // 1 小时间隔
          type: 'worker', // 每台机器上只有一个 worker 会执行这个定时任务
          // immediate: true, // app ready 后立即跑一次(上线注释掉)
          cron: '0 30 10 ? * MON', // 每周一早上10点
          // cron: '0 */1 * * * ?', // 每1分钟一次
          disable: require('os').hostname() !== 'lbs-dev-monitor011015250024.center.na62',
        };
      }
    
      // subscribe 是真正定时任务执行时被运行的函数
      *subscribe() {
        const { logger, diamond } = this.ctx;
        logger.info('monitor check schedule');
        const monitorData = yield diamond.getConfig('monitor', 'lbs');
        logger.info('get cc from diamond');
    
        const feedbackMailCC = JSON.parse(monitorData).feedbackMailCC;
        yield report(new Date().getTime(), 1,feedbackMailCC, logger);
      }
    }
    
    module.exports = SendMail;

  • 相关阅读:
    oracle 12C linux centos7.5 安装 12C
    FizzBuzz
    批量判断能否telnet登录
    统计所有机器的挂载情况
    ffmpeg windows vs library 下载地址
    需求文档测试
    接口测试分析
    chrome网页截图
    不要为了测试写一个新系统
    C# 判断是否为数字
  • 原文地址:https://www.cnblogs.com/kaiqinzhang/p/11884203.html
Copyright © 2011-2022 走看看