mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-30 03:00:41 -04:00
feat(backend): add endedAt field to track execution completion time
- Added endedAt field to AgentGraphExecution schema - Set endedAt when execution reaches terminal status (COMPLETED, FAILED, TERMINATED) - Updated from_db() to use endedAt instead of updatedAt for ended_at - Migration backfills endedAt with updatedAt for existing records - This fixes the issue where updatedAt changed when adding correctness scores - Chart grouping uses createdAt (when queued), endedAt tracks when execution actually finished
This commit is contained in:
@@ -230,7 +230,7 @@ class GraphExecutionMeta(BaseDbModel):
|
||||
@staticmethod
|
||||
def from_db(_graph_exec: AgentGraphExecution):
|
||||
start_time = _graph_exec.startedAt
|
||||
end_time = _graph_exec.updatedAt
|
||||
end_time = _graph_exec.endedAt
|
||||
|
||||
try:
|
||||
stats = GraphExecutionStats.model_validate(_graph_exec.stats)
|
||||
@@ -898,6 +898,14 @@ async def update_graph_execution_stats(
|
||||
|
||||
if status:
|
||||
update_data["executionStatus"] = status
|
||||
# Set endedAt when execution reaches a terminal status
|
||||
terminal_statuses = [
|
||||
ExecutionStatus.COMPLETED,
|
||||
ExecutionStatus.FAILED,
|
||||
ExecutionStatus.TERMINATED,
|
||||
]
|
||||
if status in terminal_statuses:
|
||||
update_data["endedAt"] = datetime.now(tz=timezone.utc)
|
||||
|
||||
where_clause: AgentGraphExecutionWhereInput = {"id": graph_exec_id}
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "platform"."AgentGraphExecution" ADD COLUMN "endedAt" TIMESTAMP(3);
|
||||
|
||||
-- Set endedAt to updatedAt for existing records
|
||||
UPDATE "platform"."AgentGraphExecution" SET "endedAt" = "updatedAt" WHERE "endedAt" IS NULL;
|
||||
@@ -383,6 +383,7 @@ model AgentGraphExecution {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime? @updatedAt
|
||||
startedAt DateTime?
|
||||
endedAt DateTime?
|
||||
|
||||
isDeleted Boolean @default(false)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user