chore: improve image worker logging
This commit is contained in:
@@ -4,6 +4,7 @@ import uuid
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from apps.api.models import ImageGenerationTask
|
||||
from apps.api.image_tasks import reap_stale_image_tasks, run_one_image_task
|
||||
|
||||
|
||||
@@ -56,7 +57,7 @@ class Command(BaseCommand):
|
||||
|
||||
task = run_one_image_task(worker_id=worker_id)
|
||||
if task is not None:
|
||||
self.stdout.write(f"task={task.task_id} status={task.status}")
|
||||
self.stdout.write(format_task_log_line(task, started_at=now))
|
||||
if once:
|
||||
return
|
||||
continue
|
||||
@@ -64,3 +65,18 @@ class Command(BaseCommand):
|
||||
if once:
|
||||
return
|
||||
time.sleep(sleep_seconds)
|
||||
|
||||
|
||||
def format_task_log_line(task: ImageGenerationTask, *, started_at: float) -> str:
|
||||
duration_ms = max(0, int((time.monotonic() - started_at) * 1000))
|
||||
alias = str((task.request_payload or {}).get("model") or "")
|
||||
fields = {
|
||||
"event": "image_task_processed",
|
||||
"task_id": str(task.task_id),
|
||||
"status": task.status,
|
||||
"alias": alias,
|
||||
"duration_ms": str(duration_ms),
|
||||
}
|
||||
if task.status in {ImageGenerationTask.Status.FAILED, ImageGenerationTask.Status.EXPIRED}:
|
||||
fields["error_code"] = task.error_code or "upstream_error"
|
||||
return " ".join(f"{key}={value}" for key, value in fields.items())
|
||||
|
||||
Reference in New Issue
Block a user