Skip to content

Commit

Permalink
add cron job to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
amitamrutiya committed Apr 23, 2024
1 parent fb212c0 commit cb79941
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
20 changes: 20 additions & 0 deletions backend/cron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import cron from "cron";
import https from "https";

const URL = process.env.CLOUD_BACKEND_URL;

const job = new cron.CronJob("*/14 * * * *", function () {
https
.get(URL, (res) => {
if (res.statusCode === 200) {
console.log("GET request sent successfully");
} else {
console.log("GET request failed", res.statusCode);
}
})
.on("error", (e) => {
console.error("Error while sending request", e);
});
});

export default job;
3 changes: 3 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import contactUsRoute from "./routes/contactUs.route.js"
import connectDB from "./config/database.js"
import cookieParser from "cookie-parser"
import cors from "cors"
import job from "./cron.js";
import { cloudinaryConnect } from "./config/cloudinary.js"
import fileUpload from "express-fileupload"
import dotenv from "dotenv"


dotenv.config({
path: "./env",
})

job.start();
const app = express()

// database connect
Expand Down
21 changes: 21 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"cloudinary": "^1.41.0",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"cron": "^3.1.7",
"crypto-random-string": "^5.0.0",
"dotenv": "^16.3.1",
"express": "^4.18.2",
Expand Down Expand Up @@ -50,4 +51,4 @@
"jest": "^29.7.0",
"nodemon": "^3.0.1"
}
}
}
3 changes: 3 additions & 0 deletions frontend/.netlify/state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"siteId": "2f173ab2-a27f-47ab-931e-a07e183b7690"
}

0 comments on commit cb79941

Please sign in to comment.