invoke cron every min

This commit is contained in:
Kfir Dayan 2024-02-04 11:45:59 +02:00
parent 54483b96b6
commit daea0c9cfb
4 changed files with 52 additions and 8 deletions

15
dist/index.js vendored
View file

@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const GameSource_1 = __importDefault(require("./GameSource")); const GameSource_1 = __importDefault(require("./GameSource"));
const GoogleCalendar_1 = __importDefault(require("./GoogleCalendar")); const GoogleCalendar_1 = __importDefault(require("./GoogleCalendar"));
const dotenv_1 = __importDefault(require("dotenv")); const dotenv_1 = __importDefault(require("dotenv"));
const node_cron_1 = __importDefault(require("node-cron"));
dotenv_1.default.config(); dotenv_1.default.config();
class App { class App {
constructor() { constructor() {
@ -13,7 +14,7 @@ class App {
this.googleCalendar = new GoogleCalendar_1.default(); this.googleCalendar = new GoogleCalendar_1.default();
} }
async startCronJob() { async startCronJob() {
console.log("START CRON JOB"); console.log("START Haifa Reminder");
const newGamesAdded = []; const newGamesAdded = [];
await this.googleCalendar.init(); await this.googleCalendar.init();
try { try {
@ -43,7 +44,13 @@ class App {
} }
} }
const app = new App(); const app = new App();
app.startCronJob().catch((error) => { node_cron_1.default.schedule('* * * * *', () => {
console.error("Error in app:", error.message); console.log('Running startCronJob at 7:00 AM Jerusalem time');
console.log("START CRON JOB");
app.startCronJob().catch((error) => {
console.error("Error in scheduled cron job:", error.message);
});
}, {
scheduled: true,
timezone: "Asia/Jerusalem"
}); });
// app.startWebServer();

27
package-lock.json generated
View file

@ -10,12 +10,14 @@
"googleapis": "^122.0.0", "googleapis": "^122.0.0",
"moment": "^2.29.4", "moment": "^2.29.4",
"moment-timezone": "^0.5.43", "moment-timezone": "^0.5.43",
"node-cron": "^3.0.3",
"node-html-parser": "^6.1.5", "node-html-parser": "^6.1.5",
"uuid": "^9.0.0" "uuid": "^9.0.0"
}, },
"devDependencies": { "devDependencies": {
"@types/express": "^4.17.17", "@types/express": "^4.17.17",
"@types/node": "^18.15.5", "@types/node": "^18.15.5",
"@types/node-cron": "^3.0.11",
"typescript": "^5.0.3" "typescript": "^5.0.3"
} }
}, },
@ -73,6 +75,12 @@
"integrity": "sha512-Ark2WDjjZO7GmvsyFFf81MXuGTA/d6oP38anyxWOL6EREyBKAxKoFHwBhaZxCfLRLpO8JgVXwqOwSwa7jRcjew==", "integrity": "sha512-Ark2WDjjZO7GmvsyFFf81MXuGTA/d6oP38anyxWOL6EREyBKAxKoFHwBhaZxCfLRLpO8JgVXwqOwSwa7jRcjew==",
"dev": true "dev": true
}, },
"node_modules/@types/node-cron": {
"version": "3.0.11",
"resolved": "https://registry.npmjs.org/@types/node-cron/-/node-cron-3.0.11.tgz",
"integrity": "sha512-0ikrnug3/IyneSHqCBeslAhlK2aBfYek1fGo4bP4QnZPmiqSGRK+Oy7ZMisLWkesffJvQ1cqAcBnJC+8+nxIAg==",
"dev": true
},
"node_modules/@types/qs": { "node_modules/@types/qs": {
"version": "6.9.7", "version": "6.9.7",
"resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz", "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz",
@ -611,6 +619,25 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
}, },
"node_modules/node-cron": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/node-cron/-/node-cron-3.0.3.tgz",
"integrity": "sha512-dOal67//nohNgYWb+nWmg5dkFdIwDm8EpeGYMekPMrngV3637lqnX0lbUcCtgibHTz6SEz7DAIjKvKDFYCnO1A==",
"dependencies": {
"uuid": "8.3.2"
},
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/node-cron/node_modules/uuid": {
"version": "8.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
"bin": {
"uuid": "dist/bin/uuid"
}
},
"node_modules/node-fetch": { "node_modules/node-fetch": {
"version": "2.6.12", "version": "2.6.12",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz",

View file

@ -5,6 +5,7 @@
"googleapis": "^122.0.0", "googleapis": "^122.0.0",
"moment": "^2.29.4", "moment": "^2.29.4",
"moment-timezone": "^0.5.43", "moment-timezone": "^0.5.43",
"node-cron": "^3.0.3",
"node-html-parser": "^6.1.5", "node-html-parser": "^6.1.5",
"uuid": "^9.0.0" "uuid": "^9.0.0"
}, },
@ -16,6 +17,7 @@
"devDependencies": { "devDependencies": {
"@types/express": "^4.17.17", "@types/express": "^4.17.17",
"@types/node": "^18.15.5", "@types/node": "^18.15.5",
"@types/node-cron": "^3.0.11",
"typescript": "^5.0.3" "typescript": "^5.0.3"
} }
} }

View file

@ -1,6 +1,7 @@
import GameSource from "./GameSource"; import GameSource from "./GameSource";
import GoogleCalendar from "./GoogleCalendar"; import GoogleCalendar from "./GoogleCalendar";
import env from "dotenv"; import env from "dotenv";
import cron from 'node-cron';
env.config(); env.config();
@ -15,7 +16,7 @@ class App {
} }
async startCronJob() { async startCronJob() {
console.log("START CRON JOB"); console.log("START Haifa Reminder");
const newGamesAdded = []; const newGamesAdded = [];
await this.googleCalendar.init(); await this.googleCalendar.init();
try { try {
@ -50,7 +51,14 @@ class App {
const app = new App(); const app = new App();
app.startCronJob().catch((error) => {
console.error("Error in app:", error.message); cron.schedule('* * * * *', () => {
console.log('Running startCronJob at 7:00 AM Jerusalem time');
console.log("START CRON JOB");
app.startCronJob().catch((error) => {
console.error("Error in scheduled cron job:", error.message);
});
}, {
scheduled: true,
timezone: "Asia/Jerusalem"
}); });
// app.startWebServer();