Avinashnalla7 commited on
Commit
88696c0
·
1 Parent(s): 564a635

Upload stored PDFs to API space for UI fetch

Browse files
Files changed (1) hide show
  1. backend/worker/worker.py +16 -0
backend/worker/worker.py CHANGED
@@ -1,6 +1,9 @@
1
  from __future__ import annotations
2
 
3
  import os
 
 
 
4
  import time
5
  import uuid
6
  from dataclasses import dataclass
@@ -134,6 +137,19 @@ def _process_train_label(gmail: GmailClient, s: Settings, root: Path) -> None:
134
  print(
135
  f"[worker][TRAIN] stored PDF msg={m.msg_id} file={filename} "
136
  f"pdf_id={pdf_id} stored={stored_pdf_path}"
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  )
138
  print(f"[worker][TRAIN] open: {trainer_link}")
139
 
 
1
  from __future__ import annotations
2
 
3
  import os
4
+ import requests
5
+
6
+ PDF_TRAINER_API_BASE = (os.environ.get('PDF_TRAINER_API_BASE') or '').strip()
7
  import time
8
  import uuid
9
  from dataclasses import dataclass
 
137
  print(
138
  f"[worker][TRAIN] stored PDF msg={m.msg_id} file={filename} "
139
  f"pdf_id={pdf_id} stored={stored_pdf_path}"
140
+
141
+ # push PDF into API space so UI can fetch it
142
+ try:
143
+ if PDF_TRAINER_API_BASE:
144
+ with open(stored_pdf_path, "rb") as f:
145
+ requests.post(
146
+ f"{PDF_TRAINER_API_BASE.rstrip('/')}/api/pdf/{pdf_id}",
147
+ files={"file": (f"{pdf_id}.pdf", f, "application/pdf")},
148
+ data={"pdf_name": filename},
149
+ timeout=30,
150
+ ).raise_for_status()
151
+ except Exception as e:
152
+ print(f"[worker] WARN: failed to upload PDF to API: {e}")
153
  )
154
  print(f"[worker][TRAIN] open: {trainer_link}")
155