Skip to content

Commit e6b4b89

Browse files
Add DataSourcingActor (#52)
Closes #30
2 parents a852f49 + ebca3fa commit e6b4b89

File tree

7 files changed

+627
-6
lines changed

7 files changed

+627
-6
lines changed

noxfile.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ def mypy(session: nox.Session, install_deps: bool = True) -> None:
6868
# Since we use other packages in the frequenz namespace, we need to run the
6969
# checks for frequenz.sdk from the installed package instead of the src
7070
# directory.
71-
mypy_paths = [path for path in source_file_paths(session)
72-
if not path.startswith("src")]
71+
mypy_paths = [
72+
path for path in source_file_paths(session) if not path.startswith("src")
73+
]
7374

7475
mypy_cmd = [
7576
"mypy",
@@ -115,10 +116,7 @@ def docstrings(session: nox.Session, install_deps: bool = True) -> None:
115116
# This is needed only for the `src` dir, so we exclude the other top level
116117
# dirs that contain code.
117118
darglint_paths = filter(
118-
lambda path: not (
119-
path.startswith("tests")
120-
or path.startswith("benchmarks")
121-
),
119+
lambda path: not (path.startswith("tests") or path.startswith("benchmarks")),
122120
source_file_paths(session),
123121
)
124122
session.run(
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
The DataSourcingActor.
3+
4+
Copyright
5+
Copyright © 2021 Frequenz Energy-as-a-Service GmbH
6+
7+
License
8+
MIT
9+
"""
10+
11+
from .data_sourcing import DataSourcingActor
12+
13+
__all__ = [
14+
"DataSourcingActor",
15+
]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""The DataSourcing Actor.
2+
3+
Copyright
4+
Copyright © 2022 Frequenz Energy-as-a-Service GmbH
5+
6+
License
7+
MIT
8+
"""
9+
10+
from frequenz.channels import Receiver
11+
12+
from frequenz.sdk.actor import actor
13+
from frequenz.sdk.actor.channel_registry import ChannelRegistry
14+
from frequenz.sdk.data_pipeline import ComponentMetricRequest
15+
16+
from .microgrid_api_source import MicrogridApiSource
17+
18+
19+
@actor
20+
class DataSourcingActor:
21+
"""An actor that provides data streams of metrics as time series."""
22+
23+
def __init__(
24+
self,
25+
request_receiver: Receiver[ComponentMetricRequest],
26+
registry: ChannelRegistry,
27+
) -> None:
28+
"""Create a `DataSourcingActor` instance.
29+
30+
Args:
31+
request_receiver: A channel receiver to accept metric requests from.
32+
registry: A channel registry. To be replaced by a singleton
33+
instance.
34+
"""
35+
self._request_receiver = request_receiver
36+
self._microgrid_api_source = MicrogridApiSource(registry)
37+
38+
async def run(self) -> None:
39+
"""Run the actor."""
40+
async for request in self._request_receiver:
41+
await self._microgrid_api_source.add_metric(request)

0 commit comments

Comments
 (0)