From b819552a7c9b670542f02b6119bb280983f0efe8 Mon Sep 17 00:00:00 2001 From: hjlarry Date: Wed, 17 Dec 2025 10:10:40 +0800 Subject: [PATCH] print run time --- api/commands.py | 15 +++++++++++++-- api/schedule/clean_workflow_runs_task.py | 14 +++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/api/commands.py b/api/commands.py index 16554dbedc..49b3bff2e9 100644 --- a/api/commands.py +++ b/api/commands.py @@ -887,7 +887,10 @@ def clean_workflow_runs( if (start_after is None) ^ (end_before is None): raise click.UsageError("--start-after and --end-before must be provided together.") - click.echo(click.style("Starting workflow run cleanup.", fg="white")) + start_time = datetime.datetime.now(datetime.UTC) + click.echo( + click.style(f"Starting workflow run cleanup at {start_time.isoformat()}.", fg="white") + ) WorkflowRunCleanup( days=days, @@ -897,7 +900,15 @@ def clean_workflow_runs( dry_run=dry_run, ).run() - click.echo(click.style("Workflow run cleanup completed.", fg="green")) + end_time = datetime.datetime.now(datetime.UTC) + elapsed = end_time - start_time + click.echo( + click.style( + f"Workflow run cleanup completed. start={start_time.isoformat()} " + f"end={end_time.isoformat()} duration={elapsed}", + fg="green", + ) + ) @click.option("-f", "--force", is_flag=True, help="Skip user confirmation and force the command to execute.") diff --git a/api/schedule/clean_workflow_runs_task.py b/api/schedule/clean_workflow_runs_task.py index 0f34c534ab..dde5d46606 100644 --- a/api/schedule/clean_workflow_runs_task.py +++ b/api/schedule/clean_workflow_runs_task.py @@ -1,3 +1,5 @@ +from datetime import UTC, datetime + import click import app @@ -18,6 +20,8 @@ def clean_workflow_runs_task() -> None: ) ) + start_time = datetime.now(UTC) + WorkflowRunCleanup( days=dify_config.WORKFLOW_LOG_RETENTION_DAYS, batch_size=dify_config.WORKFLOW_LOG_CLEANUP_BATCH_SIZE, @@ -25,4 +29,12 @@ def clean_workflow_runs_task() -> None: end_before=None, ).run() - click.echo(click.style("Scheduled workflow run cleanup finished.", fg="green")) + end_time = datetime.now(UTC) + elapsed = end_time - start_time + click.echo( + click.style( + f"Scheduled workflow run cleanup finished. start={start_time.isoformat()} " + f"end={end_time.isoformat()} duration={elapsed}", + fg="green", + ) + )