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

定时任务schedule里怎么获取ctx上下文对象 #217

Open
snail-boy opened this issue Apr 24, 2024 · 0 comments
Open

定时任务schedule里怎么获取ctx上下文对象 #217

snail-boy opened this issue Apr 24, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@snail-boy
Copy link

在此输入你需要反馈的 Bug 具体信息(Bug in Detail):

'use strict';
import { IntervalParams, Schedule, ScheduleType } from '@eggjs/tegg/schedule';

@schedule({
type: ScheduleType.WORKER,
scheduleData: {
interval: 600 * 10,
}
})
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
export class onlineSchedule {
async subscribe(ctx) {
console.log(ctx, 'SSEService')
}
}

是否可以支持subscribe里默认获取ctx类似于eggjs中task参数可以拿到ctx

'use strict';
const { nowTime } = require("../utils");
module.exports = app => {
return {
schedule: {
interval: '120s', // 2分钟间隔
// cron: '0 0 0 * * ?',
type: 'all', // 指定所有的 worker 都需要执行
},
async task(ctx) {
await ctx.service.global.judgeUserExpire()
console.log('2分钟执行一次,检查退出咨询情况' + nowTime())
},
};
};

可复现问题的仓库地址(Reproduction Repo)

暂无

Node 版本号:

18.0.0

TEgg 版本号:

3.12.0

相关插件名称与版本号:

3.12.0

操作平台与版本号:

3.12.0

@snail-boy snail-boy added the bug Something isn't working label Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant