31 lines
650 B
TypeScript
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()
|
|
})
|
|
}
|
|
}
|