Skip to content

Commit 0bb7d06

Browse files
author
yashksaini-coder
committed
add GitHub Actions workflow to ping backend every 45 minutes
1 parent 26aaa80 commit 0bb7d06

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

.github/workflows/ping.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Keep Backend Active
2+
3+
on:
4+
schedule:
5+
- cron: '*/45 * * * *' # Runs every 45 minutes
6+
workflow_dispatch:
7+
8+
jobs:
9+
ping-backend:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v3
14+
15+
- name: Set up Node.js
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: 18
19+
20+
- name: Run ping script
21+
run: cd scripts && node ping.js ${{ secrets.BACKEND_URL }}

scripts/ping.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const args = process.argv.slice(2);
2+
3+
if (args.length < 1) {
4+
console.error("Usage: node ping.js <backend-url>");
5+
process.exit(1);
6+
}
7+
8+
const BACKEND_URL = args[0];
9+
10+
async function pingBackend() {
11+
try {
12+
const response = await fetch(BACKEND_URL, { method: "GET" });
13+
if (response.ok) {
14+
console.log("Ping successful at", new Date().toLocaleTimeString());
15+
} else {
16+
console.error("Ping failed with status:", response.status);
17+
}
18+
} catch (error) {
19+
console.error("Ping error:", error);
20+
}
21+
}
22+
23+
// Function call
24+
pingBackend();

0 commit comments

Comments
 (0)