const Subscription = require("egg").Subscription;
|
|
class autoTask extends Subscription {
|
// 通过 schedule 属性来设置定时任务的执行间隔等配置
|
static get schedule() {
|
return {
|
immediate: false,
|
disable: true,
|
interval: "6s", // 10秒钟间隔
|
type: "worker" // 指定所有的 worker 都需要执行
|
};
|
}
|
|
// subscribe 是真正定时任务执行时被运行的函数
|
async subscribe() {
|
this.doUrl();
|
}
|
|
async doUrl() {
|
let log = this.ctx.getLogger("scheduleLogger");
|
log.info("start-执行作业开始...");
|
// // 执行
|
let res = await this.ctx.curl("http://127.0.0.1:7001/api/task/start", {
|
dataType: "json",
|
timeout: 60 * 1000 // 1分钟超时
|
});
|
log.info("start-执行作业结束" + JSON.stringify(res.data));
|
|
log.info("start-执行作业开始...");
|
// // 执行
|
res = await this.ctx.curl("http://127.0.0.1:7001/api/task/doStep", {
|
dataType: "json",
|
timeout: 60 * 1000 // 1分钟超时
|
});
|
log.info("start-执行作业结束" + JSON.stringify(res.data));
|
}
|
}
|
|
module.exports = autoTask;
|