Add timestamp to pipeline runs (#91599)
* Add timestamp to pipeline runs * Include the timestamp in the listpull/91612/head
parent
4132f08146
commit
016e051db6
|
@ -191,7 +191,7 @@ class PipelineRun:
|
|||
pipeline_data.pipeline_runs[self.pipeline.id] = LimitedSizeDict(
|
||||
size_limit=STORED_PIPELINE_RUNS
|
||||
)
|
||||
pipeline_data.pipeline_runs[self.pipeline.id][self.id] = []
|
||||
pipeline_data.pipeline_runs[self.pipeline.id][self.id] = PipelineRunDebug()
|
||||
|
||||
@callback
|
||||
def process_event(self, event: PipelineEvent) -> None:
|
||||
|
@ -201,7 +201,7 @@ class PipelineRun:
|
|||
if self.id not in pipeline_data.pipeline_runs[self.pipeline.id]:
|
||||
# This run has been evicted from the logged pipeline runs already
|
||||
return
|
||||
pipeline_data.pipeline_runs[self.pipeline.id][self.id].append(event)
|
||||
pipeline_data.pipeline_runs[self.pipeline.id][self.id].events.append(event)
|
||||
|
||||
def start(self) -> None:
|
||||
"""Emit run start event."""
|
||||
|
@ -717,10 +717,21 @@ class PipelineStorageCollectionWebsocket(
|
|||
class PipelineData:
|
||||
"""Store and debug data stored in hass.data."""
|
||||
|
||||
pipeline_runs: dict[str, LimitedSizeDict[str, list[PipelineEvent]]]
|
||||
pipeline_runs: dict[str, LimitedSizeDict[str, PipelineRunDebug]]
|
||||
pipeline_store: PipelineStorageCollection
|
||||
|
||||
|
||||
@dataclass
|
||||
class PipelineRunDebug:
|
||||
"""Debug data for a pipelinerun."""
|
||||
|
||||
events: list[PipelineEvent] = field(default_factory=list, init=False)
|
||||
timestamp: str = field(
|
||||
default_factory=lambda: dt_util.utcnow().isoformat(),
|
||||
init=False,
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_pipeline_store(hass: HomeAssistant) -> None:
|
||||
"""Set up the pipeline storage collection."""
|
||||
pipeline_store = PipelineStorageCollection(
|
||||
|
|
|
@ -232,7 +232,15 @@ def websocket_list_runs(
|
|||
|
||||
pipeline_runs = pipeline_data.pipeline_runs[pipeline_id]
|
||||
|
||||
connection.send_result(msg["id"], {"pipeline_runs": list(pipeline_runs)})
|
||||
connection.send_result(
|
||||
msg["id"],
|
||||
{
|
||||
"pipeline_runs": [
|
||||
{"pipeline_run_id": id, "timestamp": pipeline_run.timestamp}
|
||||
for id, pipeline_run in pipeline_runs.items()
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
|
@ -274,5 +282,5 @@ def websocket_get_run(
|
|||
|
||||
connection.send_result(
|
||||
msg["id"],
|
||||
{"events": pipeline_runs[pipeline_run_id]},
|
||||
{"events": pipeline_runs[pipeline_run_id].events},
|
||||
)
|
||||
|
|
|
@ -1022,7 +1022,7 @@ async def test_audio_pipeline_debug(
|
|||
assert msg["success"]
|
||||
assert msg["result"] == {"pipeline_runs": [ANY]}
|
||||
|
||||
pipeline_run_id = msg["result"]["pipeline_runs"][0]
|
||||
pipeline_run_id = msg["result"]["pipeline_runs"][0]["pipeline_run_id"]
|
||||
|
||||
await client.send_json_auto_id(
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue