https://github.com/mtulio/flask-complex-sample
A complex Flask sample application that run jobs using multi thread and report some metrics
https://github.com/mtulio/flask-complex-sample
Last synced: over 1 year ago
JSON representation
A complex Flask sample application that run jobs using multi thread and report some metrics
- Host: GitHub
- URL: https://github.com/mtulio/flask-complex-sample
- Owner: mtulio
- License: apache-2.0
- Created: 2017-09-17T17:24:52.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-10-01T16:30:36.000Z (over 7 years ago)
- Last Synced: 2025-01-06T01:30:03.106Z (over 1 year ago)
- Language: Python
- Size: 16.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# flask-complex-sample
A complex Flask sample application that run asynchronous jobs using multithread and report some metrics.
[](https://hub.docker.com/r/mtulio/flask_sample/)
## Overview
This project is more an study case using Flask framework, now I'm approaching some concepts:
* Future
* Queues
* Multithread
* Metrics*
* Metrics report to Librato*
* Metrics report to Zabbix*
### Metrics (TODO)
* Keep internal metrics of all of the queues
* Keep Flask metric
* Report custom metrics to Librato
* Report custom metrics to Zabbix
## USAGE
* Install the dependencies
`make setup`
* Run the application localy
`make run`
* Run in docker
* Build
* Run
1)
`make docker-build`
2)
```bash
$ make docker-run
sudo docker run --rm -p 5000:5000 --name flask_app -d flask_app:0.2.0
c573c441dfe36c19ffc1d8c2c165bb1c9a571f9628ee9c6ed6b91dd0777af062
sleep 2 && curl http://localhost:5000/status
{
"pool": {
"_finished": {
"_count": 0,
"_max": 100
},
"_running": {
"_count": 0,
"_max": 5
},
"_waiting": {
"_count": 0,
"_max": 100
},
"manager": ""
},
"this": "",
"version": "0.2.0"
}
```
* Simple status - only counters and sys info
```bash
$ http http://localhost:5000/status
HTTP/1.0 200 OK
{
"pool": {
"_finished": {
"_count": 50,
"_max": 100
},
"_running": {
"_count": 0,
"_max": 5
},
"_waiting": {
"_count": 0,
"_max": 100
},
"manager": ""
},
"this": "",
"version": "0.1.0"
}
```
* run the sample job
```
$ http http://localhost:5000/run
HTTP/1.0 200 OK
Two jobs was launched in background!
```
* Detailed the thread status
```
http http://localhost:5000/status/details
HTTP/1.0 200 OK
{
"pool": {
"_finished": {
"_count": 1,
"_max": 100,
"list": [
{
"_args": "{'a2': 123, 'func': >, 'a1': 'aaa', 'alias': 'task2'}",
"_func": ">",
"_result": "True",
"_time": "1505690055.8564484",
"job": "",
"name": "task2"
}
]
},
"_running": {
"_count": 1,
"_max": 5,
"list": [
{
"_args": "{'func': >, 'alias': 'task1'}",
"_func": ">",
"job": "",
"name": "task1"
}
]
},
"_waiting": {
"_count": 0,
"_max": 100
},
"manager": ""
},
"this": "",
"version": "0.2.0"
}
```
* run 19 sample jobs - each run will schedulle 2 jobs, so 38 jobs will be schedulled
```bash
for X in $(seq 1 19); do http http://localhost:5000/run; done
```
* kill and remove the container
`make docker-kill`
## TODO
* Unit tests
* Converage tests