Added cron event handler
This commit is contained in:
20
src/utils/Cron.ts
Normal file
20
src/utils/Cron.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { CronJob } from "cron"
|
||||
import path from "path"
|
||||
import fs from "fs"
|
||||
import { Cron } from "../interfaces"
|
||||
|
||||
function loadCronEvents() {
|
||||
const cronPath = path.join(__dirname, "..", "events", "cron")
|
||||
const cronFiles = fs.readdirSync(cronPath).filter(file => file.endsWith(".js"))
|
||||
|
||||
for (const file of cronFiles) {
|
||||
const filePath = path.join(cronPath, file)
|
||||
const cron: Cron = require(filePath)
|
||||
|
||||
const time = cron.time.seconds + " " + cron.time.minutes + " " + cron.time.hours + " " + cron.time.dayOfMonth + " " + cron.time.month + " " + cron.time.dayOfWeek
|
||||
|
||||
new CronJob(time, cron.execute, cron.onComplete, cron.start, cron.timeZone).start()
|
||||
}
|
||||
}
|
||||
|
||||
export { loadCronEvents }
|
||||
@@ -3,6 +3,7 @@ import config from "./Config"
|
||||
import { redis } from "./Redis"
|
||||
import { connect } from "mongoose"
|
||||
import init from "./Init"
|
||||
import { loadCronEvents } from "./Cron"
|
||||
const client = new Client()
|
||||
|
||||
export default class Illegitimate {
|
||||
@@ -10,13 +11,11 @@ export default class Illegitimate {
|
||||
|
||||
async start() {
|
||||
init()
|
||||
|
||||
client.start()
|
||||
|
||||
loadCronEvents()
|
||||
redis.on("ready", () => {
|
||||
console.log("Connected to Redis")
|
||||
})
|
||||
|
||||
connect(config.prod.mongoURI!, {}).then(() => {
|
||||
console.log("Connected to MongoDB")
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user