Skip to content

Commit 3eefb47

Browse files
committed
feat: github actions script to check current lag
1 parent cf7257c commit 3eefb47

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Toolforge Check Lag
2+
on:
3+
schedule:
4+
- cron: "42 * * * *"
5+
workflow_dispatch:
6+
7+
jobs:
8+
check_lag:
9+
name: Check Lag
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
max-parallel: 4
14+
matrix:
15+
tool: ["editgroups"]
16+
17+
steps:
18+
- name: Configure SSH key
19+
uses: shimataro/ssh-key-action@v2
20+
with:
21+
key: ${{ secrets.SSH_PRIVATE_KEY }}
22+
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
23+
24+
- name: Run deployment commands
25+
uses: appleboy/[email protected]
26+
with:
27+
host: ${{ vars.SSH_HOST }}
28+
username: ${{ secrets.SSH_USER }}
29+
key: ${{ secrets.SSH_PRIVATE_KEY }}
30+
port: ${{ vars.SSH_PORT }}
31+
request_pty: true
32+
script: |
33+
set -xe
34+
become ${{ matrix.tool }} webservice python3.11 shell -- webservice-python-bootstrap
35+
become ${{ matrix.tool }} webservice python3.11 shell -- ./www/python/venv/bin/python ./www/python/src/manage.py check_lag
36+
if (( $? != 0 )); then
37+
become ${{ matrix.tool }} webservice python3.11 restart
38+
fi

store/management/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from django.core.management.base import BaseCommand
2+
from django.core.management.base import CommandError
3+
4+
from store.models import Edit
5+
6+
7+
class Command(BaseCommand):
8+
MAX_SECONDS = 3000
9+
help = f"Exits with 1 if current lag is bigger than {MAX_SECONDS} seconds"
10+
11+
def handle(self, *args, **options):
12+
lag = Edit.current_lag().total_seconds()
13+
print(f"Current lag: {lag:.2f} seconds")
14+
if lag > 3000:
15+
raise CommandError(f"Current lag is bigger than {self.MAX_SECONDS}")

0 commit comments

Comments
 (0)