From b9af6176c5e0929595fba4112e4eb605505ac1d3 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 7 Dec 2023 12:31:12 -0500 Subject: [PATCH] Factor `TimeseriesNotFound` to top level TO CHERRY into #486 --- piker/data/history.py | 21 ++++++++++++++------- piker/storage/__init__.py | 7 +++++++ piker/storage/nativedb.py | 10 +++------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/piker/data/history.py b/piker/data/history.py index 9d110bb2..4026121b 100644 --- a/piker/data/history.py +++ b/piker/data/history.py @@ -57,6 +57,7 @@ from ._sampling import ( from ..brokers._util import ( DataUnavailable, ) +from ..storage import TimeseriesNotFound if TYPE_CHECKING: from bidict import bidict @@ -690,13 +691,18 @@ async def tsdb_backfill( # but if not then below the remaining history can be lazy # loaded? fqme: str = mkt.fqme - tsdb_entry: tuple | None = await storage.load( - fqme, - timeframe=timeframe, - ) - last_tsdb_dt: datetime | None = None - if tsdb_entry: + try: + tsdb_entry: tuple | None = await storage.load( + fqme, + timeframe=timeframe, + ) + except TimeseriesNotFound: + log.warning( + f'No timeseries yet for {fqme}' + ) + + else: ( tsdb_history, first_tsdb_dt, @@ -963,7 +969,8 @@ async def manage_history( sub_for_broadcasts=False, ) as sample_stream: - # register 1s and 1m buffers with the global incrementer task + # register 1s and 1m buffers with the global + # incrementer task log.info(f'Connected to sampler stream: {sample_stream}') for timeframe in [60, 1]: diff --git a/piker/storage/__init__.py b/piker/storage/__init__.py index 7830efe5..f32f40b6 100644 --- a/piker/storage/__init__.py +++ b/piker/storage/__init__.py @@ -139,6 +139,13 @@ class StorageClient( ... +class TimeseriesNotFound(Exception): + ''' + No timeseries entry can be found for this backend. + + ''' + + class StorageConnectionError(ConnectionError): ''' Can't connect to the desired tsdb subsys/service. diff --git a/piker/storage/nativedb.py b/piker/storage/nativedb.py index 4bafc5a2..f4ecfbea 100644 --- a/piker/storage/nativedb.py +++ b/piker/storage/nativedb.py @@ -19,7 +19,8 @@ call a poor man's tsdb). AKA a `piker`-native file-system native "time series database" -without needing an extra process and no standard TSDB features, YET! +without needing an extra process and no standard TSDB features, +YET! ''' # TODO: like there's soo much.. @@ -67,17 +68,12 @@ from piker import config from piker.data import def_iohlcv_fields from piker.data import ShmArray from piker.log import get_logger +from . import TimeseriesNotFound log = get_logger('storage.nativedb') -class TimeseriesNotFound(Exception): - ''' - No timeseries entry can be found for this backend. - - ''' - # NOTE: thanks to this SO answer for the below conversion routines # to go from numpy struct-arrays to polars dataframes and back: # https://stackoverflow.com/a/72054819