activity-oauth-svr/src/schedule/discord.schedule.ts
2024-01-25 15:00:11 +08:00

31 lines
650 B
TypeScript

import { singleton } from 'decorators/singleton'
import * as schedule from 'node-schedule'
import { DiscordSvr } from 'services/discord.svr';
/**
* 定时更新discord缓存
*/
@singleton
export default class DiscordSchedule {
private running: boolean = false;
async updateCache() {
if (this.running) {
return;
}
try {
this.running = true;
await new DiscordSvr().updateCache();
this.running = false;
} catch (error) {
this.running = false;
console.log(error);
}
}
scheduleAll() {
schedule.scheduleJob('*/5 * * * * *', async () => {
await this.updateCache()
})
}
}