Skip to main content

Django tasks Repid backend

Project description

django-tasks-repid

A django-tasks backend powered by repid.

Requirements

  • Python 3.12+
  • Django 6.0+
  • django-tasks 0.12+
  • repid 1.6+

Installation

pip install django-tasks-repid

Configuration

Add the backend to your TASKS setting:

TASKS = {
    "default": {
        "BACKEND": "django_tasks_repid.backend.RepidBackend",
        "QUEUES": ["default"],
        "OPTIONS": {
            "BROKER": "redis://localhost:6379",
            "RESULT_BACKEND": "redis://localhost:6379",
        },
    }
}

Options

Option Description Default
BROKER Message broker DSN. Supports amqp://, redis://, valkey://. In-memory (development only)
RESULT_BACKEND Redis DSN for storing task results. Required for get_result(). None (results unavailable)

Supported brokers

Scheme Backend
amqp:// RabbitMQ
redis:// Redis
valkey:// Valkey (protocol-compatible with Redis)
(none) In-memory (single-process, non-persistent — development only)

Defining tasks

from django_tasks import task

@task()
def send_welcome_email(user_id: int) -> None:
    ...

@task()
async def generate_report(report_id: int) -> dict:
    ...

Enqueueing tasks

# Sync
result = send_welcome_email.enqueue(user_id=42)

# Async
result = await send_welcome_email.aenqueue(user_id=42)

# Deferred
from datetime import datetime, timedelta, timezone

result = send_welcome_email.using(
    run_after=datetime.now(tz=timezone.utc) + timedelta(hours=1)
).enqueue(user_id=42)

Retrieving results

get_result() and aget_result() require RESULT_BACKEND to be configured.

from django_tasks import default_task_backend

result = send_welcome_email.enqueue(user_id=42)

# Later — fetch updated status
result = default_task_backend.get_result(result.id)

if result.is_finished:
    print(result.return_value)

Running a worker

Use repid's worker to consume and execute tasks:

# worker.py
import django
django.setup()

import asyncio
from repid import Connection, Queue, Repid, Router
from repid.connections import RedisMessageBroker

from myapp.tasks import send_welcome_email

router = Router()
router.include_func(send_welcome_email.func)

async def main():
    async with Repid(Connection(RedisMessageBroker("redis://localhost:6379"))).magic():
        await Queue("default").declare()
        worker = router.create_worker(Queue("default"))
        await worker.run()

asyncio.run(main())

Development / testing

The in-memory broker (no BROKER configured) is useful for tests:

# settings.py
TASKS = {
    "default": {
        "BACKEND": "django_tasks_repid.backend.RepidBackend",
        "OPTIONS": {},
    }
}

Run the test suite:

uv run pytest

License

MIT

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

django_tasks_repid-0.1.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

django_tasks_repid-0.1.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file django_tasks_repid-0.1.1.tar.gz.

File metadata

  • Download URL: django_tasks_repid-0.1.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for django_tasks_repid-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c90363c4e0f02ac00e46a57e01e34c6f2f28b4d61863a13b3b25a07fc84ca2a7
MD5 a46a72b37039de33e46b5c16f668dc9c
BLAKE2b-256 54ae3469b0c17bacc623ce34133a29b78f1bc9817240103b837a27a7352716ef

See more details on using hashes here.

File details

Details for the file django_tasks_repid-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: django_tasks_repid-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for django_tasks_repid-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 90b68cacd8728e3be2fdb440ccec94b0f41750c1a64f6684a2eebfbe3910f290
MD5 521cc71033ea63c1704fea35205f37fd
BLAKE2b-256 b19c6cf998e5e1914c1e8c5805b8d976ee3cc81f6c76a7960dc16a8bc649b40f

See more details on using hashes here.

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