Auto-commit: v2.10 — Docker diagnostic logging for consumer & task execution
- web/app.py: Startup banner to docker logs (Python version, platform, Huey version, DB paths). All print() calls now flush=True so Docker captures them immediately. Emoji-free for robust stdout encoding. Startup now detects orphaned queued runs (queue empty but DB queued) and resets them to 'failed' so the UI does not stay stuck on reload. Huey logging configured at INFO level so task pick-up/completion appears in `docker logs`. Consumer skip reason logged explicitly. - web/tasks.py: generate_book_task now emits [TASK run=N] lines to stdout (docker logs) at pick-up, log-file creation, DB status update, and on error (with full traceback) so failures are always visible. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
24
web/tasks.py
24
web/tasks.py
@@ -43,6 +43,13 @@ def generate_book_task(run_id, project_path, bible_path, allow_copy=True, feedba
|
||||
"""
|
||||
Background task to run the book generation.
|
||||
"""
|
||||
import sys as _sys
|
||||
def _task_log(msg):
|
||||
"""Print directly to stdout (docker logs) regardless of utils state."""
|
||||
print(f"[TASK run={run_id}] {msg}", flush=True, file=_sys.stdout)
|
||||
|
||||
_task_log(f"Task picked up by Huey worker. project_path={project_path}")
|
||||
|
||||
# 1. Setup Logging
|
||||
log_filename = f"system_log_{run_id}.txt"
|
||||
|
||||
@@ -54,8 +61,9 @@ def generate_book_task(run_id, project_path, bible_path, allow_copy=True, feedba
|
||||
try:
|
||||
with open(initial_log, 'a', encoding='utf-8') as _f:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
_task_log(f"Log file created: {initial_log}")
|
||||
except Exception as _e:
|
||||
_task_log(f"WARNING: Could not touch log file {initial_log}: {_e}")
|
||||
|
||||
utils.set_log_file(initial_log)
|
||||
|
||||
@@ -68,10 +76,12 @@ def generate_book_task(run_id, project_path, bible_path, allow_copy=True, feedba
|
||||
try:
|
||||
with sqlite3.connect(db_path, timeout=30, check_same_thread=False) as conn:
|
||||
conn.execute("UPDATE run SET status = 'running' WHERE id = ?", (run_id,))
|
||||
_task_log("Run status set to 'running' in DB.")
|
||||
except sqlite3.OperationalError as e:
|
||||
utils.log("SYSTEM", f"⚠️ Database locked when setting run status (run {run_id}): {e}")
|
||||
except Exception:
|
||||
pass
|
||||
_task_log(f"WARNING: DB locked when setting run status: {e}")
|
||||
utils.log("SYSTEM", f"Database locked when setting run status (run {run_id}): {e}")
|
||||
except Exception as e:
|
||||
_task_log(f"WARNING: Could not set run status: {e}")
|
||||
|
||||
utils.log("SYSTEM", f"Starting Job #{run_id}")
|
||||
|
||||
@@ -169,6 +179,9 @@ def generate_book_task(run_id, project_path, bible_path, allow_copy=True, feedba
|
||||
status = "completed"
|
||||
|
||||
except Exception as e:
|
||||
import traceback as _tb
|
||||
_task_log(f"ERROR: Job failed — {type(e).__name__}: {e}")
|
||||
_task_log(_tb.format_exc())
|
||||
utils.log("ERROR", f"Job Failed: {e}")
|
||||
status = "failed"
|
||||
|
||||
@@ -203,6 +216,7 @@ def generate_book_task(run_id, project_path, bible_path, allow_copy=True, feedba
|
||||
except Exception as e:
|
||||
print(f"Failed to update run status in DB: {e}")
|
||||
|
||||
_task_log(f"Task finished. status={status} cost=${total_cost:.4f}")
|
||||
return {"run_id": run_id, "status": status, "cost": total_cost, "final_log": final_log_path}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user