{"id":15442735,"url":"https://github.com/memphis-tools/dummy_flask_rabbitmq_celery","last_synced_at":"2025-08-30T17:08:56.638Z","repository":{"id":247293346,"uuid":"825469827","full_name":"memphis-tools/dummy_flask_rabbitmq_celery","owner":"memphis-tools","description":"Dummy example for Flask usage triggering celery asynchronous task","archived":false,"fork":false,"pushed_at":"2025-08-21T09:49:25.000Z","size":2688,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-21T11:52:30.787Z","etag":null,"topics":["docker","docker-swarm","flask","mongodb","nginx","python-3","rabbitmq","redis"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/memphis-tools.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2024-07-07T21:33:58.000Z","updated_at":"2025-06-23T07:57:29.000Z","dependencies_parsed_at":"2025-06-11T11:27:27.199Z","dependency_job_id":"6cea6087-3b0f-458e-9d79-3b9cbd42cb62","html_url":"https://github.com/memphis-tools/dummy_flask_rabbitmq_celery","commit_stats":{"total_commits":3,"total_committers":3,"mean_commits":1.0,"dds":0.6666666666666667,"last_synced_commit":"74d1bc5b53d1804bf6aefeaed58a270c18c3c622"},"previous_names":["memphis-tools/dummy_flask_rabbitmq_celery"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/memphis-tools/dummy_flask_rabbitmq_celery","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/memphis-tools%2Fdummy_flask_rabbitmq_celery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/memphis-tools%2Fdummy_flask_rabbitmq_celery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/memphis-tools%2Fdummy_flask_rabbitmq_celery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/memphis-tools%2Fdummy_flask_rabbitmq_celery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/memphis-tools","download_url":"https://codeload.github.com/memphis-tools/dummy_flask_rabbitmq_celery/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/memphis-tools%2Fdummy_flask_rabbitmq_celery/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272878320,"owners_count":25008336,"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","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["docker","docker-swarm","flask","mongodb","nginx","python-3","rabbitmq","redis"],"created_at":"2024-10-01T19:29:44.847Z","updated_at":"2025-08-30T17:08:56.616Z","avatar_url":"https://github.com/memphis-tools.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Screenshot](https://img.shields.io/badge/python-v3.12-blue?logo=python\u0026logoColor=yellow)\n![Screenshot](https://img.shields.io/badge/rabbitmq-v3.13.3-blue?logo=rabbitmq\u0026logoColor=yellow)\n![Screenshot](https://img.shields.io/badge/redis-v5.0.6-blue?logo=redis\u0026logoColor=yellow)\n![Screenshot](https://img.shields.io/badge/celery-v5.4.0-blue?logo=celery\u0026logoColor=yellow)\n![Screenshot](https://img.shields.io/badge/nginx-v1.27.0-blue?logo=nginx\u0026logoColor=yellow)\n![Screenshot](https://img.shields.io/badge/gunicorn-v22.0.0-blue?logo=gunicorn\u0026logoColor=yellow)\n![Screenshot](https://img.shields.io/badge/flask-v3.0.3-blue?logo=flask\u0026logoColor=yellow)\n![Screenshot](https://img.shields.io/badge/mongodb-v7.0.12-blue?logo=mongodb\u0026logoColor=yellow)\n![pylint and flake](https://github.com/memphis-tools/dummy_flask_rabbitmq_celery/actions/workflows/lint-flake.yml/badge.svg)\n![pylint](https://img.shields.io/badge/PyLint-10.00-brightgreen?logo=python\u0026logoColor=white)\n![unittest](https://github.com/memphis-tools/dummy_flask_rabbitmq_celery/actions/workflows/run_tests.yml/badge.svg)\n\n\n# DUMMY FLASK CELERY RABBITMQ REDIS APPLICATION\n\n## Prerequisites\n\nAll services of this dummy illustration micro application are served through **Docker swarm**.\n\nSet up and coding on a RedHat Linux OS based system. The following RPM should be used:\n\n    python3-docker-pycreds \u003e= 0.4.0-15\n    python3-dockerpty \u003e= 0.4.1-27\n    python3-docker \u003e= 5.0.3-3\n    python3-docker+ssh \u003e= 5.0.3-3\n    docker-compose =\u003e 1.29.2-7\n    docker-compose-plugin =\u003e 2.27.1-1\n    docker-buildx-plugin =\u003e 0.14.1-1\n    docker-ce-cli =\u003e 26.1.4-1\n    docker-ce-rootless-extras =\u003e 26.1.4-1\n    docker-ce \u003e= 26.1.4-1\n\nA running SMTP server at port 25 is required in order to have unittest tests succeeded (here postfix has been used), for a \"tests\" context.\n\nTo set a basic configuration for this service, you will use files to load environment vars: '.env.rc', '.env.rc.tests'\n\nFor the simulated \"prod\" context, suggestion is to use, for example, \u003ca href=\"https://mailtrap.io/\"\u003eMAILTRAP\u003c/a\u003e.\n\n## What is it ?\n\nA dummy application for learning purposes deployed as a stack on docker swarm.\n\nAim is to execute asynchronous process, triggered by **Flask**, executed by a **Celery worker**.\n\n**Flask** is the celery client. **Nginx** the reverse proxy to serve **Flask through Gunicorn**.\n\nTask consist to send an email with a PDF file attached.\n\nThe PDF file content is a list of dummy movies pre-inserted in a MongoDB database.\n\nFor the POC we use mailtrap to simulate email reception.\n\nA dummy Docker swarm.\n\n\u003cimg src=\"illustrations/swarm.png\" width=\"100%%\" height=\"auto\"\u003e\n\nSome dummy Flask routes.\n\n\u003cimg src=\"illustrations/flask.png\" width=\"100%%\" height=\"auto\"\u003e\n\nA dummy mailtrap account.\n\n\u003cimg src=\"illustrations/mailtrap.png\" width=\"100%%\" height=\"auto\"\u003e\n\n\n## How it works ?\n\n**Celery** workers use a default configuration.\n\n**Rabbitmq** is setup with this default configuration (we just set a specific user, password and vhost).\n\nWe have a celery worker's cluster.\n\nCelery uses 2 types of exchanges: fanout and direct.\n\nThe first one is a broadcast, which spread a task execution order, only 1 worker will execute the task.\n\nThe second one is for the celery worker to return message result to the rabbitmq queue.\n\n    rabbitmqctl list_queues -p donald_vhost name messages\n\n    rabbitmqctl list_bindings -p donald_vhost\n\n\u003cimg src=\"illustrations/rabbitmq.png\" width=\"100%%\" height=\"auto\"\u003e\n\nThe **Redis** database has a persistent volume. We can find all the transactions relative to the tasks execution from the celery workers.\n\n\u003cimg src=\"illustrations/redis.png\" width=\"100%%\" height=\"auto\"\u003e\n\nThe **MongoDB** will have a default dummy database created: \"dummy_movies\". And a dummy collection \"movies\", with 274 documents.\n\nOnce you entered the MongoDB container (replace username and password according to the ones defined in the compose file):\n\n    mongosh --username [username] --password [passord] --authenticationDatabase admin\n\n\u003cimg src=\"illustrations/mongodb.png\" width=\"100%%\" height=\"auto\"\u003e\n\nThe swarm services need several timeouts. There is a simple usage of the 'sleep' UNIX command.\n\n## How use it ?\n\nFor convenience, 2 dummy bash scripts are set. First you source either .env.rc or .env.rc.tests.\n\nExample content of a **.env.rc** file:\n\n    export SWARM_IP=\"0.0.0.0\"\n    export MONGO_INITDB_ROOT_USERNAME=admin\n    export MONGO_INITDB_ROOT_PASSWORD=SuperPassword\n    export MONGO_SERVER=localhost\n    export MONGO_PORT=27017\n    export MONGO_COLLECTION_NAME=movies\n    export MONGO_DB_NAME=dummy_movies\n\n    export RABBITMQ_DEFAULT_USER=donald\n    export RABBITMQ_DEFAULT_PASS=SuperPassword\n    export RABBITMQ_DEFAULT_VHOST=donald_vhost\n\n    export CELERY_BROKER_URL='pyamqp://donald:SuperPassword@rabbitmq:5672/donald_vhost'\n    export CELERY_RESULT_BACKEND='redis://redis:6379/0'\n    export TIMEZONE='Europe/Paris'\n\n    export MAIL_SERVER=\"sandbox.smtp.mailtrap.io\"\n    export MAIL_PORT=\"2525\"\n    export MAIL_USE_TLS=True\n    export MAIL_USERNAME=yourMailTrapUserId\n    export MAIL_PASSWORD=yourMailTrapUserPassword\n    export MAIL_SENDER=\"flask@dummy-ops.localhost\"\n\nExample content of a **.env.rc.tests** file, will just be sligthly different from the previous one, just adapt these definitions:\n\n    export MAIL_SERVER=localhost\n    export MAIL_PORT=25\n    export MAIL_USE_TLS=False\n    export MAIL_USERNAME=\"\"\n    export MAIL_PASSWORD=\"\"\n\nAs long as we start application in a \"test\" context, we run unittest.\n\nIn a production context, we do not need to source the venv and set the PYTHONPATH.\n\n    source .env.rc\n    ./start_application.sh\n\n    source venv/bin/activate\n    export PYTHONPATH=./celery_client_and_worker/app\n    source .env.rc.tests\n    ./start_application.sh -c test\n    coverage run -m unittest -v\n\nIf you want to ask for one or more docker image to be rebuild:\n\n    source .env.rc\n    ./start_application.sh -r flask\n    ./start_application.sh -r flask mongo redis\n\n    source venv/bin/activate\n    export PYTHONPATH=./celery_client_and_worker/app\n    source .env.rc.tests\n    ./start_application.sh -c test -r flask\n    ./start_application.sh -c test -r flask mongo redis\n    coverage run -m unittest -v\n\nNotice: as celery worker tasks test involved to send a mail, you need a MTA service running at port 25 (postfix for example).\n\nTo stop the application only run:\n\n    ./stop_application.sh\n\n## How lint it ?\n\n    pylint celery_client_and_worker/ mongodb/\n\n    flake8 celery_client_and_worker/ mongodb/ --max-line-length=127 --count --statistics\n\n## Usefull links\n\nLearn rabbitmq: https://www.rabbitmq.com/tutorials\n\nFor the PDF creation: https://docs.reportlab.com/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmemphis-tools%2Fdummy_flask_rabbitmq_celery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmemphis-tools%2Fdummy_flask_rabbitmq_celery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmemphis-tools%2Fdummy_flask_rabbitmq_celery/lists"}