buz 2.15.12__py3-none-any.whl → 2.16.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,8 @@
1
1
  from typing import Optional, Iterable
2
2
 
3
3
  from buz.event import Event, EventBus
4
+ from buz.event.middleware.publish_middleware import PublishMiddleware
5
+ from buz.event.middleware.publish_middleware_chain_resolver import PublishMiddlewareChainResolver
4
6
  from buz.event.transactional_outbox import OutboxRecord
5
7
  from buz.event.transactional_outbox.event_to_outbox_record_translator import EventToOutboxRecordTranslator
6
8
  from buz.event.transactional_outbox.outbox_record_validation.outbox_record_validator import OutboxRecordValidator
@@ -13,22 +15,40 @@ class TransactionalOutboxEventBus(EventBus):
13
15
  outbox_repository: OutboxRepository,
14
16
  event_to_outbox_record_translator: EventToOutboxRecordTranslator,
15
17
  outbox_record_validator: Optional[OutboxRecordValidator] = None,
16
- ):
18
+ publish_middlewares: Optional[list[PublishMiddleware]] = None,
19
+ ) -> None:
17
20
  self.__outbox_repository = outbox_repository
18
21
  self.__event_to_outbox_record_translator = event_to_outbox_record_translator
19
22
  self.__outbox_record_validator = outbox_record_validator
23
+ self.__publish_middleware_chain_resolver = PublishMiddlewareChainResolver(publish_middlewares or [])
20
24
 
21
25
  def publish(self, event: Event) -> None:
22
- outbox_record = self.__translate_and_validate(event)
26
+ self.__publish_middleware_chain_resolver.resolve(event, self.__perform_publish)
27
+
28
+ def __perform_publish(self, event: Event) -> None:
29
+ outbox_record = self.__process_event(event)
23
30
  self.__outbox_repository.save(outbox_record)
24
31
 
25
32
  def bulk_publish(self, events: Iterable[Event]) -> None:
26
- outbox_records = map(self.__translate_and_validate, events)
33
+ outbox_records: list[OutboxRecord] = []
34
+ for event in events:
35
+ self.__publish_middleware_chain_resolver.resolve(
36
+ event, lambda resolved_event: outbox_records.append(self.__process_event(resolved_event))
37
+ )
38
+
39
+ if len(outbox_records) == 0:
40
+ return None
41
+
27
42
  self.__outbox_repository.bulk_create(outbox_records)
28
43
 
29
- # Raises OutboxRecordValidationException: If any validation inside outbox_record_validator fails
30
- def __translate_and_validate(self, event: Event) -> OutboxRecord:
31
- outbox_record = self.__event_to_outbox_record_translator.translate(event)
44
+ def __process_event(self, event: Event) -> OutboxRecord:
45
+ outbox_record = self.__translate_event(event)
46
+ self.__validate_outbox_record(outbox_record)
47
+ return outbox_record
48
+
49
+ def __translate_event(self, event: Event) -> OutboxRecord:
50
+ return self.__event_to_outbox_record_translator.translate(event)
51
+
52
+ def __validate_outbox_record(self, outbox_record: OutboxRecord) -> None:
32
53
  if self.__outbox_record_validator is not None:
33
54
  self.__outbox_record_validator.validate(record=outbox_record)
34
- return outbox_record
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: buz
3
- Version: 2.15.12
3
+ Version: 2.16.0
4
4
  Summary: Buz is a set of light, simple and extensible implementations of event, command and query buses.
5
5
  License: MIT
6
6
  Author: Luis Pintado Lozano
@@ -140,7 +140,7 @@ buz/event/transactional_outbox/outbox_record_validation/outbox_record_validation
140
140
  buz/event/transactional_outbox/outbox_record_validation/outbox_record_validator.py,sha256=XGHTT1dH2CJOqhYYnyPJHmZsAuVXuDOeqgJzK7mRidc,328
141
141
  buz/event/transactional_outbox/outbox_record_validation/size_outbox_record_validator.py,sha256=f8sQ5IHfO4J8m5l7rS3JYUoBvx0B1EAFMRsJ0HPQKG8,2436
142
142
  buz/event/transactional_outbox/outbox_repository.py,sha256=Sn7aWaq1G6uiKXcV09l9L1eVQ_bPUTqY-OSD12_H2jU,628
143
- buz/event/transactional_outbox/transactional_outbox_event_bus.py,sha256=S2VIrKCyZG8vztgBagKOJUhp2oJhbLx6oGVHPBplRZ4,1676
143
+ buz/event/transactional_outbox/transactional_outbox_event_bus.py,sha256=9eUevDAKEwouKrSEhf5dpqFwI-FbB5z9R7gIxaFCLno,2551
144
144
  buz/event/transactional_outbox/transactional_outbox_worker.py,sha256=x6kf-Oc4oYKu9S4MTcCqd3VqPNURScTReYJ3Ahx4rKA,2221
145
145
  buz/event/worker.py,sha256=BL9TXB_kyr0Avql9fIcFm3CDNnXPvZB6O6BxVwjtCdA,942
146
146
  buz/handler.py,sha256=W6jSTo5BNV9u9QKBaEMhLIa3tgQocd6oYEJf5K4EfEU,358
@@ -257,7 +257,7 @@ buz/serializer/message_to_json_bytes_serializer.py,sha256=RGZJ64t4t4Pz2FCASZZCv-
257
257
  buz/wrapper/__init__.py,sha256=GnRdJFcncn-qp0hzDG9dBHLmTJSbHFVjE_yr-MdW_n4,77
258
258
  buz/wrapper/async_to_sync.py,sha256=OfK-vrVUhuN-LLLvekLdMbQYtH0ue5lfbvuasj6ovMI,698
259
259
  buz/wrapper/event_loop.py,sha256=pfBJ1g-8A2a3YgW8Gf9Fg0kkewoh3-wgTy2KIFDyfHk,266
260
- buz-2.15.12.dist-info/LICENSE,sha256=jcLgcIIVaBqaZNwe0kzGWSU99YgwMcI0IGv142wkYSM,1062
261
- buz-2.15.12.dist-info/METADATA,sha256=0OTKNDoBKW4CPRuo5gFprqjtavCT7uL-qVJ1oTdWYZg,12680
262
- buz-2.15.12.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
263
- buz-2.15.12.dist-info/RECORD,,
260
+ buz-2.16.0.dist-info/LICENSE,sha256=jcLgcIIVaBqaZNwe0kzGWSU99YgwMcI0IGv142wkYSM,1062
261
+ buz-2.16.0.dist-info/METADATA,sha256=NUJDqpVmTFd9vDNXIhjiaN1N9jKAiUOisQfBFUB6q_Y,12679
262
+ buz-2.16.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
263
+ buz-2.16.0.dist-info/RECORD,,
File without changes
File without changes