Bogdanp / django_dramatiq

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

Result backend not registered? #74

Closed Baekalfen closed 4 years ago

Baekalfen commented 4 years ago

I've tried to set up a minimal setup with a result backend, but I still get an error message, that the middleware is not loaded.

Django, Redis and Dramatiq are all running in individual docker containers. Dramatiq is started with python manage.py rundramatiq.

Settings:

DRAMATIQ_BROKER = {
    "BROKER": "dramatiq.brokers.rabbitmq.RabbitmqBroker",
    "OPTIONS": {
        "url": BROKER_URL,
    },
    "MIDDLEWARE": [
        "dramatiq.middleware.Prometheus",
        "dramatiq.middleware.AgeLimit",
        "dramatiq.middleware.TimeLimit",
        "dramatiq.middleware.Callbacks",
        "dramatiq.middleware.Retries",
        "django_dramatiq.middleware.AdminMiddleware",
        "django_dramatiq.middleware.DbConnectionsMiddleware",
    ]
}

DRAMATIQ_RESULT_BACKEND = {
    "BACKEND": "dramatiq.results.backends.redis.RedisBackend",
    "BACKEND_OPTIONS": {
        "url": "redis://redis:6379",
    }
}

If I send a task using the Django shell, I see the following in the log:

dramatiq_1      | Pushing message '8c87e639-342b-4c9b-81ad-56997f6a729f' onto work queue.
dramatiq_1      | Received message test_actor('123') with id '8c87e639-342b-4c9b-81ad-56997f6a729f'.
dramatiq_1      | Updating Task from message '8c87e639-342b-4c9b-81ad-56997f6a729f'.
postgres_1      | 2020-07-13 13:50:56.669 UTC [72] ERROR:  duplicate key value violates unique constraint "django_dramatiq_task_pkey"
postgres_1      | 2020-07-13 13:50:56.669 UTC [72] DETAIL:  Key (id)=(8c87e639-342b-4c9b-81ad-56997f6a729f) already exists.
postgres_1      | 2020-07-13 13:50:56.669 UTC [72] STATEMENT:  INSERT INTO "django_dramatiq_task" ("id", "status", "created_at", "updated_at", "message_data", "actor_name", "queue_name") VALUES ('8c87e639-342b-4c9b-81ad-56997f6a729f'::uuid, 'running', '2020-07-13T13:50:56.668878+00:00'::timestamptz, '2020-07-13T13:50:56.669010+00:00'::timestamptz, '\x7b2271756575655f6e616d65223a2264656661756c74222c226163746f725f6e616d65223a22746573745f6163746f72222c2261726773223a5b22313233225d2c226b7761726773223a7b7d2c226f7074696f6e73223a7b7d2c226d6573736167655f6964223a2238633837653633392d333432622d346339622d383161642d353639393766366137323966222c226d6573736167655f74696d657374616d70223a313539343634383235363539327d'::bytea, 'test_actor', 'default')
dramatiq_1      | Received args=('123',) kwargs={}.
dramatiq_1      | Actor 'test_actor' returns a value that is not None, and you haven't added the Results middleware to the broker, which means the return value will be silently dropped. Consider adding the Results middleware to your broker.
dramatiq_1      | Completed after 0.40ms.
dramatiq_1      | Updating Task from message '8c87e639-342b-4c9b-81ad-56997f6a729f'.
dramatiq_1      | Acknowledging message '8c87e639-342b-4c9b-81ad-56997f6a729f'.
Baekalfen commented 4 years ago

I've tried to add some print statements in apps.py, and I can see that the settings are picked up and the middleware is supposedly loaded, when I run python manage.py shell

Bogdanp commented 4 years ago

The warning might be mis-diagnosing the problem. Are you passing store_results=True to @actor(...)?

Baekalfen commented 4 years ago

Ah, that was it! Thank you!