Skip to content

Commit cef414d

Browse files
committed
Add Dispatch.end_time and print it in dispatch-cli
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent 101f0aa commit cef414d

File tree

5 files changed

+16
-1
lines changed

5 files changed

+16
-1
lines changed

RELEASE_NOTES.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Frequenz Dispatch Client Library Release Notes
22

3+
## Features
4+
5+
* `Dispatch.end_time` has been added to the `Dispatch` class, which is the time when the dispatch ended as calculated by the server. `dispatch-cli` will also print this time.
6+
37
## Bug Fixes
48

5-
* Fix that duration=0 was sent & received as None.
69
* Fix that `dispatch-cli stream` would try to print an event as dispatch, causing an exception.

src/frequenz/client/dispatch/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def format_line(key: str, value: str, color: str = "cyan") -> str:
148148
lines.append(format_line("Recurrence", "None"))
149149
lines.append(format_line("Create Time", format_datetime(dispatch.create_time)))
150150
lines.append(format_line("Update Time", format_datetime(dispatch.update_time)))
151+
lines.append(format_line("End Time", format_datetime(dispatch.end_time)))
151152

152153
# Combine all lines
153154
dispatch_info: str = "\n".join(lines)

src/frequenz/client/dispatch/types.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ class Dispatch: # pylint: disable=too-many-instance-attributes
158158
update_time: datetime
159159
"""The last update time of the dispatch in UTC. Set when a dispatch is modified."""
160160

161+
end_time: datetime | None = None
162+
"""The end time of the dispatch in UTC.
163+
164+
Calculated and sent by the backend service.
165+
"""
166+
161167
@property
162168
def started(self) -> bool:
163169
"""Check if the dispatch has started.
@@ -290,6 +296,7 @@ def from_protobuf(cls, pb_object: PBDispatch) -> "Dispatch":
290296
type=pb_object.data.type,
291297
create_time=to_datetime(pb_object.metadata.create_time),
292298
update_time=to_datetime(pb_object.metadata.modification_time),
299+
end_time=to_datetime(pb_object.metadata.end_time),
293300
start_time=to_datetime(pb_object.data.start_time),
294301
duration=(
295302
timedelta(seconds=pb_object.data.duration)
@@ -317,6 +324,7 @@ def to_protobuf(self) -> PBDispatch:
317324
dispatch_id=self.id,
318325
create_time=to_timestamp(self.create_time),
319326
modification_time=to_timestamp(self.update_time),
327+
end_time=to_timestamp(self.end_time),
320328
),
321329
data=DispatchData(
322330
type=self.type,

tests/test_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def _update_metadata(dispatch: Dispatch, created: Dispatch) -> Dispatch:
3838
id=created.id,
3939
create_time=created.create_time,
4040
update_time=created.update_time,
41+
end_time=created.end_time,
4142
)
4243

4344

tests/test_proto.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def test_dispatch() -> None:
9797
create_time=datetime(2023, 1, 1, tzinfo=timezone.utc),
9898
update_time=datetime(2023, 1, 1, tzinfo=timezone.utc),
9999
start_time=datetime(2024, 10, 10, tzinfo=timezone.utc),
100+
end_time=datetime(2024, 10, 20, tzinfo=timezone.utc),
100101
duration=timedelta(days=10),
101102
target=[1, 2, 3],
102103
active=True,
@@ -117,6 +118,7 @@ def test_dispatch() -> None:
117118
create_time=datetime(2024, 3, 10, tzinfo=timezone.utc),
118119
update_time=datetime(2024, 3, 11, tzinfo=timezone.utc),
119120
start_time=datetime(2024, 11, 10, tzinfo=timezone.utc),
121+
end_time=datetime(2024, 11, 20, tzinfo=timezone.utc),
120122
duration=timedelta(seconds=20),
121123
target=[ComponentCategory.BATTERY],
122124
active=False,

0 commit comments

Comments
 (0)