From 8ce37875a02990f514ee4424cae2da83f43a7b64 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 22 Mar 2021 09:24:38 -0400 Subject: [PATCH] Use pikerd to spawn emsd --- piker/clearing/_client.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/piker/clearing/_client.py b/piker/clearing/_client.py index 0fa23e60..97412280 100644 --- a/piker/clearing/_client.py +++ b/piker/clearing/_client.py @@ -168,27 +168,28 @@ async def send_order_cmds(): @asynccontextmanager async def maybe_open_emsd( -) -> 'StreamReceiveChannel': # noqa + brokername: str, +) -> tractor._portal.Portal: # noqa async with tractor.find_actor('emsd') as portal: if portal is not None: yield portal else: - # we gotta spawn it - log.info("Spawning EMS daemon") + # ask remote daemon tree to spawn it + from .._daemon import spawn_emsd - # TODO: add ``maybe_spawn_emsd()`` for this - async with tractor.open_nursery() as n: + async with tractor.find_actor('pikerd') as portal: - portal = await n.start_actor( - 'emsd', - enable_modules=[ - 'piker.exchange._ems', - ], - ) + if portal is not None: - yield portal + name = await portal.run( + spawn_emsd, + brokername=brokername, + ) + + async with tractor.wait_for_actor(name) as portal: + yield portal @asynccontextmanager @@ -235,7 +236,7 @@ async def open_ems( # ready for order commands book = get_orders() - async with maybe_open_emsd() as portal: + async with maybe_open_emsd(broker) as portal: trades_stream = await portal.run( _emsd_main,