Skip to content

Commit

Permalink
Factor TimeseriesNotFound to top level
Browse files Browse the repository at this point in the history
TO CHERRY into #486
  • Loading branch information
goodboy committed Dec 7, 2023
1 parent dd0167b commit b9af617
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
21 changes: 14 additions & 7 deletions piker/data/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from ..brokers._util import (
DataUnavailable,
)
from ..storage import TimeseriesNotFound

if TYPE_CHECKING:
from bidict import bidict
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]:
Expand Down
7 changes: 7 additions & 0 deletions piker/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ async def write_ohlcv(
...


class TimeseriesNotFound(Exception):
'''
No timeseries entry can be found for this backend.
'''


class StorageConnectionError(ConnectionError):
'''
Can't connect to the desired tsdb subsys/service.
Expand Down
10 changes: 3 additions & 7 deletions piker/storage/nativedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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..
Expand Down Expand Up @@ -67,17 +68,12 @@
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
Expand Down

0 comments on commit b9af617

Please sign in to comment.