Add run lifecycle timestamps - improvments (#2601)

Co-authored-by: Shuchang Zheng <wintonzheng0325@gmail.com>
This commit is contained in:
Prakash Maheshwaran
2025-06-11 23:36:49 -04:00
committed by GitHub
parent 90feb96b0f
commit b5bf9d291f
15 changed files with 138 additions and 1 deletions

View File

@@ -625,6 +625,12 @@ class AgentDB:
).first():
if status is not None:
task.status = status
if status == TaskStatus.queued and task.queued_at is None:
task.queued_at = datetime.utcnow()
if status == TaskStatus.running and task.started_at is None:
task.started_at = datetime.utcnow()
if status.is_final() and task.finished_at is None:
task.finished_at = datetime.utcnow()
if extracted_information is not None:
task.extracted_information = extracted_information
if failure_reason is not None:
@@ -1499,6 +1505,12 @@ class AgentDB:
if workflow_run:
workflow_run.status = status
workflow_run.failure_reason = failure_reason
if status == WorkflowRunStatus.queued and workflow_run.queued_at is None:
workflow_run.queued_at = datetime.utcnow()
if status == WorkflowRunStatus.running and workflow_run.started_at is None:
workflow_run.started_at = datetime.utcnow()
if status.is_final() and workflow_run.finished_at is None:
workflow_run.finished_at = datetime.utcnow()
await session.commit()
await session.refresh(workflow_run)
await save_workflow_run_logs(workflow_run_id)
@@ -2542,6 +2554,12 @@ class AgentDB:
if task_v2:
if status:
task_v2.status = status
if status == TaskV2Status.queued and task_v2.queued_at is None:
task_v2.queued_at = datetime.utcnow()
if status == TaskV2Status.running and task_v2.started_at is None:
task_v2.started_at = datetime.utcnow()
if status.is_final() and task_v2.finished_at is None:
task_v2.finished_at = datetime.utcnow()
if workflow_run_id:
task_v2.workflow_run_id = workflow_run_id
if workflow_id:

View File

@@ -84,6 +84,9 @@ class TaskModel(Base):
max_steps_per_run = Column(Integer, nullable=True)
application = Column(String, nullable=True)
include_action_history_in_verification = Column(Boolean, default=False, nullable=True)
queued_at = Column(DateTime, nullable=True)
started_at = Column(DateTime, nullable=True)
finished_at = Column(DateTime, nullable=True)
created_at = Column(DateTime, default=datetime.datetime.utcnow, nullable=False, index=True)
modified_at = Column(
DateTime,
@@ -251,6 +254,10 @@ class WorkflowRunModel(Base):
totp_verification_url = Column(String)
totp_identifier = Column(String)
queued_at = Column(DateTime, nullable=True)
started_at = Column(DateTime, nullable=True)
finished_at = Column(DateTime, nullable=True)
created_at = Column(DateTime, default=datetime.datetime.utcnow, nullable=False)
modified_at = Column(
DateTime,
@@ -592,6 +599,10 @@ class TaskV2Model(Base):
error_code_mapping = Column(JSON, nullable=True)
max_steps = Column(Integer, nullable=True)
queued_at = Column(DateTime, nullable=True)
started_at = Column(DateTime, nullable=True)
finished_at = Column(DateTime, nullable=True)
created_at = Column(DateTime, default=datetime.datetime.utcnow, nullable=False)
modified_at = Column(DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow, nullable=False)
model = Column(JSON, nullable=True)

View File

@@ -139,6 +139,9 @@ def convert_to_task(task_obj: TaskModel, debug_enabled: bool = False, workflow_p
errors=task_obj.errors,
application=task_obj.application,
model=task_obj.model,
queued_at=task_obj.queued_at,
started_at=task_obj.started_at,
finished_at=task_obj.finished_at,
)
return task
@@ -269,6 +272,9 @@ def convert_to_workflow_run(
webhook_callback_url=workflow_run_model.webhook_callback_url,
totp_verification_url=workflow_run_model.totp_verification_url,
totp_identifier=workflow_run_model.totp_identifier,
queued_at=workflow_run_model.queued_at,
started_at=workflow_run_model.started_at,
finished_at=workflow_run_model.finished_at,
created_at=workflow_run_model.created_at,
modified_at=workflow_run_model.modified_at,
workflow_title=workflow_title,