From 22231a581f23ad4093f71e83b902c673532fd85a Mon Sep 17 00:00:00 2001 From: Evgeni Pandurski Date: Wed, 3 Aug 2022 15:00:29 +0300 Subject: [PATCH] Work toward 1.0 --- .circleci/config.yml | 5 +-- CHANGES.rst | 8 +++++ docs/api.rst | 4 ++- docs/conf.py | 8 ++--- flask_melodramatiq/__init__.py | 2 -- flask_melodramatiq/lazy_broker.py | 13 +++++++- flask_melodramatiq/rabbitmq.py | 53 ------------------------------- setup.py | 7 ++-- tests/test_rabbitmq_broker.py | 38 ---------------------- 9 files changed, 34 insertions(+), 104 deletions(-) delete mode 100644 flask_melodramatiq/rabbitmq.py delete mode 100644 tests/test_rabbitmq_broker.py diff --git a/.circleci/config.yml b/.circleci/config.yml index 1f27d7c..36d4132 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,8 +9,9 @@ jobs: name: Run Tests command: | apt-get update && apt-get -y --no-install-recommends install rabbitmq-server - service rabbitmq-server start - python setup.py test + pip install 'pytest~=6.2' 'pytest-cov~=2.7' 'mock~=2.0' 'pika>=0.13' 'redis>=3.4' + pip install -e . + pytest workflows: version: 2 commit: diff --git a/CHANGES.rst b/CHANGES.rst index 72dbac1..18d8a49 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,14 @@ Changelog ========= +Version 1.0 +----------- + +- Removed the `RabbitmqBroker.publish_message()` method. + +- Documented the use of `missing` configuration values. + + Version 0.3.9 ------------- diff --git a/docs/api.rst b/docs/api.rst index eb9d815..f835dad 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -9,10 +9,12 @@ API Reference :members: init_app, set_default, actor .. autoclass:: RabbitmqBroker - :members: init_app, set_default, actor, publish_message + :members: init_app, set_default, actor .. autoclass:: RedisBroker :members: init_app, set_default, actor .. autoclass:: StubBroker :members: init_app, set_default, actor + +.. autoclass:: missing diff --git a/docs/conf.py b/docs/conf.py index 6f86155..54a7327 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -62,16 +62,16 @@ # built documents. # # The short X.Y version. -version = '0.3.9' +version = '1.0' # The full version, including alpha/beta/rc tags. -release = '0.3.9' +release = '1.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = 'en' # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: @@ -138,7 +138,7 @@ # The name for this set of Sphinx documents. # " v documentation" by default. # -# html_title = 'Flask-Melodramatiq v0.3.9' +# html_title = 'Flask-Melodramatiq v1.0' # A shorter title for the navigation bar. Default is the same as html_title. # diff --git a/flask_melodramatiq/__init__.py b/flask_melodramatiq/__init__.py index 27f8e20..a88a490 100644 --- a/flask_melodramatiq/__init__.py +++ b/flask_melodramatiq/__init__.py @@ -9,7 +9,6 @@ Broker, missing, ) -from flask_melodramatiq.rabbitmq import RabbitmqBrokerMixin __all__ = ['create_broker_class', 'Broker', 'RabbitmqBroker', 'RedisBroker', 'StubBroker'] @@ -77,7 +76,6 @@ def raise_error(e, *args, **kwargs): docstring=LAZY_BROKER_DOCSTRING_TEMPLATE.format( description='A lazy broker wrapping a :class:`~dramatiq.brokers.rabbitmq.RabbitmqBroker`.\n', ), - mixins=(RabbitmqBrokerMixin,) ) diff --git a/flask_melodramatiq/lazy_broker.py b/flask_melodramatiq/lazy_broker.py index 47a5b14..055698f 100644 --- a/flask_melodramatiq/lazy_broker.py +++ b/flask_melodramatiq/lazy_broker.py @@ -8,7 +8,18 @@ class missing: - """Missing value for configuration variables.""" + """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 + """ DEFAULT_CLASS_NAME = 'RabbitmqBroker' diff --git a/flask_melodramatiq/rabbitmq.py b/flask_melodramatiq/rabbitmq.py deleted file mode 100644 index dfa24d2..0000000 --- a/flask_melodramatiq/rabbitmq.py +++ /dev/null @@ -1,53 +0,0 @@ -import dramatiq - - -class RabbitmqBrokerMixin: - def publish_message(self, message, *, exchange='', routing_key=None): - """Publish a message on an exchange. - - :param message: The message - :type message: dramatiq.Message - - :param exchange: The name of the RabbitMQ exchange on which to - publish the message - - :param routing_key: The message routing key. If the value is - `None`, the routing key will be - ``f"dramatiq.events.{message.actor_name}"`` if - ``message.queue_name`` is `None`, and ``message.queue_name`` - otherwise. - - """ - - import pika - - if routing_key is None: - if message.queue_name is None: - routing_key = 'dramatiq.events.' + message.actor_name - else: - routing_key = message.queue_name - - properties = pika.BasicProperties( - delivery_mode=2, - priority=message.options.get("broker_priority"), - ) - - attempts = 1 - while True: - try: - self.channel.basic_publish( - exchange=exchange, - routing_key=routing_key, - body=message.encode(), - properties=properties, - ) - return - - except (pika.exceptions.AMQPConnectionError, - pika.exceptions.AMQPChannelError) as e: - del self.channel - del self.connection - - attempts += 1 - if attempts > 6: - raise dramatiq.ConnectionClosed(e) from None diff --git a/setup.py b/setup.py index 5044375..3212975 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ def rel(*xs): setup( name='Flask-Melodramatiq', - version='0.3.9', + version='1.0', url='https://github.com/epandurski/flask_melodramatiq', license='MIT', author='Evgeni Pandurski', @@ -54,9 +54,10 @@ def rel(*xs): 'Topic :: Software Development :: Libraries :: Python Modules', 'Programming Language :: Python', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', ], project_urls={ "Bug Tracker": "https://github.com/epandurski/flask_melodramatiq/issues", diff --git a/tests/test_rabbitmq_broker.py b/tests/test_rabbitmq_broker.py deleted file mode 100644 index acc1b00..0000000 --- a/tests/test_rabbitmq_broker.py +++ /dev/null @@ -1,38 +0,0 @@ -import dramatiq -import time - - -def test_broker_connection_attrs(app, rabbitmq_broker): - rabbitmq_broker.init_app(app) - assert hasattr(rabbitmq_broker, 'channel') - assert hasattr(rabbitmq_broker, 'connection') - del rabbitmq_broker.channel - del rabbitmq_broker.connection - assert hasattr(rabbitmq_broker, 'channel') - assert hasattr(rabbitmq_broker, 'connection') - - -def test_connection_closed_error(): - e = Exception() - assert isinstance(dramatiq.ConnectionClosed(e), Exception) - - -def test_publish_message(app, rabbitmq_broker, run_mock): - @rabbitmq_broker.actor - def task(): - run_mock() - - rabbitmq_broker.init_app(app) - m = dramatiq.Message(queue_name='default', actor_name='task', args=(), kwargs={}, options={}) - worker = dramatiq.Worker(rabbitmq_broker) - worker.start() - time.sleep(3.0) - rabbitmq_broker.publish_message(m, exchange='') - time.sleep(3.0) - worker.join() - worker.stop() - run_mock.assert_called_once() - - # try `queue_name=None` - m = dramatiq.Message(queue_name=None, actor_name='task', args=(), kwargs={}, options={}) - rabbitmq_broker.publish_message(m, exchange='')