Use pikerd to spawn emsd

supervise
Tyler Goodlet 2021-03-22 09:24:38 -04:00
parent 1931da97f4
commit 8ce37875a0
1 changed files with 14 additions and 13 deletions

View File

@ -168,26 +168,27 @@ 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:
name = await portal.run(
spawn_emsd,
brokername=brokername,
)
async with tractor.wait_for_actor(name) as portal:
yield portal
@ -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,