Skip to content
This repository has been archived by the owner on Jan 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #158 from Clariteia/0.0.3
Browse files Browse the repository at this point in the history
0.0.3
  • Loading branch information
andrea-mucci authored May 24, 2021
2 parents 32782fd + 2c5e802 commit cde6744
Show file tree
Hide file tree
Showing 85 changed files with 2,172 additions and 1,661 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,5 @@ ENV/

# Intellij IDEa / PyCharm / etc.
.idea

docs/api
7 changes: 7 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ History

* Completed the Poetry Support
* added actions for documentation

0.0.3 (2021-05-24)
------------------

* renamed classes and removed Minos prefix
* Integration of Command and CommandReply with Handler

7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,8 @@ reformat: ## check code coverage quickly with the default Python
poetry run isort --recursive minos tests

docs: ## generate Sphinx HTML documentation, including API docs
rm -f docs/minos_microservice_network.rst
rm -f docs/modules.rst
poetry run sphinx-apidoc -o docs/api minos
poetry run $(MAKE) -C docs clean
poetry run $(MAKE) -C docs html
rm -rf docs/api
poetry run $(MAKE) -C docs clean html

servedocs: docs ## compile the docs watching for changes
watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D .
Expand Down
2 changes: 1 addition & 1 deletion docs/authors.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.. include:: ../AUTHORS.rst
.. include:: ../AUTHORS.md
27 changes: 26 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#
import os
import sys

sys.path.insert(0, os.path.abspath('..'))

from minos import networks
Expand All @@ -31,7 +32,12 @@

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
extensions = [
"sphinxcontrib.apidoc",
'sphinx.ext.autodoc',
"sphinx_autodoc_typehints",
'sphinx.ext.viewcode',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down Expand Up @@ -158,5 +164,24 @@
'Miscellaneous'),
]

## "apidoc" extension
apidoc_module_dir = "../minos"
apidoc_output_dir = "api"
apidoc_separate_modules = True
autodoc_default_options = {
"inherited-members": True,
"special-members": "__init__",
"undoc-members": True,
}

apidoc_toc_file = False
apidoc_module_first = True
apidoc_extra_args = [
"--force",
"--implicit-namespaces",
]

## "autodoc typehints" extension

set_type_checking_flag = True
typehints_fully_qualified = True
2 changes: 1 addition & 1 deletion docs/history.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.. include:: ../HISTORY.rst
.. include:: ../HISTORY.md
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Welcome to Minos Microservice Networks's documentation!

readme
usage
api/modules
modules
authors
history

Expand Down
8 changes: 8 additions & 0 deletions docs/modules.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=======
Modules
=======

.. toctree::
:maxdepth: 2

api/minos
2 changes: 1 addition & 1 deletion docs/readme.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.. include:: ../README.rst
.. include:: ../README.md
55 changes: 29 additions & 26 deletions minos/networks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,43 @@
Minos framework can not be copied and/or distributed without the express permission of Clariteia SL.
"""
__version__ = "0.0.2"
__version__ = "0.0.3"

from .broker import (
MinosCommandBroker,
MinosEventBroker,
MinosQueueDispatcher,
MinosQueueService,
from .brokers import (
CommandBroker,
CommandReplyBroker,
EventBroker,
Producer,
ProducerService,
)
from .exceptions import (
MinosNetworkException,
MinosPreviousVersionSnapshotException,
MinosSnapshotException,
)
from .handler import (
MinosCommandHandlerDispatcher,
MinosCommandHandlerServer,
MinosCommandPeriodicService,
MinosCommandReplyHandlerDispatcher,
MinosCommandReplyHandlerServer,
MinosCommandReplyPeriodicService,
MinosCommandReplyServerService,
MinosCommandServerService,
MinosEventHandlerDispatcher,
MinosEventHandlerServer,
MinosEventPeriodicService,
MinosEventServerService,
MinosHandlerSetup,
from .handlers import (
CommandConsumer,
CommandConsumerService,
CommandHandler,
CommandHandlerService,
CommandReplyConsumer,
CommandReplyConsumerService,
CommandReplyHandler,
CommandReplyHandlerService,
Consumer,
EventConsumer,
EventConsumerService,
EventHandler,
EventHandlerService,
Handler,
HandlerSetup,
)
from .rest_interface import (
REST,
RestInterfaceHandler,
from .rest import (
RestBuilder,
RestService,
)
from .snapshots import (
MinosSnapshotDispatcher,
MinosSnapshotEntry,
MinosSnapshotService,
SnapshotBuilder,
SnapshotEntry,
SnapshotService,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@
Minos framework can not be copied and/or distributed without the express permission of Clariteia SL.
"""
from .commands import (
MinosCommandBroker,
from .abc import (
Broker,
)
from .command_replies import (
CommandReplyBroker,
)
from .dispatchers import (
MinosQueueDispatcher,
from .commands import (
CommandBroker,
)
from .events import (
MinosEventBroker,
EventBroker,
)
from .producers import (
Producer,
)
from .services import (
MinosQueueService,
ProducerService,
)
13 changes: 7 additions & 6 deletions minos/networks/broker/abc.py → minos/networks/brokers/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
)
from typing import (
NoReturn,
Optional,
)

from minos.common import (
MinosBaseBroker,
MinosBroker,
PostgreSqlMinosDatabase,
)


class MinosBrokerSetup(PostgreSqlMinosDatabase):
class BrokerSetup(PostgreSqlMinosDatabase):
"""Minos Broker Setup Class"""

async def _setup(self) -> NoReturn:
Expand All @@ -31,14 +32,14 @@ async def _create_broker_table(self) -> NoReturn:
await self.submit_query(_CREATE_TABLE_QUERY)


class MinosBroker(MinosBaseBroker, MinosBrokerSetup, ABC):
class Broker(MinosBroker, BrokerSetup, ABC):
"""Minos Broker Class."""

ACTION: str

def __init__(self, topic: str, *args, **kwargs):
MinosBaseBroker.__init__(self, topic)
MinosBrokerSetup.__init__(self, *args, **kwargs)
def __init__(self, topic: Optional[str] = None, *args, **kwargs):
super().__init__(*args, **kwargs)
self.topic = topic

async def _send_bytes(self, topic: str, raw: bytes) -> int:
params = (topic, raw, 0, self.ACTION, datetime.now(), datetime.now())
Expand Down
64 changes: 64 additions & 0 deletions minos/networks/brokers/command_replies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
Copyright (C) 2021 Clariteia SL
This file is part of minos framework.
Minos framework can not be copied and/or distributed without the express permission of Clariteia SL.
"""
from __future__ import (
annotations,
)

from typing import (
Optional,
)

from minos.common import (
CommandReply,
MinosConfig,
MinosModel,
)

from .abc import (
Broker,
)


class CommandReplyBroker(Broker):
"""Minos Command Broker Class."""

ACTION = "commandReply"

def __init__(self, *args, saga_id: str, task_id: str, **kwargs):
super().__init__(*args, **kwargs)
self.saga_id = saga_id
self.task_id = task_id

@classmethod
def _from_config(cls, *args, config: MinosConfig, **kwargs) -> CommandReplyBroker:
return cls(*args, **config.saga.queue._asdict(), **kwargs)

async def send(
self,
items: list[MinosModel],
topic: Optional[str] = None,
saga_id: Optional[str] = None,
task_id: Optional[str] = None,
**kwargs
) -> int:
"""Send a list of ``Aggregate`` instances.
:param items: A list of aggregates.
:param topic: Topic in which the message will be published.
:param saga_id: Saga identifier.
:param task_id: Saga execution identifier.
:return: This method does not return anything.
"""
if topic is None:
topic = self.topic
if saga_id is None:
saga_id = self.saga_id
if task_id is None:
task_id = self.task_id
command_reply = CommandReply(topic=topic, items=items, saga_id=saga_id, task_id=task_id)
return await self._send_bytes(command_reply.topic, command_reply.avro_bytes)
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
)

from minos.common import (
Aggregate,
Command,
MinosConfig,
MinosModel,
)

from .abc import (
MinosBroker,
Broker,
)


class MinosCommandBroker(MinosBroker):
class CommandBroker(Broker):
"""Minos Command Broker Class."""

ACTION = "command"
Expand All @@ -36,25 +36,34 @@ def __init__(self, *args, saga_id: str, task_id: str, reply_on: str, **kwargs):
self.task_id = task_id

@classmethod
def from_config(cls, *args, config: MinosConfig = None, **kwargs) -> Optional[MinosCommandBroker]:
"""Build a new repository from config.
:param args: Additional positional arguments.
:param config: Config instance. If `None` is provided, default config is chosen.
:param kwargs: Additional named arguments.
:return: A `MinosRepository` instance.
"""
if config is None:
config = MinosConfig.get_default()
if config is None:
return None
# noinspection PyProtectedMember
def _from_config(cls, *args, config: MinosConfig, **kwargs) -> CommandBroker:
return cls(*args, **config.commands.queue._asdict(), **kwargs)

async def send(self, items: list[Aggregate]) -> int:
async def send(
self,
items: list[MinosModel],
topic: Optional[str] = None,
saga_id: Optional[str] = None,
task_id: Optional[str] = None,
reply_on: Optional[str] = None,
**kwargs
) -> int:
"""Send a list of ``Aggregate`` instances.
:param items: A list of aggregates.
:param topic: Topic in which the message will be published.
:param saga_id: Saga identifier.
:param task_id: Saga execution identifier.
:param reply_on: Topic name in which the reply will be published.
:return: This method does not return anything.
"""
command = Command(self.topic, items, self.saga_id, self.task_id, self.reply_on)
if topic is None:
topic = self.topic
if saga_id is None:
saga_id = self.saga_id
if task_id is None:
task_id = self.task_id
if reply_on is None:
reply_on = self.reply_on
command = Command(topic, items, saga_id, task_id, reply_on)
return await self._send_bytes(command.topic, command.avro_bytes)
Loading

0 comments on commit cde6744

Please sign in to comment.