Skip to content

Commit

Permalink
Merge pull request #174 from salute-developers/fix/PNLP-7915_fix_Ille…
Browse files Browse the repository at this point in the history
…galStateError

PNLP-7915: fix IllegalStateError
  • Loading branch information
SyrexMinus authored Dec 11, 2023
2 parents bda0ede + 0956bf2 commit caade20
Showing 1 changed file with 1 addition and 24 deletions.
25 changes: 1 addition & 24 deletions core/mq/kafka/kafka_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,6 @@ def __init__(self, config: Dict[str, Any], loop: AbstractEventLoop):
self._consumer = AIOKafkaConsumer(**conf, loop=loop)
loop.run_until_complete(self._consumer.start())

def on_assign_offset_end(self, consumer: AIOKafkaConsumer, partitions: List[TopicPartition]) -> None:
for p in partitions:
p.offset = consumer.last_stable_offset(p)
self.on_assign_log(consumer, partitions)
try:
consumer.assign(partitions)
except KafkaError as e:
self._error_callback(e)

def on_coop_assign_offset_end(self, consumer: AIOKafkaConsumer, partitions: List[TopicPartition]) -> None:
for p in partitions:
p.offset = consumer.last_stable_offset(p)
self.on_assign_log(consumer, partitions)
consumer.assign(consumer.assignment().update(partitions))

def on_assign_log(self, consumer: AIOKafkaConsumer, partitions: List[TopicPartition]) -> None:
log_level = "WARNING"
params = {
Expand All @@ -77,19 +62,11 @@ def subscribe(self, topics: Optional[Iterable[str]] = None) -> None:
try:
self._consumer.subscribe(topics, listener=CoreConsumerRebalanceListener(
consumer=self._consumer,
on_assign_callback=(self.get_on_assign_callback() if self.assign_offset_end
else self.on_assign_log)
on_assign_callback=self.on_assign_log
))
except KafkaError as e:
self._error_callback(e)

def get_on_assign_callback(self) -> Callable[[AIOKafkaConsumer, List[TopicPartition]], None]:
if "cooperative" in self._config["conf"].get("partition_assignment_strategy", ""):
callback = self.on_coop_assign_offset_end
else:
callback = self.on_assign_offset_end
return callback

def unsubscribe(self) -> None:
self._consumer.unsubscribe()

Expand Down

0 comments on commit caade20

Please sign in to comment.