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 @asynccontextmanager
async def maybe_open_emsd( async def maybe_open_emsd(
) -> 'StreamReceiveChannel': # noqa brokername: str,
) -> tractor._portal.Portal: # noqa
async with tractor.find_actor('emsd') as portal: async with tractor.find_actor('emsd') as portal:
if portal is not None: if portal is not None:
yield portal yield portal
else: else:
# we gotta spawn it # ask remote daemon tree to spawn it
log.info("Spawning EMS daemon") from .._daemon import spawn_emsd
# TODO: add ``maybe_spawn_emsd()`` for this async with tractor.find_actor('pikerd') as portal:
async with tractor.open_nursery() as n:
portal = await n.start_actor( if portal is not None:
'emsd',
enable_modules=[ name = await portal.run(
'piker.exchange._ems', spawn_emsd,
], brokername=brokername,
) )
async with tractor.wait_for_actor(name) as portal:
yield portal yield portal
@ -235,7 +236,7 @@ async def open_ems(
# ready for order commands # ready for order commands
book = get_orders() book = get_orders()
async with maybe_open_emsd() as portal: async with maybe_open_emsd(broker) as portal:
trades_stream = await portal.run( trades_stream = await portal.run(
_emsd_main, _emsd_main,