Bogdanp / django_dramatiq

A Django app that integrates with Dramatiq.
https://dramatiq.io
Other
331 stars 77 forks source link

Fixed not able to use redis as broker with django_dramatiq #40

Closed vjMagar closed 5 years ago

vjMagar commented 5 years ago

This is PR for fixing the configuration issue when using redis as broker.

File "*****************/python3.7/site-packages/django_dramatiq/apps.py", line 107, in <module>
DjangoDramatiqConfig.initialize()
File "*****************/python3.7/site-packages/django_dramatiq/apps.py", line 74, in initialize
    broker = broker_class(middleware=middleware, **broker_options)
File "*****************/python3.7/site-packages/dramatiq/results/backends/redis.py", line 48, in __init__
    self.client = client or redis.StrictRedis(**parameters)
TypeError: __init__() got an unexpected keyword argument 'middleware'

This PR will fixes this issus.

Bogdanp commented 5 years ago

Hi @vjMagar, can you provide a minimal example where this breaks? I'm not sure this is an actual issue since RedisBroker does take a middleware keyword argument, so it should no be passed to StrictRedis. The only way I can see this happening is if you have a middleware key in your OPTIONS dictionary of your broker settings.

vjMagar commented 5 years ago

Hi @Bogdanp,

Yes! you are right, I went back to the setting and it turns out that I did typo in the DRAMATIQ_BROKER key.

Folllowing the local setting which I have used in the settings.py

DRAMATIQ_BROKER = {
    "BROKER": "dramatiq.brokers.redis.RedisBroker",
    "OPTIONS": {
        "url": "redis://localhost:6379",
        "MIDDLEWARE": [
            "dramatiq.middleware.Prometheus",
            "dramatiq.middleware.AgeLimit",
            "dramatiq.middleware.TimeLimit",
            "dramatiq.middleware.Callbacks",
            "dramatiq.middleware.Retries",
            "django_dramatiq.middleware.AdminMiddleware",
            "django_dramatiq.middleware.DbConnectionsMiddleware",
        ],
    },
}

In this case this was causing trouble. The DRAMATIQ_BROKER setting must been

DRAMATIQ_BROKER = {
    "BROKER": "dramatiq.brokers.redis.RedisBroker",
    "OPTIONS": {
        "url": "redis://localhost:6379",
    },
        "MIDDLEWARE": [
            "dramatiq.middleware.Prometheus",
            "dramatiq.middleware.AgeLimit",
            "dramatiq.middleware.TimeLimit",
            "dramatiq.middleware.Callbacks",
            "dramatiq.middleware.Retries",
            "django_dramatiq.middleware.AdminMiddleware",
            "django_dramatiq.middleware.DbConnectionsMiddleware",
        ],
}
vjMagar commented 5 years ago

I am closing this pull request, as this was simple case of typo on my end. Thanks @Bogdanp