Skip to content

Commit

Permalink
cron.js added
Browse files Browse the repository at this point in the history
  • Loading branch information
burakorkmez committed Mar 8, 2024
1 parent 5511331 commit c0f6acb
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
36 changes: 36 additions & 0 deletions backend/cron/cron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import cron from "cron";
import https from "https";

const URL = "https://threads-clone-9if3.onrender.com";

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;

// CRON JOB EXPLANATION:
// Cron jobs are scheduled tasks that run periodically at fixed intervals or specific times
// send 1 GET request for every 14 minutes

// Schedule:
// You define a schedule using a cron expression, which consists of five fields representing:

//! MINUTE, HOUR, DAY OF THE MONTH, MONTH, DAY OF THE WEEK

//? EXAMPLES && EXPLANATION:
//* 14 * * * * - Every 14 minutes
//* 0 0 * * 0 - At midnight on every Sunday
//* 30 3 15 * * - At 3:30 AM, on the 15th of every month
//* 0 0 1 1 * - At midnight, on January 1st
//* 0 * * * * - Every hour
42 changes: 42 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"bcryptjs": "^2.4.3",
"cloudinary": "^1.40.0",
"cookie-parser": "^1.4.6",
"cron": "^3.1.6",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"jsonwebtoken": "^9.0.1",
Expand Down

0 comments on commit c0f6acb

Please sign in to comment.