Adds Dramatiq support to your Flask application
Project description
Flask-Dramatiq plugs Dramatiq task queue in your Flask web application.
// Features //
- Configure Dramatiq from Flask configuration.
- Ensure Flask app is available to Dramatiq actor.
- Add
worker
command to Flask CLI. - Enable Flask Application factory.
- Handle multiple brokers with configurable prefix.
// Installation and Usage //
Flask-Dramatiq is licensed under BSD-3-Clause. Add flask-dramatiq
to your
project:
$ poetry add flask-dramatiq
Then use Dramatiq
object as a regular Flask extension:
from flask import Flask
from flask_dramatiq import Dramatiq
app = Flask(__name__)
dramatiq = Dramatiq(app)
@dramatiq.actor()
def my_actor():
...
@app.route("/")
def myhandler():
my_actor.send()
Flask-Dramatiq adds two configuration keys:
DRAMATIQ_BROKER
, points to broker class likedramatiq.brokers.rabbitmq.RabbitmqBroker
ordramatiq.brokers.redis.RedisBroker
.DRAMATIQ_BROKER_URL
is passed asurl
keyword argument to broker class.
Now run worker program to consume messages and execute tasks in the background:
$ flask worker --processes=1
A complete flask app is available in project source tree example.py.
// Multiple brokers //
You may need multiple broker, e.g. by associating a broker with a blueprint. Flask-Dramatiq supports this. Give other broker a name and run a dedicated worker for it.
bluebroker = Dramatiq(name='bluebroker')
# Configuration:
BLUEBROKER_BROKER_URL = 'rabbitmq://…'
Now run it :
$ flask worker bluebroker
// Using Dramatiq CLI //
You can still use dramatiq
CLI by declaring a file containing:
app = create_app()
broker = dramatiq.broker
Now call dramatiq
CLI with some_module:broker
as usual.
// Credit and Support //
Feel free to open an issue or suggest a merge request on Gitlab project page. Contribution welcome!
The project is based on Bogdanp/flask_dramatiq_example.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for flask_dramatiq-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f04d885e1fea7bf47f25ef6b6724ee1dc46be8887fcbb90f0b9ef2ea6321f73e |
|
MD5 | cb8346e54a5d0331708eab0bad652014 |
|
BLAKE2b-256 | 318c073e5e2b9da3bf8eda51e3b308efc48584e4093b4c3b89ac954d9d2ff505 |