Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions nominal/core/_stream/write_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,23 @@ def sort_key(cls, item: Self) -> tuple[str, Sequence[tuple[str, str]], str]:
return item._to_api_batch_key()


DataStream: TypeAlias = WriteStreamBase[str | float | int]
FlexibleTimestampType = str | datetime | IntegralNanosecondsUTC

DataStream: TypeAlias = WriteStreamBase[str | float | int, FlexibleTimestampType]
"""Stream type for asynchronously sending timeseries data to the Nominal backend."""

DataItem: TypeAlias = BatchItem[str | float | int]
"""Individual item of timeseries data to stream to Nominal."""

LogStream: TypeAlias = WriteStreamBase[str]
LogStream: TypeAlias = WriteStreamBase[str, str | datetime | IntegralNanosecondsUTC]
"""Stream type for asynchronously sending log data to the Nominal backend."""

LogItem: TypeAlias = BatchItem[str]
"""Individual item of log data to stream to Nominal."""


@dataclass(frozen=True)
class WriteStream(WriteStreamBase[StreamType]):
class WriteStream(WriteStreamBase[StreamType, FlexibleTimestampType]):
batch_size: int
max_wait: timedelta
_process_batch: Callable[[Sequence[BatchItem[StreamType]]], None]
Expand Down Expand Up @@ -92,7 +94,7 @@ def __exit__(
def enqueue(
self,
channel_name: str,
timestamp: str | datetime | IntegralNanosecondsUTC,
timestamp: FlexibleTimestampType,
value: StreamType,
tags: Mapping[str, str] | None = None,
) -> None:
Expand Down
12 changes: 5 additions & 7 deletions nominal/core/_stream/write_stream_base.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
from __future__ import annotations

import abc
from datetime import datetime
from types import TracebackType
from typing import Generic, Mapping, Sequence, Type, TypeVar

from typing_extensions import Self

from nominal.ts import IntegralNanosecondsUTC

StreamType = TypeVar("StreamType")
TimestampType = TypeVar("TimestampType")


class WriteStreamBase(abc.ABC, Generic[StreamType]):
class WriteStreamBase(abc.ABC, Generic[StreamType, TimestampType]):
@abc.abstractmethod
def __enter__(self) -> Self:
"""Create the stream as a context manager."""
Expand All @@ -27,7 +25,7 @@ def __exit__(
def enqueue(
self,
channel_name: str,
timestamp: str | datetime | IntegralNanosecondsUTC,
timestamp: TimestampType,
value: StreamType,
tags: Mapping[str, str] | None = None,
) -> None:
Expand All @@ -44,7 +42,7 @@ def enqueue(
def enqueue_batch(
self,
channel_name: str,
timestamps: Sequence[str | datetime | IntegralNanosecondsUTC],
timestamps: Sequence[TimestampType],
values: Sequence[StreamType],
tags: Mapping[str, str] | None = None,
) -> None:
Expand All @@ -71,7 +69,7 @@ def enqueue_batch(

def enqueue_from_dict(
self,
timestamp: str | datetime | IntegralNanosecondsUTC,
timestamp: TimestampType,
channel_values: Mapping[str, StreamType],
tags: Mapping[str, str] | None = None,
) -> None:
Expand Down