Updated dir structure
This commit is contained in:
37
src/utils/Events/cron.ts
Normal file
37
src/utils/Events/cron.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { CronJob } from "cron"
|
||||
import path from "path"
|
||||
import fs from "fs"
|
||||
import { Cron } from "interfaces"
|
||||
|
||||
export default 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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user