Skip to main content

Redis-backed deduplication middleware for Taskiq

Project description

Taskiq Deduplication

Redis-backed deduplication middleware for Taskiq that prevents duplicate tasks from being queued or executed concurrently.

CI codecov ty uv Ruff Python 3.10+ License: MIT


Documentation: https://taskiq-deduplication.d3vyce.fr

Source Code: https://github.com/d3vyce/taskiq-deduplication


Installation

uv add "taskiq-deduplication"

Quick Start

from taskiq_redis import ListQueueBroker
from taskiq_deduplication import RedisDeduplicationMiddleware, DuplicateTaskError

broker = ListQueueBroker("redis://localhost:6379").with_middlewares(
    RedisDeduplicationMiddleware(redis_url="redis://localhost:6379"),
)

@broker.task
async def send_report(user_id: int) -> None:
    ...

# First dispatch acquires the lock — succeeds.
await send_report.kiq(user_id=42)

# Second dispatch while the first is queued or running — raises.
try:
    await send_report.kiq(user_id=42)
except DuplicateTaskError:
    pass  # already queued or running

Features

  • Sender-side deduplication — rejects duplicate tasks at dispatch time via a Redis lock, before they reach the broker.
  • Atomic lock release — lock is released on completion or error via a Lua check-and-delete; only the owning task can release its lock.
  • Configurable TTL — set a global default or override per task with the deduplication_ttl label.
  • Lock heartbeat — a background task re-extends the lock TTL while the task runs, so long-running tasks keep their lock instead of expiring mid-execution and admitting a duplicate.
  • Explicit lock key — pin any task to a fixed Redis key with deduplication_key, bypassing fingerprint computation entirely.
  • Partial fingerprint — deduplicate on a subset of kwargs with deduplication_key_fields, ignoring irrelevant arguments.
  • Per-task opt-out — disable deduplication for individual tasks with the deduplication label.
  • Startup resilience — automatic reconnection with exponential backoff if Redis is unavailable at broker startup.

License

MIT License - see LICENSE for details.

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

taskiq_deduplication-1.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

taskiq_deduplication-1.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file taskiq_deduplication-1.1.0.tar.gz.

File metadata

  • Download URL: taskiq_deduplication-1.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for taskiq_deduplication-1.1.0.tar.gz
Algorithm Hash digest
SHA256 20b05f750e7a81e6b3b4206c320a81cbbbf774f174d9c5ef1394c9a977f68753
MD5 bdbf3b718e12f5fe1056a00b42a2e0d2
BLAKE2b-256 40bb900f93ce81ff351da37e685d006c7de1671c9419339aabcaaff84579e526

See more details on using hashes here.

Provenance

The following attestation bundles were made for taskiq_deduplication-1.1.0.tar.gz:

Publisher: build-release.yml on d3vyce/taskiq-deduplication

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file taskiq_deduplication-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for taskiq_deduplication-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fbb142bdcca82dddf78f20589bb751d23847d98dfa32cdbde01612ea7fc21f09
MD5 a3ad5a415396718d0626b816fad8ea6f
BLAKE2b-256 1f1422234daa553700a1ce8356a46de2c77dbe57302099a497eba249a619f481

See more details on using hashes here.

Provenance

The following attestation bundles were made for taskiq_deduplication-1.1.0-py3-none-any.whl:

Publisher: build-release.yml on d3vyce/taskiq-deduplication

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page