From d99b40317d76d8497d06ab2a650c4b13da0cacc0 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 7 Nov 2022 10:21:52 -0500 Subject: [PATCH] Add a `pikerd -p ` flag --- piker/_daemon.py | 10 ++++++++-- piker/cli/__init__.py | 27 ++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/piker/_daemon.py b/piker/_daemon.py index 1dfebae3..64c22875 100644 --- a/piker/_daemon.py +++ b/piker/_daemon.py @@ -35,7 +35,12 @@ log = get_logger(__name__) _root_dname = 'pikerd' -_registry_addr = ('127.0.0.1', 6116) +_registry_host: str = '127.0.0.1' +_registry_port: int = 6116 +_registry_addr = ( + _registry_host, + _registry_port, +) _tractor_kwargs: dict[str, Any] = { # use a different registry addr then tractor's default 'arbiter_addr': _registry_addr @@ -135,6 +140,7 @@ async def open_pikerd( # XXX: you should pretty much never want debug mode # for data daemons when running in production. debug_mode: bool = False, + registry_addr: None | tuple[str, int] = None, ) -> Optional[tractor._portal.Portal]: ''' @@ -153,7 +159,7 @@ async def open_pikerd( tractor.open_root_actor( # passed through to ``open_root_actor`` - arbiter_addr=_registry_addr, + arbiter_addr=registry_addr or _registry_addr, name=_root_dname, loglevel=loglevel, debug_mode=debug_mode, diff --git a/piker/cli/__init__.py b/piker/cli/__init__.py index c87f9751..4bfd134a 100644 --- a/piker/cli/__init__.py +++ b/piker/cli/__init__.py @@ -27,7 +27,11 @@ import tractor from ..log import get_console_log, get_logger, colorize_json from ..brokers import get_brokermod -from .._daemon import _tractor_kwargs +from .._daemon import ( + _tractor_kwargs, + _registry_host, + _registry_port, +) from .. import config @@ -39,13 +43,21 @@ DEFAULT_BROKER = 'questrade' @click.option('--loglevel', '-l', default='warning', help='Logging level') @click.option('--tl', is_flag=True, help='Enable tractor logging') @click.option('--pdb', is_flag=True, help='Enable tractor debug mode') -@click.option('--host', '-h', default='127.0.0.1', help='Host address to bind') +@click.option('--host', '-h', default=None, help='Host addr to bind') +@click.option('--port', '-p', default=None, help='Port number to bind') @click.option( '--tsdb', is_flag=True, help='Enable local ``marketstore`` instance' ) -def pikerd(loglevel, host, tl, pdb, tsdb): +def pikerd( + loglevel: str, + host: str, + port: int, + tl: bool, + pdb: bool, + tsdb: bool, +): ''' Spawn the piker broker-daemon. @@ -62,12 +74,21 @@ def pikerd(loglevel, host, tl, pdb, tsdb): "\n" )) + reg_addr: None | tuple[str, int] = None + if host or port: + reg_addr = ( + host or _registry_host, + int(port) or _registry_port, + ) + async def main(): async with ( open_pikerd( loglevel=loglevel, debug_mode=pdb, + registry_addr=reg_addr, + ), # normally delivers a ``Services`` handle trio.open_nursery() as n, ):