Add `services` cmd for monitoring actors
parent
e6e06a52cb
commit
bdcf5f884b
|
@ -1135,7 +1135,7 @@ async def stream_quotes(
|
||||||
loglevel: str = None,
|
loglevel: str = None,
|
||||||
# feed_type: str = 'stock',
|
# feed_type: str = 'stock',
|
||||||
) -> AsyncGenerator[str, Dict[str, Any]]:
|
) -> AsyncGenerator[str, Dict[str, Any]]:
|
||||||
# XXX: why do we need this again?
|
# XXX: required to propagate ``tractor`` loglevel to piker logging
|
||||||
get_console_log(tractor.current_actor().loglevel)
|
get_console_log(tractor.current_actor().loglevel)
|
||||||
|
|
||||||
async with get_cached_client('questrade') as client:
|
async with get_cached_client('questrade') as client:
|
||||||
|
|
|
@ -6,9 +6,8 @@ import os
|
||||||
import click
|
import click
|
||||||
import tractor
|
import tractor
|
||||||
|
|
||||||
from ..log import get_console_log, get_logger
|
from ..log import get_console_log, get_logger, colorize_json
|
||||||
from ..brokers import get_brokermod, config
|
from ..brokers import get_brokermod, config
|
||||||
from ..data import maybe_spawn_brokerd
|
|
||||||
|
|
||||||
log = get_logger('cli')
|
log = get_logger('cli')
|
||||||
DEFAULT_BROKER = 'questrade'
|
DEFAULT_BROKER = 'questrade'
|
||||||
|
@ -72,11 +71,38 @@ def cli(ctx, broker, loglevel, tl, configdir):
|
||||||
ctx.obj.update({'tractorloglevel': loglevel})
|
ctx.obj.update({'tractorloglevel': loglevel})
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
@click.option('--tl', is_flag=True, help='Enable tractor logging')
|
||||||
|
@click.argument('names', nargs=-1, required=False)
|
||||||
|
@click.pass_obj
|
||||||
|
def services(config, tl, names):
|
||||||
|
|
||||||
|
async def list_services():
|
||||||
|
async with tractor.get_arbiter(
|
||||||
|
*tractor.current_actor()._arb_addr
|
||||||
|
) as portal:
|
||||||
|
registry = await portal.run('self', 'get_registry')
|
||||||
|
json_d = {}
|
||||||
|
for uid, socket in registry.items():
|
||||||
|
name, uuid = uid
|
||||||
|
host, port = socket
|
||||||
|
json_d[f'{name}.{uuid}'] = f'{host}:{port}'
|
||||||
|
click.echo(
|
||||||
|
f"Available `piker` services:\n{colorize_json(json_d)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
tractor.run(
|
||||||
|
list_services,
|
||||||
|
name='service_query',
|
||||||
|
loglevel=config['loglevel'] if tl else None,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _load_clis() -> None:
|
def _load_clis() -> None:
|
||||||
from ..data import cli as _
|
from ..data import cli as _
|
||||||
from ..brokers import cli as _
|
from ..brokers import cli as _ # noqa
|
||||||
from ..ui import cli as _
|
from ..ui import cli as _ # noqa
|
||||||
from ..watchlists import cli as _
|
from ..watchlists import cli as _ # noqa
|
||||||
|
|
||||||
|
|
||||||
# load downstream cli modules
|
# load downstream cli modules
|
||||||
|
|
Loading…
Reference in New Issue