Skip to content

Commit

Permalink
feat: add a health check workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
andylolz committed Aug 8, 2024
1 parent 15e6ca7 commit 6525ff1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/health_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Health check

on:
workflow_dispatch:
schedule:
- cron: "15 */12 * * *"

jobs:
health-check:
name: Health check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Poetry
uses: snok/install-poetry@v1

- name: Set up python
uses: actions/setup-python@v5
with:
python-version-file: pyproject.toml
cache: poetry

- name: Install dependencies
run: poetry install --only main

- name: Run health check
run: poetry run python -m x_notes.health_check
22 changes: 22 additions & 0 deletions x_notes/health_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import json
from datetime import datetime, timedelta, timezone
from io import BytesIO

import requests

MAX_AGE_IN_DAYS = 3


def health_check() -> None:
r = requests.get(
"https://github.com/andylolz/x-community-notes/raw/gh-pages/_data/meta.json"
)
meta = json.load(BytesIO(r.content))
delta = datetime.now(timezone.utc) - datetime.fromisoformat(meta["most_recent"])

if delta > timedelta(days=MAX_AGE_IN_DAYS):
raise Exception(f"Most recent tweet is more than {MAX_AGE_IN_DAYS} days old.")


if __name__ == "__main__":
health_check()

0 comments on commit 6525ff1

Please sign in to comment.