Skip to content

Commit

Permalink
Refactorization in the Zookeeper advertise code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ateska committed Feb 10, 2023
1 parent 55145f1 commit 5797bad
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions asab/zookeeper/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def on_watcher_trigger():
self.App.PubSub.publish(self.App.PubSub.publish("ZooKeeper.watcher!", data, stat))
self.App.Loop.call_soon_threadsafe(on_watcher_trigger)


async def create_watcher(self, client, path):
# Do this in executor
watcher = kazoo.recipe.watchers.DataWatch(client, path, func=self._on_watcher_trigger)
Expand Down Expand Up @@ -149,17 +148,8 @@ async def _do_advertise(self, zoocontainer):
await zoocontainer.ZooKeeper.set_data(self.Node, self.Data)
return

# Parms description
# self.Path. Path to be created
# self.Data. Data in the path
# sequential=True. Path is suffixed with a unique index.
# ephemeral=True. Node created is ephemeral

async def create():
self.Node = await zoocontainer.ZooKeeper.create(self.Path, self.Data, True, True)

try:
await create()
self.Node = await zoocontainer.ZooKeeper.create(self.Path, self.Data, sequential=True, ephemeral=True)
except kazoo.exceptions.NoNodeError:
await zoocontainer.ZooKeeper.ensure_path(self.Path.rstrip(self.Path.split("/")[-1]))
await create()
self.Node = await zoocontainer.ZooKeeper.create(self.Path, self.Data, sequential=True, ephemeral=True)

0 comments on commit 5797bad

Please sign in to comment.