// agent.js
'use strict';
const _func = async agent => {
class ClusterStrategy extends agent.TimerScheduleStrategy {
async handler() {
try {
const scheduleName = this.key.replace(`${this.agent.baseDir}\\app\\schedule\\`, '');
const result = await agent.redis.set(redis_key, scheduleName, 'EX', 50, 'NX');
if (result === 'OK') {
this.sendone();
} else {
this._scheduleNext();
}
} catch (err) {
agent.loggers.exceptionLogger.info(`key: ${this.key}, err: ${err}`);
}
}
}
agent.schedule.use('schedule_name', ClusterStrategy);
}
class AppBootHook {
constructor(app) {
this.app = app;
}
async configWillLoad() {
await _func(this.app);
}
}
module.exports = AppBootHook;
Eggjs 集群环境下扩展定时任务类型 agent.js
最新推荐文章于 2023-10-30 23:36:00 发布