2
import dramatiq
from dramatiq.brokers.redis import RedisBroker
from dramatiq.results import Results
from dramatiq.results.backends import RedisBackend

broker = RedisBroker(host="127.0.0.1", port=6379)
broker.declare_queue("default")
dramatiq.set_broker(broker)
# backend = RedisBackend()
# broker.add_middleware(Results(backend=backend))

@dramatiq.actor()
def print_words(text):
        print('This is ' + text)

print_words('sync')
a = print_words.send('async')
a.get_results()

I was checking alternatives to celery and found Dramatiq. I'm just getting started with dramatiq and I'm unable to retrieve results. I even tried setting the backend and 'save_results' to True. I'm always getting this AttributeError: 'Message' object has no attribute 'get_results'

Any idea on how to get the result?

Vaibhav
  • 507
  • 2
  • 4
  • 20

2 Answers2

2

You were on the right track with adding a result backend. The way to instruct an actor to store results is store_results=True, not save_results and the method to retrieve results is get_result(), not get_results.

Bogdan Popa
  • 1,081
  • 7
  • 6
  • I made these changes and I’m getting dramatiq.results.errors.ResultMissing’. Any idea on how to solve this? – Vaibhav Jul 20 '20 at 11:34
  • Are you returning a value from the actor? The example code in your question does not so that's probably the problem. – Bogdan Popa Jul 20 '20 at 15:45
  • Yeah. I tried with the example.py provided in your github repo and still I get the error. `dramatiq.results.errors.ResultMissing: count_words('https://www.crash.net')` . The count is getting printed in the terminal running the command `dramatiq example` but I can't return the result. – Vaibhav Jul 20 '20 at 19:13
0

When you run get_result() with block=False, you should wait the worker set result ready, like this:

while True:
    try:
        res = a.get_result(backend=backend)
        break
    except dramatiq.results.errors.ResultMissing:
        # do something like retry N times.
        time.sleep(1)
print(res)