Skip to main content

Eager broker for dramatiq

Project description

dramatiq-eager-broker

An eager broker for Dramatiq that executes tasks synchronously and immediately, without queuing. Perfect for testing and development environments.

Features

  • Synchronous task execution
  • No message broker required (Redis, RabbitMQ, etc.)
  • Pipeline support
  • Middleware support
  • Drop-in replacement for testing

Installation

pip install dramatiq-eager-broker

Or with uv:

uv add dramatiq-eager-broker

Usage

import dramatiq
from dramatiq_eager_broker import EagerBroker

broker = EagerBroker(middleware=None)
dramatiq.set_broker(broker)

@dramatiq.actor
def send_email(email, message):
    print(f"Sending email to {email}: {message}")

# Tasks are executed immediately and synchronously
send_email.send("user@example.com", "Hello!")

Testing Example

import dramatiq
import pytest
from dramatiq_eager_broker import EagerBroker


@pytest.fixture
def eager_broker():
    broker = EagerBroker(middleware=None)
    dramatiq.set_broker(broker)
    yield broker
    dramatiq.set_broker(None)


def test_my_actor(eager_broker):
    results = []

    @dramatiq.actor
    def my_task(value):
        results.append(value)

    my_task.send("test")
    assert results == ["test"]

Pipeline Support

The eager broker supports Dramatiq pipelines:

@dramatiq.actor
def add(x, y):
    return x + y

@dramatiq.actor
def multiply(result, factor):
    return result * factor

# Create and execute a pipeline
pipeline = add.message(2, 3) | multiply.message(factor=10)
broker.enqueue(pipeline.messages[0])

Results Support

The eager broker supports Dramatiq get_result() if the Results middleware is loaded:

@dramatiq.actor
def add(x, y):
    return x + y

@dramatiq.actor
def multiply(result, factor):
    return result * factor

broker.add_middleware(Results(backend=StubBackend()))

# Create and execute a pipeline
pipeline = add.message(2, 3) | multiply.message(factor=10)
broker.enqueue(pipeline.messages[0])

assert pipeline.get_result() == 60

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

dramatiq_eager_broker-0.2.0.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

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

dramatiq_eager_broker-0.2.0-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file dramatiq_eager_broker-0.2.0.tar.gz.

File metadata

File hashes

Hashes for dramatiq_eager_broker-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2465a7367bbaed3fc2b7c97590024938062be63c5dc5827d17570499b70ab951
MD5 2f91197f576a59a2244396fb7869d7c0
BLAKE2b-256 0ec549b874d43a081a1901288fd578aca0238721c4838408acf1c28a4b283951

See more details on using hashes here.

File details

Details for the file dramatiq_eager_broker-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dramatiq_eager_broker-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2fb98b3630b99a1a56287346079c69ec13f1c6662d2e957334dae4958741b134
MD5 506828593e03aa8bbc379a00c14aabc9
BLAKE2b-256 f44f32c802e43a594d6b8d755850362abb6386cab496d34e96d7e886b4e470a6

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