⚡️ better schedule manager
This commit is contained in:
parent
5ae6c05aef
commit
77daf24f6d
2 changed files with 5 additions and 8 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue