Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4cd6aed

Browse files
author
Sergio García Prado
authored
Merge pull request#356 from minos-framework/0.6.1
0.6.1
2 parents72cd513 +b86750e commit4cd6aed

File tree

10 files changed

+141
-30
lines changed

10 files changed

+141
-30
lines changed

‎packages/core/minos-microservice-common/HISTORY.md‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,54 @@ History
308308
* Add`Object` base class with the purpose to avoid issues related with multi-inheritance and mixins.
309309
* Add`Port` base class as the base class for ports.
310310
* Add`CircuitBreakerMixin` class to provide circuit breaker functionalities.
311-
* Add`SetupMixin` class as a replacement of the`MinosSetup` class.
311+
* Add`SetupMixin` class as a replacement of the`MinosSetup` class.
312+
313+
###Update Guide (from 0.5.x to 0.6.0)
314+
315+
* Add`@Injectable` decorator to classes that injections:
316+
317+
```python
318+
from minos.commonimport Injectable
319+
320+
321+
@Injectable("THE_INJECTION_NAME")
322+
classMyInjectableClass:
323+
...
324+
```
325+
326+
* Add`minos-http-aiohttp` package:
327+
328+
```shell
329+
poetry add minos-http-aiohttp@^0.6
330+
```
331+
332+
* Add`HttpConnector` instance to`service.injections` section of`config.yml` file:
333+
334+
```yaml
335+
...
336+
service:
337+
injections:
338+
http_connector:minos.plugins.aiohttp.AioHttpConnector
339+
...
340+
...
341+
...
342+
```
343+
344+
* Add`routers` section to`config.yml` file:
345+
346+
```yaml
347+
...
348+
routers:
349+
-minos.networks.BrokerRouter
350+
-minos.networks.PeriodicRouter
351+
-minos.networks.RestHttpRouter
352+
...
353+
```
354+
355+
* Update`minos.common.Config` usages according to the new provided API:
356+
* Most common issues come from calls like`config.query_repository._asdict()`, that must be transformed to`config.get_database_by_name("query")`
357+
358+
0.6.1 (2022-04-01)
359+
------------------
360+
361+
* Fix bug that didn't show the correct exception traceback when microservice failures occurred.

‎packages/core/minos-microservice-common/minos/common/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__author__="Minos Framework Devs"
22
__email__="hey@minos.run"
3-
__version__="0.6.0"
3+
__version__="0.6.1"
44

