Skip to content

Duplicated translator code maybe? #226

Description

@samoehlert
async def websocket_loop():
    """Connect to the websocket and start listening for messages for Gobgp."""
    logger.info("connecting to gobgp at %s", settings.gobgp_url)
    g = GoBGP(settings.gobgp_url)
    async for websocket in websockets.connect(settings.scram_events_url):
        try:
            async for message in websocket:
                await process(message, websocket, g)
        except websockets.ConnectionClosed:
            continue

Seems really close to main() at least as far connecting to the websocket

async def main():
    """Connect to the websocket and start listening for messages."""
    while True:
        try:
            logger.debug("connecting to gobgp at %s", settings.gobgp_url)
            g = GoBGP(settings.gobgp_url)
            async for websocket in websockets.connect(settings.scram_events_url):
                heartbeat_task = asyncio.create_task(heartbeat(websocket, g))
                try:
                    async for message in websocket:
                        await process(message, websocket, g)
                except websockets.ConnectionClosed:
                    heartbeat_task.cancel()
                    continue
                finally:
                    heartbeat_task.cancel()
        except RpcError as e:
            logger.warning("Encountered an error connecting to gobgp, retrying in 10s, error is: %s", e)
            await asyncio.sleep(10)
        except Exception:
            logger.exception("Unexpected error in main loop, retrying in 10s")
            await asyncio.sleep(10)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions