-
Notifications
You must be signed in to change notification settings - Fork 22
added subject filtering at produce function #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,10 @@ def __init__(self): | |
| self.schema_updates_data = {} | ||
| self.partition_producers_updates_data = {} | ||
| self.partition_consumers_updates_data = {} | ||
| self.functions_updates_data = {} | ||
| self.functions_updates_subs = {} | ||
| self.functions_tasks = {} | ||
| self.functions_clients_per_station = {} | ||
| self.schema_updates_subs = {} | ||
| self.clients_per_station = {} | ||
| self.schema_tasks = {} | ||
|
|
@@ -468,6 +472,10 @@ async def producer( | |
|
|
||
| self.update_schema_data(station_name) | ||
|
|
||
| if "station_version" in create_res: | ||
| if create_res["station_version"] > 0: | ||
| await self.start_listen_for_functions_updates(internal_station_name, create_res["station_partitions_first_functions"]) | ||
|
|
||
| producer = Producer(self, producer_name, station_name, real_name) | ||
| map_key = internal_station_name + "_" + real_name | ||
| self.producers_map[map_key] = producer | ||
|
|
@@ -545,6 +553,39 @@ def parse_descriptor(self, station_name): | |
| except Exception as e: | ||
| raise MemphisError(str(e)) from e | ||
|
|
||
| async def start_listen_for_functions_updates(self, station_name, first_functions): | ||
| #first_functions should contain the dict of the first function of each partition key: partition number, value: first function id | ||
|
|
||
| if station_name in self.functions_updates_subs: | ||
| self.functions_clients_per_station[station_name] += 1 | ||
| return | ||
| else: | ||
| self.functions_clients_per_station[station_name] = 1 | ||
|
|
||
| functions_updates_subject = "$memphis_functions_updates_" + station_name | ||
|
|
||
| if len(first_functions) == 0: | ||
| self.functions_updates_data[station_name] = {} | ||
| else: | ||
| self.functions_updates_data[station_name] = first_functions | ||
|
|
||
| sub = await self.broker_manager.subscribe(functions_updates_subject) | ||
| self.functions_updates_subs[station_name] = sub | ||
|
|
||
| loop = asyncio.get_event_loop() | ||
| task = loop.create_task( | ||
| self.get_msg_functions_updates( | ||
| station_name, self.functions_updates_subs[station_name].messages | ||
| ) | ||
| ) | ||
| self.functions_tasks[station_name] = task | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please cancel these tasks and stop all functions operation where needed, when destroying producers/stations and on connection close, like we are doing in Schemaverse
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I handle the destruction in producer.py line: 264 |
||
|
|
||
| async def get_msg_functions_updates(self, station_name, iterable): | ||
| async for msg in iterable: | ||
| message = msg.data.decode("utf-8") | ||
| message = json.loads(message) | ||
| self.functions_updates_data[station_name] = message["functions"] | ||
|
|
||
| async def start_listen_for_schema_updates(self, station_name, schema_update_data): | ||
| schema_updates_subject = "$memphis_schema_updates_" + station_name | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.