Skip to content

Commit d24ec9f

Browse files
committed
Make poll interval configurable
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent a0b1839 commit d24ec9f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/frequenz/dispatch/actor.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
The exact value is not important, but should be a few hours and not more than a day.
2828
"""
2929

30+
_DEFAULT_POLL_INTERVAL = timedelta(seconds=10)
31+
"""The default interval to poll the API for dispatch changes."""
32+
3033
_logger = logging.getLogger(__name__)
3134
"""The logger for this module."""
3235

@@ -99,6 +102,7 @@ def __init__(
99102
svc_addr: str,
100103
updated_dispatch_sender: Sender[DispatchEvent],
101104
ready_dispatch_sender: Sender[Dispatch],
105+
poll_interval: timedelta = _DEFAULT_POLL_INTERVAL,
102106
) -> None:
103107
"""Initialize the actor.
104108
@@ -108,6 +112,7 @@ def __init__(
108112
svc_addr: Address of the service to connect to.
109113
updated_dispatch_sender: A sender for new or updated dispatches.
110114
ready_dispatch_sender: A sender for ready dispatches.
115+
poll_interval: The interval to poll the API for dispatche changes.
111116
"""
112117
super().__init__(name="dispatch")
113118

@@ -117,13 +122,14 @@ def __init__(
117122
self._microgrid_id = microgrid_id
118123
self._updated_dispatch_sender = updated_dispatch_sender
119124
self._ready_dispatch_sender = ready_dispatch_sender
125+
self._poll_interval = poll_interval
120126

121127
async def _run(self) -> None:
122128
"""Run the actor."""
123129
try:
124130
while True:
125131
await self._fetch()
126-
await asyncio.sleep(_MAX_AHEAD_SCHEDULE.total_seconds())
132+
await asyncio.sleep(self._poll_interval.total_seconds())
127133
except asyncio.CancelledError:
128134
for task in self._scheduled.values():
129135
task.cancel()

0 commit comments

Comments
 (0)