Spaces:
Running
Running
prince1604 commited on
Commit ·
bc84e50
1
Parent(s): 1b7c76e
Add elapsed time and ETA to progress stats
Browse files
api.py
CHANGED
|
@@ -113,6 +113,7 @@ def run_scan_job(job_id: str, domain: str, limit: int, is_auto: bool = False):
|
|
| 113 |
"status": "running",
|
| 114 |
"percent": 0,
|
| 115 |
"message": "Initializing Crawler...",
|
|
|
|
| 116 |
"error": None
|
| 117 |
})
|
| 118 |
|
|
@@ -194,6 +195,8 @@ def start_scan(payload: StartReq, bg: BackgroundTasks):
|
|
| 194 |
"pages_scanned": 0,
|
| 195 |
"images_found": 0,
|
| 196 |
"message": "Queued",
|
|
|
|
|
|
|
| 197 |
"result": None,
|
| 198 |
"error": None,
|
| 199 |
}
|
|
@@ -206,12 +209,33 @@ def scan_progress(job_id: str):
|
|
| 206 |
if not job:
|
| 207 |
return JSONResponse(status_code=404, content={"status": "not_found", "error": "Job ID not found"})
|
| 208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
return {
|
| 210 |
"status": job["status"],
|
| 211 |
"percent": job["percent"],
|
| 212 |
-
"pages_scanned":
|
| 213 |
"images_found": job.get("images_found", 0),
|
| 214 |
"message": job.get("message", ""),
|
|
|
|
|
|
|
| 215 |
"error": job.get("error"),
|
| 216 |
}
|
| 217 |
|
|
|
|
| 113 |
"status": "running",
|
| 114 |
"percent": 0,
|
| 115 |
"message": "Initializing Crawler...",
|
| 116 |
+
"start_time": time.time(),
|
| 117 |
"error": None
|
| 118 |
})
|
| 119 |
|
|
|
|
| 195 |
"pages_scanned": 0,
|
| 196 |
"images_found": 0,
|
| 197 |
"message": "Queued",
|
| 198 |
+
"start_time": time.time(),
|
| 199 |
+
"elapsed": 0,
|
| 200 |
"result": None,
|
| 201 |
"error": None,
|
| 202 |
}
|
|
|
|
| 209 |
if not job:
|
| 210 |
return JSONResponse(status_code=404, content={"status": "not_found", "error": "Job ID not found"})
|
| 211 |
|
| 212 |
+
# Calculate Live Stats
|
| 213 |
+
current_time = time.time()
|
| 214 |
+
elapsed = int(current_time - job.get("start_time", current_time))
|
| 215 |
+
|
| 216 |
+
# Simple ETA Calculation
|
| 217 |
+
# If we have scanned X pages in Y seconds, and need to scan Z total...
|
| 218 |
+
# ETA = (target_pages - scanned_pages) * (elapsed / scanned_pages)
|
| 219 |
+
eta_seconds = None
|
| 220 |
+
pages_scanned = job.get("pages_scanned", 0)
|
| 221 |
+
percent = job.get("percent", 0)
|
| 222 |
+
|
| 223 |
+
if job["status"] == "running" and pages_scanned > 0 and percent > 0:
|
| 224 |
+
avg_per_page = elapsed / pages_scanned
|
| 225 |
+
# Assume limit is roughly the target (or use percent to back-calculate)
|
| 226 |
+
# Using percent is safer if limit wasn't reached
|
| 227 |
+
estimated_total = (pages_scanned / percent) * 100
|
| 228 |
+
remaining = estimated_total - pages_scanned
|
| 229 |
+
eta_seconds = int(remaining * avg_per_page)
|
| 230 |
+
|
| 231 |
return {
|
| 232 |
"status": job["status"],
|
| 233 |
"percent": job["percent"],
|
| 234 |
+
"pages_scanned": pages_scanned,
|
| 235 |
"images_found": job.get("images_found", 0),
|
| 236 |
"message": job.get("message", ""),
|
| 237 |
+
"elapsed_seconds": elapsed,
|
| 238 |
+
"eta_seconds": eta_seconds,
|
| 239 |
"error": job.get("error"),
|
| 240 |
}
|
| 241 |
|