55
from .buildersimport (
66
BuildableMixin,

‎packages/core/minos-microservice-common/minos/common/launchers.py‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def launch(self) -> NoReturn:
134134
logger.info("Stopping microservice...")
135135
exception=exc
136136
exceptExceptionasexc:# pragma: no cover
137+
logger.exception("Stopping microservice due to an unhandled exception...")
137138
exception=exc
138139
finally:
139140
self.graceful_shutdown(exception)
@@ -143,14 +144,14 @@ def graceful_launch(self) -> None:
143144
144145
:return: This method does not return anything.
145146
"""
146-
self.loop.run_until_complete(gather(self.setup(),self.entrypoint.__aenter__()))
147+
self.loop.run_until_complete(self.setup())
147148

148149
defgraceful_shutdown(self,err:Exception=None)->None:
149150
"""Shutdown the execution gracefully.
150151
151152
:return: This method does not return anything.
152153
"""
153-
self.loop.run_until_complete(gather(self.entrypoint.__aexit__(None,err,None),self.destroy()))
154+
self.loop.run_until_complete(self.destroy())
154155

155156
@cached_property
156157
defentrypoint(self)->Entrypoint:
@@ -199,9 +200,10 @@ async def _setup(self) -> None:
199200
200201
:return: This method does not return anything.
201202
"""
202-
awaitself.injector.wire_and_setup_injections(
203-
modules=self._external_modules+self._internal_modules,packages=self._external_packages
204-
)
203+
modules=self._external_modules+self._internal_modules
204+
packages=self._external_packages
205+
self.injector.wire_injections(modules=modules,packages=packages)
206+
awaitgather(self.injector.setup_injections(),self.entrypoint.__aenter__())
205207

206208
@property
207209
def_internal_modules(self)->list[ModuleType]:
@@ -212,7 +214,8 @@ async def _destroy(self) -> None:
212214
213215
:return: This method does not return anything.
214216
"""
215-
awaitself.injector.unwire_and_destroy_injections()
217+
awaitgather(self.entrypoint.__aexit__(None,None,None),self.injector.destroy_injections())
218+
self.injector.unwire_injections()
216219

217220
@property
218221
definjections(self)->dict[str,InjectableMixin]:

‎packages/core/minos-microservice-common/pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name ="minos-microservice-common"
3-
version ="0.6.0"
3+
version ="0.6.1"
44
description ="The common core of the Minos Framework"
55
readme ="README.md"
66
repository ="https://github.com/minos-framework/minos-python"

‎packages/core/minos-microservice-common/tests/test_common/test_launchers.py‎

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
importwarnings
33
fromunittest.mockimport (
44
AsyncMock,
5+
MagicMock,
56
call,
67
patch,
78
)
@@ -106,37 +107,67 @@ async def test_loop(self):
106107
self.assertEqual(call(),mock_loop.call_args)
107108

108109
asyncdeftest_setup(self):
109-
mock=AsyncMock()
110-
self.launcher.injector.wire_and_setup_injections=mock
111-
awaitself.launcher.setup()
110+
wire_mock=MagicMock()
111+
setup_mock=AsyncMock()
112+
mock_entrypoint_aenter=AsyncMock()
113+
114+
self.launcher.injector.wire_injections=wire_mock
115+
self.launcher.injector.setup_injections=setup_mock
116+
117+
withpatch("minos.common.launchers._create_loop")asmock_loop:
118+
loop=FakeLoop()
119+
mock_loop.return_value=loop
120+
withpatch("minos.common.launchers._create_entrypoint")asmock_entrypoint:
121+
entrypoint=FakeEntrypoint()
122+
mock_entrypoint.return_value=entrypoint
123+
124+
entrypoint.__aenter__=mock_entrypoint_aenter
125+
126+
awaitself.launcher.setup()
112127

113-
self.assertEqual(1,mock.call_count)
128+
self.assertEqual(1,wire_mock.call_count)
114129
importtests
115130
fromminosimport (
116131
common,
117132
)
118133

119-
self.assertEqual(0,len(mock.call_args.args))
120-
self.assertEqual(2,len(mock.call_args.kwargs))
121-
observed=mock.call_args.kwargs["modules"]
134+
self.assertEqual(0,len(wire_mock.call_args.args))
135+
self.assertEqual(2,len(wire_mock.call_args.kwargs))
136+
observed=wire_mock.call_args.kwargs["modules"]
122137

123138
self.assertIn(tests,observed)
124139
self.assertIn(common,observed)
125140

126-
self.assertEqual(["tests"],mock.call_args.kwargs["packages"])
141+
self.assertEqual(["tests"],wire_mock.call_args.kwargs["packages"])
127142

128-
awaitself.launcher.destroy()
143+
self.assertEqual(1,setup_mock.call_count)
144+
self.assertEqual(1,mock_entrypoint_aenter.call_count)
129145

130146
asyncdeftest_destroy(self):
131-
self.launcher.injector.wire_and_setup_injections=AsyncMock()
147+
self.launcher._setup=AsyncMock()
132148
awaitself.launcher.setup()
133149

134-
mock=AsyncMock()
135-
self.launcher.injector.unwire_and_destroy_injections=mock
136-
awaitself.launcher.destroy()
150+
destroy_mock=AsyncMock()
151+
unwire_mock=MagicMock()
152+
mock_entrypoint_aexit=AsyncMock()
153+
154+
self.launcher.injector.destroy_injections=destroy_mock
155+
self.launcher.injector.unwire_injections=unwire_mock
156+
157+
withpatch("minos.common.launchers._create_loop")asmock_loop:
158+
loop=FakeLoop()
159+
mock_loop.return_value=loop
160+
withpatch("minos.common.launchers._create_entrypoint")asmock_entrypoint:
161+
entrypoint=FakeEntrypoint()
162+
mock_entrypoint.return_value=entrypoint
163+
164+
entrypoint.__aexit__=mock_entrypoint_aexit
165+
166+
awaitself.launcher.destroy()
137167

138-
self.assertEqual(1,mock.call_count)
139-
self.assertEqual(call(),mock.call_args)
168+
self.assertEqual(1,unwire_mock.call_count)
169+
self.assertEqual(1,destroy_mock.call_count)
170+
self.assertEqual(1,mock_entrypoint_aexit.call_count)
140171

141172
deftest_launch(self):
142173
mock_setup=AsyncMock()
@@ -157,8 +188,8 @@ def test_launch(self):
157188

158189
self.launcher.launch()
159190

160-
self.assertEqual(1,mock_entrypoint.call_count)
161-
self.assertEqual(1,mock_loop.call_count)
191+
self.assertEqual(1,mock_setup.call_count)
192+
self.assertEqual(1,mock_destroy.call_count)
162193

163194

164195
classTestEntryPointLauncherLoop(unittest.TestCase):

‎packages/plugins/minos-broker-kafka/HISTORY.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@
1818
##0.6.0 (2022-03-28)
1919

2020
* Add`KafkaCircuitBreakerMixin` to integrate`minos.common.CircuitBreakerMixin` into the`KafkaBrokerPublisher` and`KafkaBrokerSubscriber` classes to be tolerant to connection failures to`kafka`.
21-
* Add`KafkaBrokerPublisherBuilder` and`KafkaBrokerBuilderMixin` classes to ease the building process.
21+
* Add`KafkaBrokerPublisherBuilder` and`KafkaBrokerBuilderMixin` classes to ease the building process.
22+
23+
##0.6.1 (2022-04-01)
24+
25+
* Improve`KafkaBrokerSubscriber`'s destroying process.

‎packages/plugins/minos-broker-kafka/minos/plugins/kafka/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__author__="Minos Framework Devs"
22
__email__="hey@minos.run"
3-
__version__="0.6.0"
3+
__version__="0.6.1"
44

55
from .commonimport (
66
KafkaBrokerBuilderMixin,

‎packages/plugins/minos-broker-kafka/minos/plugins/kafka/subscriber.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
fromaiokafkaimport (
2424
AIOKafkaConsumer,
25+
ConsumerStoppedError,
2526
)
2627
fromcached_propertyimport (
2728
cached_property,
@@ -166,7 +167,12 @@ def admin_client(self):
166167
returnKafkaAdminClient(bootstrap_servers=f"{self.host}:{self.port}")
167168

168169
asyncdef_receive(self)->BrokerMessage:
169-
record=awaitself.client.getone()
170+
try:
171+
record=awaitself.client.getone()
172+
exceptConsumerStoppedErrorasexc:
173+
ifself.already_destroyed:
174+
raiseStopAsyncIteration
175+
raiseexc
170176
bytes_=record.value
171177
message=BrokerMessage.from_avro_bytes(bytes_)
172178
returnmessage

‎packages/plugins/minos-broker-kafka/pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name ="minos-broker-kafka"
3-
version ="0.6.0"
3+
version ="0.6.1"
44
description ="The kafka plugin of the Minos Framework"
55
readme ="README.md"
66
repository ="https://github.com/minos-framework/minos-python"

‎packages/plugins/minos-broker-kafka/tests/test_kafka/test_subscriber.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
fromaiokafkaimport (
1212
AIOKafkaConsumer,
13+
ConsumerStoppedError,
1314
)
1415
fromkafkaimport (
1516
KafkaAdminClient,
@@ -206,6 +207,22 @@ async def test_receive(self):
206207
self.assertEqual(messages[0],awaitsubscriber.receive())
207208
self.assertEqual(messages[1],awaitsubscriber.receive())
208209

210+
asyncdeftest_receive_already_stopped_raises(self):
211+
subscriber=KafkaBrokerSubscriber.from_config(CONFIG_FILE_PATH,topics={"foo","bar"})
212+
get_mock=AsyncMock(side_effect=ConsumerStoppedError)
213+
subscriber.client.getone=get_mock
214+
215+
withself.assertRaises(StopAsyncIteration):
216+
awaitsubscriber.receive()
217+
218+
asyncdeftest_receive_stopped(self):
219+
asyncwithKafkaBrokerSubscriber.from_config(CONFIG_FILE_PATH,topics={"foo","bar"})assubscriber:
220+
get_mock=AsyncMock(side_effect=ConsumerStoppedError)
221+
subscriber.client.getone=get_mock
222+
223+
withself.assertRaises(ConsumerStoppedError):
224+
awaitsubscriber.receive()
225+
209226

210227
classTestKafkaBrokerSubscriberBuilder(unittest.TestCase):
211228
defsetUp(self)->None:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp