ymo2017 commited on
Commit
ce79f16
·
verified ·
1 Parent(s): 326cf8e

log jobs to container stdout (worker-side observability)

Browse files
Files changed (1) hide show
  1. app.py +10 -0
app.py CHANGED
@@ -22,9 +22,16 @@ def _cleanup():
22
  pass
23
 
24
 
 
 
 
 
 
 
25
  def run_job(files, job_json, token):
26
  _cleanup()
27
  if not WORKER_TOKEN or not hmac.compare_digest(str(token or ""), WORKER_TOKEN):
 
28
  return None, "auth failed"
29
  try:
30
  job = json.loads(job_json)
@@ -62,13 +69,16 @@ def run_job(files, job_json, token):
62
  return a
63
  args = [_subst(a) for a in args]
64
  workdir = tempfile.mkdtemp(dir=JOB_ROOT)
 
65
  t1 = time.time()
66
  try:
67
  p = subprocess.run(["ffmpeg", "-y"] + args, capture_output=True, text=True,
68
  timeout=timeout, cwd=workdir)
69
  except subprocess.TimeoutExpired:
 
70
  return None, f"timeout after {timeout}s"
71
  dt = time.time() - t1
 
72
  log = (f"rc={p.returncode} elapsed={dt:.1f}s\n"
73
  f"--- stdout ---\n{p.stdout}\n--- stderr (tail) ---\n{p.stderr[-6000:]}")
74
  out_path = os.path.join(workdir, out_name)
 
22
  pass
23
 
24
 
25
+ def _wlog(msg):
26
+ # Container stdout -> Space runtime log. Gradio return values never reach
27
+ # it, so without this successful jobs are invisible there.
28
+ print(f"[ffmpeg-worker] {msg}", flush=True)
29
+
30
+
31
  def run_job(files, job_json, token):
32
  _cleanup()
33
  if not WORKER_TOKEN or not hmac.compare_digest(str(token or ""), WORKER_TOKEN):
34
+ _wlog("auth failed")
35
  return None, "auth failed"
36
  try:
37
  job = json.loads(job_json)
 
69
  return a
70
  args = [_subst(a) for a in args]
71
  workdir = tempfile.mkdtemp(dir=JOB_ROOT)
72
+ _wlog(f"start: {len(in_paths)} input(s), timeout={timeout}s, output={out_name!r}")
73
  t1 = time.time()
74
  try:
75
  p = subprocess.run(["ffmpeg", "-y"] + args, capture_output=True, text=True,
76
  timeout=timeout, cwd=workdir)
77
  except subprocess.TimeoutExpired:
78
+ _wlog(f"timeout after {timeout}s (output={out_name!r})")
79
  return None, f"timeout after {timeout}s"
80
  dt = time.time() - t1
81
+ _wlog(f"done: rc={p.returncode} elapsed={dt:.1f}s output={out_name!r}")
82
  log = (f"rc={p.returncode} elapsed={dt:.1f}s\n"
83
  f"--- stdout ---\n{p.stdout}\n--- stderr (tail) ---\n{p.stderr[-6000:]}")
84
  out_path = os.path.join(workdir, out_name)