add batch_id to history task items

This commit is contained in:
bymyself 2025-06-21 16:45:50 -07:00
parent 38fefde06d
commit 35d98dcea8
3 changed files with 24 additions and 3 deletions

View File

@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
# timestamp: 2025-06-21T23:28:48+00:00
# timestamp: 2025-06-21T23:40:24+00:00
from __future__ import annotations
@ -476,6 +476,12 @@ class TaskHistoryItem(BaseModel):
timestamp: datetime = Field(..., description="ISO timestamp when task completed")
result: str = Field(..., description="Task result message or details")
status: Optional[TaskExecutionStatus] = None
batch_id: Optional[str] = Field(
None, description="ID of the batch this task belongs to"
)
end_time: Optional[datetime] = Field(
None, description="ISO timestamp when task execution ended"
)
class TaskStateMessage(BaseModel):

View File

@ -313,7 +313,8 @@ class TaskQueue:
"""Mark task as completed and add to history"""
with self.mutex:
timestamp = datetime.now().isoformat()
now = datetime.now()
timestamp = now.isoformat()
# Remove task from running_tasks using the task_index
self.running_tasks.pop(task_index, None)
@ -334,10 +335,12 @@ class TaskQueue:
self.history_tasks[item.ui_id] = TaskHistoryItem(
ui_id=item.ui_id,
client_id=item.client_id,
timestamp=datetime.fromisoformat(timestamp),
timestamp=now,
result=result_msg,
kind=item.kind,
status=status,
batch_id=self.batch_id,
end_time=now,
)
# Force cache refresh for successful pack-modifying operations
@ -735,6 +738,10 @@ class TaskQueue:
try:
for ui_id, task in self.history_tasks.items():
# Only include operations from the current batch
if task.batch_id != self.batch_id:
continue
result_status = OperationResult.success
if task.status:
status_str = (
@ -755,6 +762,7 @@ class TaskQueue:
target=f"task_{ui_id}",
result=result_status.value,
start_time=task.timestamp,
end_time=task.end_time,
client_id=task.client_id,
)
operations.append(operation)

View File

@ -71,6 +71,13 @@ components:
description: Task result message or details
status:
$ref: '#/components/schemas/TaskExecutionStatus'
batch_id:
type: [string, 'null']
description: ID of the batch this task belongs to
end_time:
type: [string, 'null']
format: date-time
description: ISO timestamp when task execution ended
required: [ui_id, client_id, kind, timestamp, result]
TaskExecutionStatus:
type: object