I'm new to dramatiq an experimenting for a couple of days and I'm not getting a worker to work within a (simple) script.
test.py
import dramatiq
from dramatiq.brokers.redis import RedisBroker
from dramatiq.results.backends import RedisBackend
from dramatiq.results import Results
from dramatiq.worker import Worker
redis_broker = RedisBroker(host="127.0.0.1", port=6379)
results_backend = RedisBackend(url="redis://127.0.0.1:6379")
redis_broker.add_middleware(Results(backend=results_backend))
dramatiq.set_broker(redis_broker)
worker = Worker(
broker=redis_broker
)
worker.start()
@dramatiq.actor(queue_name="default", max_retries=1, store_results=True)
def print_hello_world():
print("Hello World!")
print_hello_world.send()
result (Redis):
127.0.0.1:6379> keys *
1) "dramatiq:default.msgs"
2) "dramatiq:default"
3) "dramatiq:__heartbeats__"
But when starting a dramatiq deamon from the folder with test.py:
$ dramatiq test
the result is what I expected
result (Redis)
127.0.0.1:6379> keys *
1) "3f11649148820d957b2945da46b3c2b7"
2) "dramatiq:__heartbeats__"
It seems that the worker is not receiving the message in this way. It's hard to find examples on the internet setting up a worker from within a script.
Is there some one who can help my getting this work?