buz 2.15.10rc1__py3-none-any.whl → 2.15.10rc2__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.
@@ -374,8 +374,7 @@ class BaseBuzAIOKafkaAsyncConsumer(AsyncConsumer):
374
374
  self._logger.info("Worker stop requested. Waiting for finalize the current task")
375
375
 
376
376
  async def __manage_kafka_consumers_stopping(self) -> None:
377
- for kafka_consumer in self.__queue_per_consumer_mapper.keys():
378
- await kafka_consumer.stop()
377
+ await gather(*[kafka_consumer.stop() for kafka_consumer in self.__queue_per_consumer_mapper.keys()])
379
378
 
380
379
  async def __health_check(self) -> web.Response:
381
380
  health_information = {
@@ -4,7 +4,7 @@ import asyncio
4
4
  from logging import Logger
5
5
  from typing import Awaitable, Callable, Optional, Sequence, cast
6
6
 
7
- from aiokafka import AIOKafkaConsumer as AIOKafkaNativeConsumer, TopicPartition, OffsetAndMetadata
7
+ from aiokafka import AIOKafkaConsumer as AIOKafkaNativeConsumer, ConsumerRecord, TopicPartition, OffsetAndMetadata
8
8
  from aiokafka.helpers import create_ssl_context
9
9
 
10
10
  from buz.event.infrastructure.buz_kafka.exceptions.kafka_event_bus_config_not_valid_exception import (
@@ -26,6 +26,7 @@ from buz.kafka.infrastructure.aiokafka.translators.consumer_initial_offset_posit
26
26
 
27
27
  class AIOKafkaConsumer:
28
28
  __DEFAULT_POLL_TIMEOUT_MS = 0
29
+ __DEFAULT_ASYNC_FUNCTION_TIMEOUT_MS = 3000
29
30
 
30
31
  def __init__(
31
32
  self,
@@ -177,14 +178,15 @@ class AIOKafkaConsumer:
177
178
  async def poll(
178
179
  self,
179
180
  *,
180
- timeout_ms: int = __DEFAULT_POLL_TIMEOUT_MS,
181
181
  number_of_messages_to_poll: Optional[int] = None,
182
182
  ) -> list[KafkaPollRecord]:
183
- poll_results = await self.__consumer.getmany(
184
- timeout_ms=timeout_ms,
183
+ poll_results = await self.__get_many(
185
184
  max_records=number_of_messages_to_poll,
186
185
  )
187
186
 
187
+ if poll_results is None:
188
+ return []
189
+
188
190
  results = [
189
191
  cast(KafkaPollRecord, consumer_record)
190
192
  for consumer_records in poll_results.values()
@@ -193,6 +195,19 @@ class AIOKafkaConsumer:
193
195
 
194
196
  return results
195
197
 
198
+ async def __get_many(
199
+ self,
200
+ max_records: Optional[int] = None,
201
+ ) -> Optional[dict[TopicPartition, list[ConsumerRecord]]]:
202
+ try:
203
+ return await asyncio.wait_for(
204
+ self.__consumer.getmany(timeout_ms=self.__DEFAULT_POLL_TIMEOUT_MS, max_records=max_records),
205
+ timeout=self.__DEFAULT_ASYNC_FUNCTION_TIMEOUT_MS / 1000,
206
+ )
207
+ except asyncio.TimeoutError:
208
+ self.__logger.debug("Timeout while polling")
209
+ return None
210
+
196
211
  async def commit_poll_record(self, poll_record: KafkaPollRecord) -> None:
197
212
  topic_partition = TopicPartition(topic=poll_record.topic, partition=poll_record.partition)
198
213
  offset = {topic_partition: OffsetAndMetadata(poll_record.offset + 1, "")}
@@ -201,4 +216,13 @@ class AIOKafkaConsumer:
201
216
 
202
217
  async def stop(self) -> None:
203
218
  self.__logger.info(f"Closing connection of consumer with group_id={self.__consumer_group}")
204
- await self.__consumer.stop()
219
+
220
+ self.__consumer.unsubscribe()
221
+
222
+ try:
223
+ await asyncio.wait_for(
224
+ self.__consumer.stop(),
225
+ timeout=self.__DEFAULT_ASYNC_FUNCTION_TIMEOUT_MS / 1000,
226
+ )
227
+ except asyncio.TimeoutError:
228
+ self.__logger.debug("Timeout while stopping consumer")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: buz
3
- Version: 2.15.10rc1
3
+ Version: 2.15.10rc2
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
@@ -47,7 +47,7 @@ buz/event/exceptions/worker_execution_exception.py,sha256=6mgztvXOCG_9VZ_Jptkk72
47
47
  buz/event/infrastructure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
48
  buz/event/infrastructure/buz_kafka/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
49
  buz/event/infrastructure/buz_kafka/async_buz_kafka_event_bus.py,sha256=SyLblUVlwWOaNfZzK7vL6Ee4m-85vZVCH0rjOgqVAww,4913
50
- buz/event/infrastructure/buz_kafka/base_buz_aiokafka_async_consumer.py,sha256=pQQf9ASWg_Y84BxHHATOqiewZA_Ty7Oja_kuvS7H9cw,20688
50
+ buz/event/infrastructure/buz_kafka/base_buz_aiokafka_async_consumer.py,sha256=f7JySj4x2vIWFuJWLMJ_YthZ3V-O0_csbruWh_MFqAM,20686
51
51
  buz/event/infrastructure/buz_kafka/buz_aiokafka_async_consumer.py,sha256=DRe3u69LD7Yt9WjA_hK_PRznM08_Mz4hxC_4poppjck,6446
52
52
  buz/event/infrastructure/buz_kafka/buz_aiokafka_multi_threaded_consumer.py,sha256=-pJVJq3b2SFmPT7SNmdPhqN2o64Hsjwds-shQ-Y7ytg,6389
53
53
  buz/event/infrastructure/buz_kafka/buz_kafka_event_bus.py,sha256=ymRSvcYVgbVCPgHN6rMBVBHQ5heCSwCDl6EffyqGVX8,4601
@@ -164,7 +164,7 @@ buz/kafka/domain/services/kafka_admin_test_client.py,sha256=91l_vFIo1yhJLQQCC_Om
164
164
  buz/kafka/domain/services/kafka_producer.py,sha256=8bLTV328orrPHcARzkc6no4vyJzrArVtCsjmSRXDjos,506
165
165
  buz/kafka/infrastructure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
166
166
  buz/kafka/infrastructure/aiokafka/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
167
- buz/kafka/infrastructure/aiokafka/aiokafka_consumer.py,sha256=5m9XfSRH15wNblqpb-l8cqqIEtDFbpwySzYK_hSuXc4,8952
167
+ buz/kafka/infrastructure/aiokafka/aiokafka_consumer.py,sha256=_fuAuYlfWNaV92osy0Vo8-4-30lvWBECHgxzOvqeARU,9775
168
168
  buz/kafka/infrastructure/aiokafka/aiokafka_producer.py,sha256=LteHKIHpT6MKplwmwsPYMsd2GWNJCzus65XDHCIdoN8,3823
169
169
  buz/kafka/infrastructure/aiokafka/rebalance/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
170
170
  buz/kafka/infrastructure/aiokafka/rebalance/kafka_callback_rebalancer.py,sha256=3l7NkTrCt3rBktVIS73cTmCOvv6eFguoCbGMYIUfCFc,1774
@@ -250,7 +250,7 @@ buz/serializer/message_to_json_bytes_serializer.py,sha256=RGZJ64t4t4Pz2FCASZZCv-
250
250
  buz/wrapper/__init__.py,sha256=GnRdJFcncn-qp0hzDG9dBHLmTJSbHFVjE_yr-MdW_n4,77
251
251
  buz/wrapper/async_to_sync.py,sha256=OfK-vrVUhuN-LLLvekLdMbQYtH0ue5lfbvuasj6ovMI,698
252
252
  buz/wrapper/event_loop.py,sha256=pfBJ1g-8A2a3YgW8Gf9Fg0kkewoh3-wgTy2KIFDyfHk,266
253
- buz-2.15.10rc1.dist-info/LICENSE,sha256=Jytu2S-2SPEgsB0y6BF-_LUxIWY7402fl0JSh36TLZE,1062
254
- buz-2.15.10rc1.dist-info/METADATA,sha256=bUl0KIsBwcN6w-eRU9C5zf_ZTaGk2o8ZnECnaaVUkck,1601
255
- buz-2.15.10rc1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
256
- buz-2.15.10rc1.dist-info/RECORD,,
253
+ buz-2.15.10rc2.dist-info/LICENSE,sha256=Jytu2S-2SPEgsB0y6BF-_LUxIWY7402fl0JSh36TLZE,1062
254
+ buz-2.15.10rc2.dist-info/METADATA,sha256=b4Qv4eJ7br6183jmTGmVlSzo1FNnQpZcXktW4LELzQY,1601
255
+ buz-2.15.10rc2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
256
+ buz-2.15.10rc2.dist-info/RECORD,,