egg icon indicating copy to clipboard operation
egg copied to clipboard

定时任务只执行一次,无法多次运行

Open Niefee opened this issue 3 years ago • 3 comments

Node Version:v14.16.0 Egg Version:v2.29.3 Plugin Name: "egg-mongoose": "^3.3.1", Plugin Version: Platform: Mac os

在app/schedule下新建task.js文件,保存后只会执行一次,无法多次执行。

代码如下:

const Subscription = require('egg').Subscription;

class Task extends Subscription {
  static get schedule() {
    return {
      interval: '2s',
      type: 'all',
      env: ['local'],
      disable: false,
    };
  }

  async subscribe() {
    this.ctx.logger.info('new Date():', new Date());
    console.log(new Date());
  }
}

module.exports = Task;


Niefee avatar Apr 01 '21 08:04 Niefee

我在本地测试了下,没有问题的。可以提供完整的最小复现仓库看看。

gemwuu avatar Apr 01 '21 13:04 gemwuu

原来修改interval或者cron参数,需要ctrl + c 关掉重启才能运行, 这个算bug吗 @gemwuu

Niefee avatar Apr 07 '21 03:04 Niefee

需要复现的例子 + 执行环境

hyj1991 avatar Aug 05 '21 07:08 hyj1991