Cronjob SalaryPeriod

This commit is contained in:
Bright 2024-02-28 13:16:01 +07:00
parent b93fb6c1e5
commit 382866d1cd
2 changed files with 56 additions and 1 deletions

View file

@ -8,6 +8,7 @@ import * as cron from "node-cron";
import error from "./middlewares/error";
import { AppDataSource } from "./database/data-source";
import { RegisterRoutes } from "./routes";
import { SalaryPeriodController } from "./controllers/SalaryPeriodController";
async function main() {
await AppDataSource.initialize();
@ -25,11 +26,20 @@ async function main() {
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
RegisterRoutes(app);
app.use(error);
const APP_HOST = process.env.APP_HOST || "0.0.0.0";
const APP_PORT = +(process.env.APP_PORT || 3000);
const cronTime = "0 1 * * *"; // ตั้งเวลาทุกวันเวลา 01:00:00
cron.schedule(cronTime, async () => {
try {
const salaryPeriod = new SalaryPeriodController();
await salaryPeriod.CronjobSalaryPeriod();
} catch (error) {
console.error("Error executing function from controller:", error);
}
});
app.listen(
APP_PORT,
APP_HOST,