How to use the aiozk.WatchEvent.CREATED function in aiozk

To help you get started, we’ve selected a few aiozk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github micro-fan / aiozk / aiozk / recipes / base_watcher.py View on Github external
try:
                result = await self.fetch(path)
            except exc.NoNode:
                result = exc.NoNode
            except exc.ZKError as e:
                log.exception('Exception in watch loop: {}'.format(e))
                log.info('Waiting for safe state...')
                await self.client.session.ensure_safe_state()
                continue
            except Exception:
                log.exception('Not handled in watch loop:')
                raise

            for callback in self.callbacks[path].copy():
                maybe_future(callback(result), loop=self.client.loop)
            if WatchEvent.CREATED not in self.watched_events and result == exc.NoNode:
                return
            try:
                await self.client.wait_for_events(self.watched_events, path)
            except asyncio.CancelledError:
                pass
            except Exception as e:
                log.exception('Not handled in wait_for_events:')
                print('Not handled: {!r}'.format(e))
                raise
github micro-fan / aiozk / aiozk / recipes / double_barrier.py View on Github external
async def enter(self, timeout=None):
        log.debug("Entering double barrier %s", self.base_path)
        barrier_lifted = self.client.wait_for_events(
            [WatchEvent.CREATED], self.sentinel_path
        )

        exists = await self.client.exists(path=self.sentinel_path, watch=True)

        await self.create_unique_znode("worker")

        _, participants = await self.analyze_siblings()

        if exists:
            return

        elif len(participants) >= self.min_participants:
            await self.create_znode(self.sentinel_path)
            return

        try:
github micro-fan / aiozk / aiozk / recipes / data_watcher.py View on Github external
async def fetch(self, path):
        # exists() gives create, delete, and update watches
        watch_via_exists = WatchEvent.CREATED in self.watched_events
        if watch_via_exists:
            exists = await self.client.exists(path, watch=True)
            if not exists:
                raise NoNode
        data = await self.client.get_data(path=path, watch=not watch_via_exists)
        return data
github micro-fan / aiozk / aiozk / recipes / data_watcher.py View on Github external
def __init__(self, *args, wait_for_create=False, **kwargs):
        super().__init__(*args, **kwargs)

        if wait_for_create:
            self.watched_events.append(WatchEvent.CREATED)