-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |