Add timestamp to pipeline runs (#91599)

* Add timestamp to pipeline runs

* Include the timestamp in the list
pull/91612/head
Erik Montnemery 2023-04-18 16:43:46 +02:00 committed by GitHub
parent 4132f08146
commit 016e051db6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 6 deletions

View File

@ -191,7 +191,7 @@ class PipelineRun:
pipeline_data.pipeline_runs[self.pipeline.id] = LimitedSizeDict( pipeline_data.pipeline_runs[self.pipeline.id] = LimitedSizeDict(
size_limit=STORED_PIPELINE_RUNS 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 @callback
def process_event(self, event: PipelineEvent) -> None: 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]: if self.id not in pipeline_data.pipeline_runs[self.pipeline.id]:
# This run has been evicted from the logged pipeline runs already # This run has been evicted from the logged pipeline runs already
return 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: def start(self) -> None:
"""Emit run start event.""" """Emit run start event."""
@ -717,10 +717,21 @@ class PipelineStorageCollectionWebsocket(
class PipelineData: class PipelineData:
"""Store and debug data stored in hass.data.""" """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 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: async def async_setup_pipeline_store(hass: HomeAssistant) -> None:
"""Set up the pipeline storage collection.""" """Set up the pipeline storage collection."""
pipeline_store = PipelineStorageCollection( pipeline_store = PipelineStorageCollection(

View File

@ -232,7 +232,15 @@ def websocket_list_runs(
pipeline_runs = pipeline_data.pipeline_runs[pipeline_id] 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 @callback
@ -274,5 +282,5 @@ def websocket_get_run(
connection.send_result( connection.send_result(
msg["id"], msg["id"],
{"events": pipeline_runs[pipeline_run_id]}, {"events": pipeline_runs[pipeline_run_id].events},
) )

View File

@ -1022,7 +1022,7 @@ async def test_audio_pipeline_debug(
assert msg["success"] assert msg["success"]
assert msg["result"] == {"pipeline_runs": [ANY]} 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( await client.send_json_auto_id(
{ {