{"id":13691098,"url":"https://github.com/cofin/litestar-saq","last_synced_at":"2026-01-21T07:45:52.676Z","repository":{"id":198070198,"uuid":"700149870","full_name":"cofin/litestar-saq","owner":"cofin","description":"SAQ Plugin for Litestar","archived":false,"fork":false,"pushed_at":"2025-01-27T22:39:01.000Z","size":920,"stargazers_count":20,"open_issues_count":7,"forks_count":9,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-09T03:04:30.510Z","etag":null,"topics":["litestar","litestar-api","litestar-framework","saq"],"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/cofin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-04T03:31:02.000Z","updated_at":"2025-02-14T18:19:53.000Z","dependencies_parsed_at":"2023-10-12T13:52:08.031Z","dependency_job_id":"73ee3001-f471-4cf5-a511-ba10e559b4b3","html_url":"https://github.com/cofin/litestar-saq","commit_stats":null,"previous_names":["cofin/litestar-saq"],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cofin%2Flitestar-saq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cofin%2Flitestar-saq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cofin%2Flitestar-saq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cofin%2Flitestar-saq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cofin","download_url":"https://codeload.github.com/cofin/litestar-saq/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243841203,"owners_count":20356443,"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":["litestar","litestar-api","litestar-framework","saq"],"created_at":"2024-08-02T17:00:40.192Z","updated_at":"2026-01-21T07:45:52.663Z","avatar_url":"https://github.com/cofin.png","language":"Python","funding_links":[],"categories":["Third-Party Extensions"],"sub_categories":["General"],"readme":"# Litestar SAQ\n\n## Installation\n\n```shell\npip install litestar-saq\n```\n\nFor OpenTelemetry support:\n\n```shell\npip install litestar-saq[otel]\n```\n\n## Usage\n\nHere is a basic application that demonstrates how to use the plugin.\n\n```python\nfrom litestar import Litestar\nfrom litestar_saq import QueueConfig, SAQConfig, SAQPlugin\n\nsaq = SAQPlugin(\n    config=SAQConfig(\n        use_server_lifespan=True,\n        queue_configs=[\n            QueueConfig(name=\"samples\", dsn=\"redis://localhost:6379/0\")\n        ],\n    )\n)\napp = Litestar(plugins=[saq])\n```\n\nYou can start a background worker with the following command now:\n\n```shell\nlitestar --app-dir=examples/ --app basic:app workers run\nUsing Litestar app from env: 'basic:app'\nStarting SAQ Workers ──────────────────────────────────────────────────────────────────\nINFO - 2023-10-04 17:39:03,255 - saq - worker - Worker starting: Queue\u003credis=Redis\u003cConnectionPool\u003cConnection\u003chost=localhost,port=6379,db=0\u003e\u003e\u003e, name='samples'\u003e\nINFO - 2023-10-04 17:39:06,545 - saq - worker - Worker shutting down\n```\n\nYou can also start the process for only specific queues. This is helpful if you want separated processes working on different queues instead of combining them.\n\n```shell\nlitestar --app-dir=examples/ --app basic:app workers run --queues sample\nUsing Litestar app from env: 'basic:app'\nStarting SAQ Workers ──────────────────────────────────────────────────────────────────\nINFO - 2023-10-04 17:39:03,255 - saq - worker - Worker starting: Queue\u003credis=Redis\u003cConnectionPool\u003cConnection\u003chost=localhost,port=6379,db=0\u003e\u003e\u003e, name='samples'\u003e\nINFO - 2023-10-04 17:39:06,545 - saq - worker - Worker shutting down\n```\n\nIf you are starting the process for only specific queues and still want to read from the other queues or enqueue a task into another queue that was not initialized in your worker or is found somewhere else, you can do so like here\n\n```python\nimport os\nfrom saq import Queue\n\ndef get_queue_directly(queue_name: str, redis_url: str) -\u003e Queue:\n    return Queue.from_url(redis_url, name=queue_name)\n\nredis_url = os.getenv(\"REDIS_URL\")\nqueue = get_queue_directly(\"queue-in-other-process\", redis_url)\n\n# Get queue info\ninfo = await queue.info(jobs=True)\n\n# Enqueue new task\nawait queue.enqueue(\"task_name\", arg1=\"value1\")\n```\n\n## Monitored Jobs\n\nFor long-running tasks, use the `monitored_job` decorator to automatically send heartbeats and prevent SAQ from marking jobs as stuck:\n\n```python\nfrom litestar_saq import monitored_job\n\n@monitored_job()  # Auto-calculates interval from job.heartbeat\nasync def long_running_task(ctx):\n    await process_large_dataset()\n    return {\"status\": \"complete\"}\n\n@monitored_job(interval=30.0)  # Explicit 30-second interval\nasync def train_model(ctx, model_id: str):\n    for epoch in range(100):\n        await train_epoch(model)\n    return {\"model_id\": model_id}\n```\n\n## OpenTelemetry Integration\n\nlitestar-saq supports optional OpenTelemetry instrumentation for distributed tracing.\n\n### Configuration\n\n```python\nfrom litestar_saq import SAQConfig, QueueConfig\n\nconfig = SAQConfig(\n    queue_configs=[QueueConfig(dsn=\"redis://localhost:6379/0\")],\n    enable_otel=None,  # Auto-detect (default) - enabled if OTEL installed AND Litestar OpenTelemetryPlugin is active\n    # enable_otel=True,  # Force enable (raises error if not installed)\n    # enable_otel=False,  # Force disable\n)\n```\n\nWhen enabled, the plugin creates:\n\n- **CONSUMER spans** for job processing\n- **PRODUCER spans** for job enqueue operations\n- **Automatic context propagation** across process boundaries\n\nSpans follow [OpenTelemetry messaging semantic conventions](https://opentelemetry.io/docs/specs/semconv/messaging/) with `messaging.system = \"saq\"`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcofin%2Flitestar-saq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcofin%2Flitestar-saq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcofin%2Flitestar-saq/lists"}