{"id":20511301,"url":"https://github.com/intility/metroid","last_synced_at":"2025-08-22T13:45:47.650Z","repository":{"id":44643006,"uuid":"340009177","full_name":"intility/metroid","owner":"intility","description":"Metroid - Metro for Django (An async Azure Service Bus receiver, triggering task in Celery/RQ)","archived":false,"fork":false,"pushed_at":"2024-01-03T14:53:11.000Z","size":355,"stargazers_count":25,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-27T13:01:53.841Z","etag":null,"topics":["asyncio","azure-service-bus","celery","django","intility","rq"],"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/intility.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2021-02-18T10:10:01.000Z","updated_at":"2024-05-25T19:06:15.000Z","dependencies_parsed_at":"2024-11-15T20:35:44.114Z","dependency_job_id":"edb25f4b-277f-4dc3-a366-b232afcbfdec","html_url":"https://github.com/intility/metroid","commit_stats":{"total_commits":85,"total_committers":7,"mean_commits":"12.142857142857142","dds":0.3294117647058824,"last_synced_commit":"43a34b863165edcffcf92ef198101465dde01487"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intility%2Fmetroid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intility%2Fmetroid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intility%2Fmetroid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intility%2Fmetroid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/intility","download_url":"https://codeload.github.com/intility/metroid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248560483,"owners_count":21124662,"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":["asyncio","azure-service-bus","celery","django","intility","rq"],"created_at":"2024-11-15T20:35:27.477Z","updated_at":"2025-04-13T22:42:12.809Z","avatar_url":"https://github.com/intility.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003cimg src=\".github/images/intility.png\" width=\"124px\"/\u003e\u003cbr/\u003e\n  Metroid\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cem\u003eSubscribe, act, publish.\u003c/em\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://python.org\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/python-v3.10+-blue.svg\" alt=\"Python version\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://djangoproject.com\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/django-4.2+%20-blue.svg\" alt=\"Django version\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://docs.celeryproject.org/en/stable/\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/celery-5.3.0+%20-blue.svg\" alt=\"Celery version\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/servicebus/azure-servicebus\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/azure--servicebus-7.10.0+%20-blue.svg\" alt=\"ServiceBus version\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/snok/django-guid/\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/django--guid-3.2.0+-blue.svg\" alt=\"Django GUID version\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://codecov.io/gh/intility/metroid\"\u003e\n        \u003cimg src=\"https://codecov.io/gh/intility/metroid/branch/main/graph/badge.svg\" alt=\"Codecov\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/pre-commit/pre-commit\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit\u0026logoColor=white\" alt=\"Pre-commit\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/psf/black\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/code%20style-black-000000.svg\" alt=\"Black\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://mypy-lang.org\"\u003e\n        \u003cimg src=\"http://www.mypy-lang.org/static/mypy_badge.svg\" alt=\"mypy\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pycqa.github.io/isort/\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat\u0026labelColor=ef8336\" alt=\"isort\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\n# Metroid - Metro for Django\n\nThis app is intended to streamline integration with Metro for all Django+Celery users by:\n\n* Asynchronous handling of subscriptions and messages with one command\n* Execute Celery tasks based on message topics, defined in `settings.py`\n* Retry failed tasks through your admin dashboard when using the `MetroidTask` base\n\n## Overview\n* `python` \u003e= 3.10\n* `django` \u003e= 4.2 - For `asgiref`, settings\n* `django-guid` \u003e= 3.2.0 - Storing correlation IDs for failed tasks in the database, making debugging easy\n* Choose one:\n   * `celery` \u003e= 5.3.0 - Execute tasks based on a subject\n   * `django-rq` \u003e= 2.4.1 - Execute tasks based on a subject\n\n### Implementation\n\nThe `python manage.py metroid` app is fully asynchronous, and has no blocking code. It utilizes `Celery` to execute tasks.\n\nIt works by:\n1. Going through all your configured subscriptions and start a new async connection for each one of them\n2. Metro sends messages on the subscriptions\n3. This app filters out messages matching subjects you have defined, and queues a celery task to execute\n   the function as specified for that subject  \n   3.1. If no task is found for that subject, the message is marked as complete\n4. The message is marked as complete after the Celery task has successfully been queued\n5. If the task is failed, an entry is automatically created in your database\n6. All failed tasks can be retried manually through the admin dashboard\n\n\n### Configure and install this package\n\n\n\u003e **_Note_**\n\u003e For a complete example, have a look in `demoproj/settings.py`.\n\n1. Create a `METROID` key in `settings.py` with all your subscriptions and handlers.\nExample settings:\n```python\nMETROID = {\n    'subscriptions': [\n        {\n            'topic_name': 'metro-demo',\n            'subscription_name': 'sub-metrodemo-metrodemoerfett',\n            'connection_string': config('CONNECTION_STRING_METRO_DEMO', None),\n            'handlers': [\n               {\n                  'subject': 'MetroDemo/Type/GeekJokes',\n                  'regex': False,\n                  'handler_function': 'demoproj.demoapp.services.my_func'\n                }\n            ],\n        },\n    ],\n   'worker_type': 'celery', # default\n}\n```\n\nThe `handler_function` is defined by providing the full dotted path as a string. For example,`from demoproj.demoapp.services import my_func` is provided as `'demoproj.demoapp.services.my_func'`.\n\nThe handlers subject can be a regular expression or a string. If a regular expression is provided, the variable regex must be set to True. Example:\n ```python\n'handlers': [{'subject': r'^MetroDemo/Type/.*$','regex':True,'handler_function': my_func}],\n ```\n\n\n\n2. Configure `Django-GUID`  by adding the app to your installed apps, to your middlewares and configuring logging\nas described [here](https://github.com/snok/django-guid#configuration).\nMake sure you enable the [`CeleryIntegration`](https://django-guid.readthedocs.io/en/latest/integrations.html#celery):\n```python\nfrom django_guid.integrations import CeleryIntegration\n\nDJANGO_GUID = {\n    'INTEGRATIONS': [\n        CeleryIntegration(\n            use_django_logging=True,\n            log_parent=True,\n        )\n    ],\n}\n```\n\n\n#### Creating your own handler functions\n\nYour functions will be called with keyword arguments for\n\n\n`message`, `topic_name`, `subscription_name` and `subject`. You function should in other words\nlook something like this:\n\n##### Celery\n```python\n@app.task(base=MetroidTask)\ndef my_func(*, message: dict, topic_name: str, subscription_name: str, subject: str) -\u003e None:\n```\n\n##### rq\n```python\ndef my_func(*, message: dict, topic_name: str, subscription_name: str, subject: str) -\u003e None:\n```\n\n\n### Running the project\n1. Ensure you have redis running:\n```bash\ndocker-compose up\n```\n2. Run migrations\n```bash\npython manage.py migrate\n```\n3. Create an admin account\n```bash\npython manage.py createsuperuser\n```\n4. Start a worker:\n```python\ncelery -A demoproj worker -l info\n```\n5. Run the subscriber:\n```python\npython manage.py metroid\n```\n6. Send messages to Metro. Example code can be found in [`demoproj/demoapp/services.py`](demoproj/demoapp/services.py)\n7. Run the webserver:\n```python\npython manage.py runserver 8000\n```\n8. See failed messages under `http://localhost:8080/admin`\n\nTo contribute, please see [`CONTRIBUTING.md`](CONTRIBUTING.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintility%2Fmetroid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fintility%2Fmetroid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintility%2Fmetroid/lists"}