creeperxts.js 659 B

12345678910111213141516171819202122
  1. 'use strict';
  2. const Subscription = require('egg').Subscription;
  3. class Creeper extends Subscription {
  4. // 通过 schedule 属性来设置定时任务的执行间隔等配置
  5. // 更改执行时间
  6. static get schedule() {
  7. return {
  8. // cron: '0 0 23 * * ?', // 每天晚上23点执行任务
  9. interval: '60s', // 1分钟执行一次
  10. type: 'worker', // 指定所有的 worker 都需要执行
  11. };
  12. }
  13. // subscribe 是真正定时任务执行时被运行的函数
  14. async subscribe() {
  15. console.log('服务器用户监控');
  16. await this.ctx.service.creeperxts.creeper(); // 服务器用户监控
  17. }
  18. }
  19. module.exports = Creeper;