I’m running Dramatiq as part of a Pyramid appserver, where tasks are scheduled from within a view function and executed by workers (actors).
Messages and results are exchanged via Redis.
Now the Redis configuration is stored in different .ini files, one for development, one for beta, one for production. When the Pyramid appserver starts up, the .ini file is passed along and used:
./bin/gunicorn --paste appsrv-localhost.ini
The appserver reads the configuration from that .ini file and connects to Redis accordingly.
The Dramatiq actors are implemented in srv/dramatiq/actors.py, and view functions can call them just fine. It all works until here.
Next I want to start the broker to handle the messages and execute the tasks. Thus, here too I need to read the .ini file and set up Dramatiq’s Redis access. To do that, I added another file srv/dramatiq/broker.py
_cp = configparser.ConfigParser() _cp.read(os.path.join(os.path.split(__file__), "../../appsrv-localhost.ini")) _redis_url = _cp.get("app:main", "redis.url") _redis_namespace = _cp.get("app:main", "redis.namespace") _redis_broker = RedisBroker(url=_redis_url, namespace=_redis_namespace) dramatiq.set_broker(_redis_broker) from .actors import *
and then call it like so:
./bin/dramatiq --processes 1 --threads 2 --watch ./srv/dramatiq/ --verbose srv.dramatiq.broker
The problem is the configuration file: how can I pass it to Dramatiq so that options become available in this context? Or what is the recommended approach here?