️ better schedule manager

This commit is contained in:
Axel Olausson Holtenäs 2022-07-05 01:40:50 +02:00
parent 5ae6c05aef
commit 77daf24f6d
No known key found for this signature in database
GPG key ID: 7BF6826B76382CBA
2 changed files with 5 additions and 8 deletions

View file

@ -6,7 +6,7 @@ import * as event from "./event";
import * as command from "./command";
export const start = async (client: Client) => {
await database.start();
await database.connect();
await schedule.start(client);
await command.register(client);
await event.register(client);

View file

@ -8,22 +8,19 @@ import listDir from "../../helpers/listDir";
import schedule from "node-schedule";
export const start = async (client: Client) => {
logger.info("Starting schedule manager...");
logger.info("⏰ Started job management");
const jobNames = await listDir("jobs");
if (!jobNames) return logger.info("No jobs found");
if (!jobNames) return logger.warn("No available jobs found");
await Promise.all(
jobNames.map(async (jobName) => {
const job: IJob = await import(`../../jobs/${jobName}`);
schedule.scheduleJob(job.options.schedule, async () => {
logger.info(`Executed job ${jobName}!`);
logger.verbose(`⏰ Performed the job "${jobName}"`);
await job.execute(client);
});
})
).then(async () => {
const list = schedule.scheduledJobs;
logger.silly(list);
});
);
};