API Reference¶
-
flask_melodramatiq.
create_broker_class
(classpath, *, classname=None, docstring=None, mixins=())¶ Create a new lazy broker class that wraps an existing broker class.
Parameters: - classpath – A module path to the existing broker class. For
example:
"dramatiq.brokers.rabbitmq:RabbitmqBroker"
. - classname – Optional name for the new class. If not given, the class name specified in classpath will be used.
- docstring – Optional documentation string for the new class
- mixins (tuple(type)) – Optional additional mix-in classes
Returns: The created lazy broker class
Example:
from flask_melodramatiq import create_broker_class PostgresBroker = create_broker_class('dramatiq_pg:PostgresBroker')
- classpath – A module path to the existing broker class. For
example:
-
class
flask_melodramatiq.
Broker
(app=None, config_prefix='DRAMATIQ_BROKER', **options)¶ A lazy broker of dynamically configurable type.
The type of the broker should be specified by the “config_prefix_CLASS” setting in the Flask application configuration. For example, if config_prefix is the defaut one, the configuration setting:
DRAMATIQ_BROKER_CLASS="RedisBroker"
specifies that the type of the broker should beRedisBroker
.The following broker type names are always valid:
"RabbitmqBroker"
(default)"RedisBroker"
"StubBroker"
In addition to these, custom broker types can be registered with
create_broker_class()
.Parameters: - app – An optonal Flask application instance
- config_prefix – A prefix for the Flask configuration settings for this broker instance. Each broker instance should have a unique configuration settings prefix.
- options – Keyword arguments to be passed to the constructor
of the wrapped
dramatiq
broker class.
-
actor
(fn=None, **kw)¶ Declare an actor for this broker instance.
Calls
dramatiq.actor()
internally.Example:
from flask_melodramatiq import Broker broker = Broker() @broker.actor def task(): print('Snakes appreciate good theatrical preformace.')
-
init_app
(app)¶ This method can be used to initialize an application for the use with this broker. A broker can not be used in the context of an application unless it is initialized that way.
init_app()
is called automatically if anapp
argument is passed to the constructor.
-
set_default
()¶ Configure this broker instance to be the global broker instance.
Calls
dramatiq.set_broker()
internally.
-
class
flask_melodramatiq.
RabbitmqBroker
(**kwargs)¶ A lazy broker wrapping a
RabbitmqBroker
.Parameters: - app – An optonal Flask application instance
- config_prefix – A prefix for the Flask configuration settings for this broker instance. Each broker instance should have a unique configuration settings prefix.
- options – Keyword arguments to be passed to the constructor
of the wrapped
dramatiq
broker class.
-
actor
(fn=None, **kw)¶ Declare an actor for this broker instance.
Calls
dramatiq.actor()
internally.Example:
from flask_melodramatiq import Broker broker = Broker() @broker.actor def task(): print('Snakes appreciate good theatrical preformace.')
-
init_app
(app)¶ This method can be used to initialize an application for the use with this broker. A broker can not be used in the context of an application unless it is initialized that way.
init_app()
is called automatically if anapp
argument is passed to the constructor.
-
set_default
()¶ Configure this broker instance to be the global broker instance.
Calls
dramatiq.set_broker()
internally.
-
class
flask_melodramatiq.
RedisBroker
(**kwargs)¶ A lazy broker wrapping a
RedisBroker
.Parameters: - app – An optonal Flask application instance
- config_prefix – A prefix for the Flask configuration settings for this broker instance. Each broker instance should have a unique configuration settings prefix.
- options – Keyword arguments to be passed to the constructor
of the wrapped
dramatiq
broker class.
-
actor
(fn=None, **kw)¶ Declare an actor for this broker instance.
Calls
dramatiq.actor()
internally.Example:
from flask_melodramatiq import Broker broker = Broker() @broker.actor def task(): print('Snakes appreciate good theatrical preformace.')
-
init_app
(app)¶ This method can be used to initialize an application for the use with this broker. A broker can not be used in the context of an application unless it is initialized that way.
init_app()
is called automatically if anapp
argument is passed to the constructor.
-
set_default
()¶ Configure this broker instance to be the global broker instance.
Calls
dramatiq.set_broker()
internally.
-
class
flask_melodramatiq.
StubBroker
(app=None, config_prefix='DRAMATIQ_BROKER', **options)¶ A lazy broker wrapping a
StubBroker
.Parameters: - app – An optonal Flask application instance
- config_prefix – A prefix for the Flask configuration settings for this broker instance. Each broker instance should have a unique configuration settings prefix.
- options – Keyword arguments to be passed to the constructor
of the wrapped
dramatiq
broker class.
-
actor
(fn=None, **kw)¶ Declare an actor for this broker instance.
Calls
dramatiq.actor()
internally.Example:
from flask_melodramatiq import Broker broker = Broker() @broker.actor def task(): print('Snakes appreciate good theatrical preformace.')
-
init_app
(app)¶ This method can be used to initialize an application for the use with this broker. A broker can not be used in the context of an application unless it is initialized that way.
init_app()
is called automatically if anapp
argument is passed to the constructor.
-
set_default
()¶ Configure this broker instance to be the global broker instance.
Calls
dramatiq.set_broker()
internally.
-
class
flask_melodramatiq.
missing
¶ Missing value for configuration variables. This can be useful when you want to document the given configuration setting in your code, but you do not want to change the default value.
For example:
from flask import Flask from flask_melodramatiq import missing app = Flask(__name__) app.config['DRAMATIQ_BROKER_URL'] = missing