Skip to content

Commit

Permalink
Added health check script
Browse files Browse the repository at this point in the history
  • Loading branch information
Neo-Ciber94 committed Nov 23, 2023
1 parent b620b01 commit d203678
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Scheduled Health Check

on:
workflow_dispatch:
schedule:
- cron: "0 0 */5 * *" # each 5 days

jobs:
health-check:
runs-on: ubuntu-latest

env:
HEALTHCHECK_URL: ${{ secrets.HEALTHCHECK_URL }}
HEALTHCHECK_TOKEN: ${{ secrets.HEALTHCHECK_TOKEN }}

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "18"

- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Run Health Check
run: tsx scripts/check.ts
23 changes: 23 additions & 0 deletions scripts/check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
async function main() {
const url = process.env.HEALTHCHECK_URL;

if (url == null) {
throw new Error("Healthcheck url is required");
}

const res = await fetch(url, {
headers: {
Authorization: process.env.HEALTHCHECK_TOKEN || "",
},
});

if (!res.ok) {
throw new Error(`Request failed with status ${res.status}`);
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const json = await res.json();
console.log(json);
}

main().catch(console.error);

0 comments on commit d203678

Please sign in to comment.