'use strict'; const Subscription = require('egg').Subscription; class Creeper extends Subscription { // 通过 schedule 属性来设置定时任务的执行间隔等配置 static get schedule() { return { cron: '0 0 23 * * ?', // 每天晚上23点执行任务 // interval: '20s', // 20秒一次 type: 'all', // 指定所有的 worker 都需要执行 }; } // subscribe 是真正定时任务执行时被运行的函数 async subscribe() { await this.service.tool.creeper(); } } module.exports = Creeper;