Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

定时任务 #713

Closed
0-Captain opened this issue Nov 11, 2020 · 1 comment
Closed

定时任务 #713

0-Captain opened this issue Nov 11, 2020 · 1 comment
Assignees
Labels
type: bug for issue something isn't working

Comments

@0-Captain
Copy link

有个定时任务的问题,执行npm run dev的时候log显示unknown task,
复现代码:https://github.com/0-Captain/schedule
主要代码为schedule文件夹中的两个文件:

// src/schedule/s1.ts
import { CommonSchedule, Provide, Schedule } from '@midwayjs/decorator';

@Provide()
@Schedule({
  type: 'worker',
  interval: 1000,
  env: ['prod'],
  immediate: true,
})
export class Test1 implements CommonSchedule {
  async exec() {
    console.log('test1');
  }
}
// src/schedule/s2.ts
import { CommonSchedule, Provide, Schedule } from '@midwayjs/decorator';

@Provide()
@Schedule({
  type: 'worker',
  interval: 1000,
  env: ['staging'],
  immediate: true,
})
export class Test2 implements CommonSchedule {
  async exec() {
    console.log('test2');
  }
}

预期结果:
执行cross-env EGG_SERVER_ENV=staging midway-bin dev --ts,打印:test1
执行cross-env EGG_SERVER_ENV=prod midway-bin dev --ts,打印:test2

实际结果:
执行cross-env EGG_SERVER_ENV=staging midway-bin dev --ts,打印:test1
执行cross-env EGG_SERVER_ENV=prod midway-bin dev --ts,打印:无输出,查看egg-schedule.log打印unknown task

@czy88840616 czy88840616 self-assigned this Nov 12, 2020
@czy88840616 czy88840616 added the type: bug for issue something isn't working label Nov 12, 2020
@czy88840616
Copy link
Member

已修复

  • 1、执行未输出的问题,原因为 env 不匹配的时候直接 return了导致循环后面没有执行
  • 2、unknown task 是在不匹配环境的时候打的,经过测试,是egg自身的限制,纯egg应用也有此问题,不在本次 bug 范围内

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug for issue something isn't working
Development

No branches or pull requests

2 participants