27
27
The exact value is not important, but should be a few hours and not more than a day.
28
28
"""
29
29
30
+ _DEFAULT_POLL_INTERVAL = timedelta (seconds = 10 )
31
+ """The default interval to poll the API for dispatch changes."""
32
+
30
33
_logger = logging .getLogger (__name__ )
31
34
"""The logger for this module."""
32
35
@@ -99,6 +102,7 @@ def __init__(
99
102
svc_addr : str ,
100
103
updated_dispatch_sender : Sender [DispatchEvent ],
101
104
ready_dispatch_sender : Sender [Dispatch ],
105
+ poll_interval : timedelta = _DEFAULT_POLL_INTERVAL ,
102
106
) -> None :
103
107
"""Initialize the actor.
104
108
@@ -108,6 +112,7 @@ def __init__(
108
112
svc_addr: Address of the service to connect to.
109
113
updated_dispatch_sender: A sender for new or updated dispatches.
110
114
ready_dispatch_sender: A sender for ready dispatches.
115
+ poll_interval: The interval to poll the API for dispatche changes.
111
116
"""
112
117
super ().__init__ (name = "dispatch" )
113
118
@@ -117,13 +122,14 @@ def __init__(
117
122
self ._microgrid_id = microgrid_id
118
123
self ._updated_dispatch_sender = updated_dispatch_sender
119
124
self ._ready_dispatch_sender = ready_dispatch_sender
125
+ self ._poll_interval = poll_interval
120
126
121
127
async def _run (self ) -> None :
122
128
"""Run the actor."""
123
129
try :
124
130
while True :
125
131
await self ._fetch ()
126
- await asyncio .sleep (_MAX_AHEAD_SCHEDULE .total_seconds ())
132
+ await asyncio .sleep (self . _poll_interval .total_seconds ())
127
133
except asyncio .CancelledError :
128
134
for task in self ._scheduled .values ():
129
135
task .cancel ()
0 commit comments