Skip to content

Commit 7466066

Browse files
authored
Gracefully handle connection errors when polling (#48)
* Handle common connection errors gracefully * Cleanup repository Correct readme command Add support for .env configuration Bump docker image to 3.12-alpine Fix `docker run` stop signal to avoid waiting shutdown timeout
1 parent 5797016 commit 7466066

File tree

5 files changed

+43
-14
lines changed

5 files changed

+43
-14
lines changed

.gitignore

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1+
# Virtual enviroments
12
venv/
23
.venv/
4+
5+
# Python cache
36
__pycache__/
7+
8+
# Editor configuration files
49
.idea/
510
*.iml
611
.vscode/
712
.settings/
813
.classpath
14+
15+
# Nox
16+
.nox/
17+
18+
# Container files
19+
.env
920
updated.txt
1021
config.yaml
1122
data/
12-
.nox/

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
FROM python:3.11-buster
1+
FROM python:3.12-alpine
22

33
WORKDIR /code
44

55
COPY ./runner.py ./runner.py
66
COPY ./dev-requirements/constraints.txt ./requirements.txt
77

8-
RUN pip install -Ur requirements.txt
8+
RUN pip install -Ur requirements.txt
99

10-
ENTRYPOINT python runner.py
10+
STOPSIGNAL SIGINT
11+
ENTRYPOINT ["python", "runner.py"]

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@ Polls GitHub to notify of any new commits to the API documentation, then sends i
44

55
## Running
66

7-
Run `docker-compose up -d -e 'DAPI_TRACKER_PATH'='http://discord-webhook-url-here'`.
7+
Create a file called `.env` in the root of the repository and add:
8+
9+
```
10+
DAPI_TRACKER_WEBHOOK_URL='<discord-webhook-url-here>'
11+
```
12+
13+
Then run it using `docker compose up -d`.

docker-compose.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
version: "3"
21
services:
32
poller:
43
build: .
5-
restart: always
4+
5+
restart: unless-stopped
6+
7+
env_file: .env
68
volumes:
79
- ./data:/data

runner.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,23 @@ def main(webhook_url: str, tracker_path: pathlib.Path, period: int, api_url: str
150150
last_update = _now()
151151

152152
while True:
153-
last_update = _poll(
154-
webhook_url=webhook_url,
155-
tracker_path=tracker_path,
156-
api_url=api_url,
157-
params=params_dict,
158-
last_update=last_update,
159-
)
153+
try:
154+
last_update = _poll(
155+
webhook_url=webhook_url,
156+
tracker_path=tracker_path,
157+
api_url=api_url,
158+
params=params_dict,
159+
last_update=last_update,
160+
)
161+
except (
162+
requests.exceptions.ConnectionError,
163+
requests.exceptions.Timeout,
164+
requests.exceptions.HTTPError,
165+
requests.exceptions.JSONDecodeError,
166+
requests.exceptions.InvalidJSONError,
167+
) as ex:
168+
logging.exception("Failed to fetch latest update, backing off and trying again later", exc_info=ex)
169+
160170
time.sleep(period)
161171

162172

0 commit comments

Comments
 (0)