mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2026-01-04 09:28:12 +00:00
新增分布式任务调度示例
This commit is contained in:
parent
3cf3742803
commit
f2b4d62f11
19
src/app/modules/demo/queue/demo.ts
Normal file
19
src/app/modules/demo/queue/demo.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { App, Provide } from '@midwayjs/decorator';
|
||||||
|
import { IMidwayWebApplication } from '@midwayjs/web';
|
||||||
|
import { ICoolQueue, Queue } from 'midwayjs-cool-queue';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务
|
||||||
|
*/
|
||||||
|
@Queue()
|
||||||
|
@Provide()
|
||||||
|
export abstract class DemoQueue implements ICoolQueue {
|
||||||
|
@App()
|
||||||
|
app: IMidwayWebApplication;
|
||||||
|
|
||||||
|
async data(job: any, done: any): Promise<void> {
|
||||||
|
// 这边可以执行定时任务具体的业务或队列的业务
|
||||||
|
console.log('数据', job);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/app/modules/demo/service/task.ts
Normal file
15
src/app/modules/demo/service/task.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { Provide } from '@midwayjs/decorator';
|
||||||
|
import { BaseService } from 'midwayjs-cool-core';
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
@Provide()
|
||||||
|
export class DemoTaskService extends BaseService {
|
||||||
|
/**
|
||||||
|
* 测试任务执行
|
||||||
|
*/
|
||||||
|
async test() {
|
||||||
|
// 需要登录后台任务管理配置任务
|
||||||
|
console.log('任务执行了');
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user