-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'egg-ts-mongoose-template' of https://github.com/liangwe…
…i0101/egg-demo into egg-ts-mongoose-template # Conflicts: # app/schedule/addUserJob.ts
- Loading branch information
Showing
3 changed files
with
25 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,24 @@ | ||
|
||
import { Subscription } from 'egg' | ||
import { UserModel } from '../model/User' | ||
|
||
/** | ||
* 间隔时间段,定时任务测试 | ||
*/ | ||
export default class AddUserJob extends Subscription { | ||
|
||
static get schedule() { | ||
return { | ||
interval: '10m', // 60s 分钟间隔 | ||
interval: '60s', // 60s 间隔 | ||
type: 'all', // 指定所有的 worker 都需要执行 | ||
}; | ||
} | ||
|
||
// subscribe 是真正定时任务执行时被运行的函数 | ||
async subscribe() { | ||
console.log('我是60s执行一次的定时任务!!' + new Date()) | ||
const ctx = this.ctx; | ||
|
||
const user = new UserModel(); | ||
user.userName = 'add user'; | ||
user.userNo = Math.floor(Math.random()*10); | ||
console.log('====================') | ||
console.log(user) | ||
console.log('====================') | ||
const aa = await user.save(); | ||
console.log('====================1') | ||
console.log(aa) | ||
console.log('====================1') | ||
console.log('每60s执行一次增加User的定时任务!!' + new Date()) | ||
|
||
const test = await ctx.service.user.addUserByScheduleTest(); | ||
|
||
console.log(test) | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters