Skip to content

Commit 7774e62

Browse files
committed
#4 Health check(done) [Support health check]
1 parent 8a4c235 commit 7774e62

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ Intro
33

44
This is a GitHub Score Application to rank repositories based on forks and starts.
55

6+
More info (Issues):
7+
8+
* https://github.com/omidraha/score/issues
69

710
Stack
811
=====
@@ -12,7 +15,7 @@ In this application we used:
1215
* Python 3.9.7
1316
* FastAPI 0.68.1
1417
* Docker 20.10.8
15-
* Docker-compose 1.26.0
18+
* Docker-compose 1.29.2
1619
* Docker-compose file version: 3.1
1720
* Gunicorn 20.1.0
1821
* uvicorn 0.15.0
@@ -76,6 +79,29 @@ Set `Environments` as previous section and then:
7679
$ docker-compose -p test run --rm web pytest
7780
```
7881

82+
83+
Health check
84+
============
85+
86+
To see health check of service, use this command:
87+
88+
```
89+
$ docker-compose -p score ps
90+
```
91+
92+
Sample output:
93+
94+
```
95+
score_web_1 /start.sh Up (healthy) 0.0.0.0:80->80/tcp,:::80->80/tcp
96+
```
97+
98+
To see logs of health check:
99+
100+
```
101+
docker inspect --format='{{json .State.Health}}' score_web_1
102+
```
103+
104+
79105
Browse
80106
======
81107

@@ -94,9 +120,11 @@ $ curl -X 'POST' 'http://127.0.0.1/score/' -H 'accept: application/json' -H 'Con
94120
TODO
95121
====
96122

97-
Cache external service API response for some short period of time for example for 1 hour in the Redis,
123+
* Cache external `GitHub` service API response for some short period of the time for example for 1 hour in the Redis,
98124
And maybe provide a new cache option for example `Cache-Control: no-cache` header to the `score` API
99125

126+
* Use async library for communicate with `Github` service API
127+
100128

101129
Extra useful links
102130
==================

docker-compose.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '3.1'
1+
version: '3.4'
22

33
services:
44
web:
@@ -8,3 +8,9 @@ services:
88
ports:
99
- '80:80'
1010
env_file: .env
11+
healthcheck:
12+
test: ./health_check.sh
13+
interval: 1m30s
14+
start_period: 10s
15+
timeout: 3s
16+
retries: 3

health_check.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bash
2+
curl --fail -s -X 'POST' 'http://127.0.0.1/score/' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{"repo":"python/cpython"}' || exit 1

0 commit comments

Comments
 (0)