{"id":19308702,"url":"https://github.com/mtulio/flask-complex-sample","last_synced_at":"2025-02-24T03:17:48.826Z","repository":{"id":89055263,"uuid":"103847742","full_name":"mtulio/flask-complex-sample","owner":"mtulio","description":"A complex Flask sample application that run jobs using multi thread and report some metrics","archived":false,"fork":false,"pushed_at":"2018-10-01T16:30:36.000Z","size":17,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-06T01:30:03.106Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mtulio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-17T17:24:52.000Z","updated_at":"2017-11-23T08:59:18.000Z","dependencies_parsed_at":"2023-06-13T17:53:48.711Z","dependency_job_id":null,"html_url":"https://github.com/mtulio/flask-complex-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtulio%2Fflask-complex-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtulio%2Fflask-complex-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtulio%2Fflask-complex-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtulio%2Fflask-complex-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtulio","download_url":"https://codeload.github.com/mtulio/flask-complex-sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240409852,"owners_count":19796797,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T00:16:08.779Z","updated_at":"2025-02-24T03:17:48.810Z","avatar_url":"https://github.com/mtulio.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flask-complex-sample\nA complex Flask sample application that run asynchronous jobs using multithread and report some metrics.\n\n[![Docker Build Statu](https://img.shields.io/docker/build/mtulio/flask_sample.svg)](https://hub.docker.com/r/mtulio/flask_sample/)\n\n## Overview\n\nThis project is more an study case using Flask framework, now I'm approaching some concepts:\n* Future\n* Queues\n* Multithread\n* Metrics*\n* Metrics report to Librato*\n* Metrics report to Zabbix*\n\n### Metrics (TODO)\n\n* Keep internal metrics of all of the queues\n* Keep Flask metric\n* Report custom metrics to Librato\n* Report custom metrics to Zabbix\n\n## USAGE\n\n* Install the dependencies\n\n`make setup`\n\n* Run the application localy\n\n`make run`\n\n* Run in docker\n * Build\n * Run\n\n1)\n\n`make docker-build`\n\n2)\n\n```bash\n$ make docker-run\nsudo docker run --rm -p 5000:5000 --name flask_app -d flask_app:0.2.0\nc573c441dfe36c19ffc1d8c2c165bb1c9a571f9628ee9c6ed6b91dd0777af062\nsleep 2 \u0026\u0026 curl http://localhost:5000/status\n{\n  \"pool\": {\n    \"_finished\": {\n      \"_count\": 0,\n      \"_max\": 100\n    },\n    \"_running\": {\n      \"_count\": 0,\n      \"_max\": 5\n    },\n    \"_waiting\": {\n      \"_count\": 0,\n      \"_max\": 100\n    },\n    \"manager\": \"\u003cFuture at 0x7f1b38260a90 state=running\u003e\"\n  },\n  \"this\": \"\u003cRequest 'http://localhost:5000/status' [GET]\u003e\",\n  \"version\": \"0.2.0\"\n}\n\n```\n\n* Simple status - only counters and sys info\n\n```bash\n$ http http://localhost:5000/status\nHTTP/1.0 200 OK\n\n{\n    \"pool\": {\n        \"_finished\": {\n            \"_count\": 50,\n            \"_max\": 100\n        },\n        \"_running\": {\n            \"_count\": 0,\n            \"_max\": 5\n        },\n        \"_waiting\": {\n            \"_count\": 0,\n            \"_max\": 100\n        },\n        \"manager\": \"\u003cFuture at 0x7f7f598db160 state=running\u003e\"\n    },\n    \"this\": \"\u003cRequest 'http://localhost:5000/status' [GET]\u003e\",\n    \"version\": \"0.1.0\"\n}\n```\n\n* run the sample job\n\n```\n$ http http://localhost:5000/run\nHTTP/1.0 200 OK\n\nTwo jobs was launched in background!\n\n```\n\n* Detailed the thread status\n\n```\nhttp http://localhost:5000/status/details\nHTTP/1.0 200 OK\n\n{\n   \"pool\": {\n       \"_finished\": {\n           \"_count\": 1,\n           \"_max\": 100,\n           \"list\": [\n               {\n                   \"_args\": \"{'a2': 123, 'func': \u003cbound method Tasks.run_sleep30 of \u003capp.tasks.Tasks object at 0x7fecaaabb630\u003e\u003e, 'a1': 'aaa', 'alias': 'task2'}\",\n                   \"_func\": \"\u003cbound method Tasks.run_sleep30 of \u003capp.tasks.Tasks object at 0x7fecaaabb630\u003e\u003e\",\n                   \"_result\": \"True\",\n                   \"_time\": \"1505690055.8564484\",\n                   \"job\": \"\u003cFuture at 0x7fecaaa65da0 state=finished returned bool\u003e\",\n                   \"name\": \"task2\"\n               }\n           ]\n       },\n       \"_running\": {\n           \"_count\": 1,\n           \"_max\": 5,\n           \"list\": [\n               {\n                   \"_args\": \"{'func': \u003cbound method Tasks.run_sleep15 of \u003capp.tasks.Tasks object at 0x7fecaaabb630\u003e\u003e, 'alias': 'task1'}\",\n                   \"_func\": \"\u003cbound method Tasks.run_sleep15 of \u003capp.tasks.Tasks object at 0x7fecaaabb630\u003e\u003e\",\n                   \"job\": \"\u003cFuture at 0x7fecaaa65b00 state=running\u003e\",\n                   \"name\": \"task1\"\n               }\n           ]\n       },\n       \"_waiting\": {\n           \"_count\": 0,\n           \"_max\": 100\n       },\n       \"manager\": \"\u003cFuture at 0x7fecaab28a90 state=running\u003e\"\n   },\n   \"this\": \"\u003cRequest 'http://localhost:5000/status/details' [GET]\u003e\",\n   \"version\": \"0.2.0\"\n}\n\n```\n\n* run 19 sample jobs - each run will schedulle 2 jobs, so 38 jobs will be schedulled\n\n```bash\nfor X in $(seq 1 19); do http http://localhost:5000/run; done\n```\n\n* kill and remove the container\n\n`make docker-kill`\n\n\n## TODO\n\n* Unit tests\n* Converage tests\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtulio%2Fflask-complex-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtulio%2Fflask-complex-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtulio%2Fflask-complex-sample/lists"}