From 9ddfae44d245df9ac81931b71ab62fae4f1e226a Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 10 May 2022 13:32:56 -0400 Subject: [PATCH] Parametrize and deliver (relevant) mkts config in `start_ahab()` --- piker/cli/__init__.py | 31 ++++++++++++++++++++++++++----- piker/data/_ahab.py | 34 ++++++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/piker/cli/__init__.py b/piker/cli/__init__.py index 721b2123..7d58ff4d 100644 --- a/piker/cli/__init__.py +++ b/piker/cli/__init__.py @@ -1,7 +1,25 @@ -""" +# piker: trading gear for hackers +# Copyright (C) 2018-present Tyler Goodlet (in stewardship of pikers) + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +''' CLI commons. -""" + +''' import os +from pprint import pformat import click import trio @@ -59,12 +77,15 @@ def pikerd(loglevel, host, tl, pdb, tsdb): from piker.data._ahab import start_ahab log.info('Spawning `marketstore` supervisor') - ctn_ready = await n.start( + ctn_ready, config, (cid, pid) = await n.start( start_ahab, 'marketstored', ) - await ctn_ready.wait() - log.info('`marketstore` container:{uid} up') + log.info( + f'`marketstored` up pid:{pid}\n' + f'container up cid:{cid} live with config:\n' + f'{pformat(config)}' + ) await trio.sleep_forever() diff --git a/piker/data/_ahab.py b/piker/data/_ahab.py index 08da0fff..87f7ef59 100644 --- a/piker/data/_ahab.py +++ b/piker/data/_ahab.py @@ -1,5 +1,5 @@ # piker: trading gear for hackers -# Copyright (C) 2018-present Tyler Goodlet (in stewardship of piker0) +# Copyright (C) 2018-present Tyler Goodlet (in stewardship of pikers) # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -21,7 +21,7 @@ Supervisor for docker with included specific-image service helpers. import os from typing import ( Optional, - # Any, + Any, ) from contextlib import asynccontextmanager as acm @@ -39,8 +39,13 @@ from .. import config log = get_logger(__name__) +_config = { + 'grpc_listen_port': 5995, + 'ws_listen_port': 5993, + 'log_level': 'debug', +} -_config = ''' +_yaml_config = ''' # piker's ``marketstore`` config. # mount this config using: @@ -49,9 +54,9 @@ _config = ''' # 5993:5993 alpacamarkets/marketstore:latest root_directory: data -listen_port: 5993 -grpc_listen_port: 5995 -log_level: debug +listen_port: {ws_listen_port} +grpc_listen_port: {grpc_listen_port} +log_level: {log_level} queryable: true stop_grace_period: 0 wal_rotate_interval: 5 @@ -76,7 +81,7 @@ triggers: # config: # filter: "nasdaq" -''' +'''.format(**_config) class DockerNotStarted(Exception): @@ -350,7 +355,12 @@ async def open_marketstored( async def start_ahab( service_name: str, - task_status: TaskStatus[trio.Event] = trio.TASK_STATUS_IGNORED, + task_status: TaskStatus[ + tuple[ + trio.Event, + dict[str, Any], + ], + ] = trio.TASK_STATUS_IGNORED, ) -> None: ''' @@ -389,14 +399,18 @@ async def start_ahab( )[2] # named user's uid ) - task_status.started(cn_ready) - async with portal.open_context( open_marketstored, ) as (ctx, first): cid, pid = first + task_status.started(( + cn_ready, + _config, + (cid, pid), + )) + await trio.sleep_forever() # since we demoted root perms in this parent