Don't run brokerds in debug mode by default

basic_orders
Tyler Goodlet 2021-03-11 21:44:10 -05:00
parent d016abcd0d
commit 624617d8e1
2 changed files with 20 additions and 10 deletions

View File

@ -87,9 +87,11 @@ _data_mods = [
@asynccontextmanager @asynccontextmanager
async def maybe_spawn_brokerd( async def maybe_spawn_brokerd(
brokername: str, brokername: str,
sleep: float = 0.5,
loglevel: Optional[str] = None, loglevel: Optional[str] = None,
**tractor_kwargs,
# XXX: you should pretty much never want debug mode
# for data daemons when running in production.
debug_mode: bool = False,
) -> tractor._portal.Portal: ) -> tractor._portal.Portal:
"""If no ``brokerd.{brokername}`` daemon-actor can be found, """If no ``brokerd.{brokername}`` daemon-actor can be found,
spawn one in a local subactor and return a portal to it. spawn one in a local subactor and return a portal to it.
@ -97,11 +99,6 @@ async def maybe_spawn_brokerd(
if loglevel: if loglevel:
get_console_log(loglevel) get_console_log(loglevel)
# disable debugger in brokerd?
# tractor._state._runtime_vars['_debug_mode'] = False
tractor_kwargs['loglevel'] = loglevel
brokermod = get_brokermod(brokername) brokermod = get_brokermod(brokername)
dname = f'brokerd.{brokername}' dname = f'brokerd.{brokername}'
async with tractor.find_actor(dname) as portal: async with tractor.find_actor(dname) as portal:
@ -113,18 +110,25 @@ async def maybe_spawn_brokerd(
else: # no daemon has been spawned yet else: # no daemon has been spawned yet
log.info(f"Spawning {brokername} broker daemon") log.info(f"Spawning {brokername} broker daemon")
# retrieve any special config from the broker mod
tractor_kwargs = getattr(brokermod, '_spawn_kwargs', {}) tractor_kwargs = getattr(brokermod, '_spawn_kwargs', {})
async with tractor.open_nursery() as nursery:
async with tractor.open_nursery(
debug_mode=False,
) as nursery:
try: try:
# spawn new daemon # spawn new daemon
portal = await nursery.start_actor( portal = await nursery.start_actor(
dname, dname,
enable_modules=_data_mods + [brokermod.__name__], enable_modules=_data_mods + [brokermod.__name__],
loglevel=loglevel, loglevel=loglevel,
debug_mode=debug_mode,
**tractor_kwargs **tractor_kwargs
) )
async with tractor.wait_for_actor(dname) as portal: async with tractor.wait_for_actor(dname) as portal:
yield portal yield portal
finally: finally:
# client code may block indefinitely so cancel when # client code may block indefinitely so cancel when
# teardown is invoked # teardown is invoked
@ -235,9 +239,15 @@ async def open_feed(
) )
async with maybe_spawn_brokerd( async with maybe_spawn_brokerd(
brokername, brokername,
loglevel=loglevel, loglevel=loglevel,
# TODO: add a cli flag for this
debug_mode=False,
) as portal: ) as portal:
stream = await portal.run( stream = await portal.run(
mod.stream_quotes, mod.stream_quotes,

View File

@ -91,7 +91,7 @@ def monitor(config, rate, name, dhost, test, tl):
@click.option('--rate', '-r', default=1, help='Logging level') @click.option('--rate', '-r', default=1, help='Logging level')
@click.argument('symbol', required=True) @click.argument('symbol', required=True)
@click.pass_obj @click.pass_obj
def optschain(config, symbol, date, tl, rate, test): def optschain(config, symbol, date, rate, test):
"""Start an option chain UI """Start an option chain UI
""" """
# global opts # global opts
@ -117,7 +117,7 @@ def optschain(config, symbol, date, tl, rate, test):
tractor.run( tractor.run(
partial(main, tries=1), partial(main, tries=1),
name='kivy-options-chain', name='kivy-options-chain',
loglevel=loglevel if tl else None, # loglevel=loglevel if tl else None,
) )