|
@@ -1,18 +1,19 @@
|
|
|
+// src/schedule/hello.ts
|
|
|
import { Provide, Inject, Schedule, CommonSchedule } from '@midwayjs/decorator';
|
|
|
-import { Context } from 'egg';
|
|
|
+import { Context } from '@midwayjs/koa';
|
|
|
|
|
|
@Provide()
|
|
|
@Schedule({
|
|
|
- interval: 2333, // 2.333s 间隔
|
|
|
+ cron: '*/5 * * * * * *',
|
|
|
type: 'worker', // 指定某一个 worker 执行
|
|
|
})
|
|
|
-export class scheduleService implements CommonSchedule {
|
|
|
+export class HelloCron implements CommonSchedule {
|
|
|
@Inject()
|
|
|
ctx: Context;
|
|
|
|
|
|
// 定时执行的具体任务
|
|
|
async exec() {
|
|
|
- // 如果需要使用ctx,就可以 this.ctx.xxx
|
|
|
+ this.ctx.logger.error('定时任务');
|
|
|
console.log('定时任务');
|
|
|
}
|
|
|
}
|