Skip to content

Commit

Permalink
use singleton on subscribers.
Browse files Browse the repository at this point in the history
  • Loading branch information
hoseinaghaei committed Feb 15, 2024
1 parent 0e3df39 commit 2bc2687
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kafka_server/broker/file/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def __new__(cls, *args, **kwargs):
return cls._instance

def __init__(self, partition: str, replica: str):
self.subscribers = None
if not hasattr(self, 'initialized'):
self.partition = partition
self.message_in_fly = False
self.message_in_fly_since = datetime.now()
self.segment = Segment(partition, replica)
self.subscribers = self.get_subscribers()
self.initialized = True

self.toggle_thread = threading.Thread(target=self.toggle_message_in_fly)
Expand All @@ -51,7 +51,9 @@ def toggle_message_in_fly(self):
time.sleep(5)

def read_data(self):
self.subscribers = self.get_subscribers()
if len(self.subscribers) == 0:
self.subscribers = self.get_subscribers()

if len(self.subscribers) == 0:
print("No subscribers")
return None, None
Expand Down

0 comments on commit 2bc2687

Please sign in to comment.