-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
fastApp.py
41 lines (31 loc) · 888 Bytes
/
fastApp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python
import time
from pprint import pprint
from flask import Flask, jsonify
app = Flask(__name__)
START = time.time()
health_status = True
def elapsed():
running = time.time() - START
minutes, seconds = divmod(running, 60)
hours, minutes = divmod(minutes, 60)
return "%d:%02d:%02d" % (hours, minutes, seconds)
@app.route('/toggle')
def toggle():
global health_status
health_status = not health_status
return jsonify(health_value=health_status)
@app.route('/health')
def health():
if health_status:
resp = jsonify(health="healthy")
resp.status_code = 200
else:
resp = jsonify(health="unhealthy")
resp.status_code = 500
return resp
@app.route('/')
def root():
return "Hello World (Python)! (up %s)\n" % elapsed()
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=8080)