cron job Revision
This commit is contained in:
parent
148fa2c81c
commit
1abf623924
3 changed files with 50 additions and 10 deletions
18
src/app.ts
18
src/app.ts
|
|
@ -4,11 +4,11 @@ import cors from "cors";
|
|||
import express from "express";
|
||||
import swaggerUi from "swagger-ui-express";
|
||||
import swaggerDocument from "./swagger.json";
|
||||
import * as cron from 'node-cron';
|
||||
import * as cron from "node-cron";
|
||||
import error from "./middlewares/error";
|
||||
import { AppDataSource } from "./database/data-source";
|
||||
import { RegisterRoutes } from "./routes";
|
||||
|
||||
import { OrganizationController } from "./controllers/OrganizationController";
|
||||
|
||||
async function main() {
|
||||
await AppDataSource.initialize();
|
||||
|
|
@ -30,10 +30,16 @@ async function main() {
|
|||
app.use(error);
|
||||
const APP_HOST = process.env.APP_HOST || "0.0.0.0";
|
||||
const APP_PORT = +(process.env.APP_PORT || 3000);
|
||||
|
||||
// cron.schedule('*/10 * * * * *', () => {
|
||||
// console.log("cron job....")
|
||||
// });
|
||||
|
||||
const cronTime = "0 0 * * * *"; // ตั้งเวลาทุกวันเวลา 00:00:00
|
||||
cron.schedule(cronTime, async () => {
|
||||
try {
|
||||
const orgController = new OrganizationController();
|
||||
await orgController.cronjobRevision();
|
||||
} catch (error) {
|
||||
console.error("Error executing function from controller:", error);
|
||||
}
|
||||
});
|
||||
|
||||
// app.listen(APP_PORT, APP_HOST, () => console.log(`Listening on: http://localhost:${APP_PORT}`));
|
||||
app.listen(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue