fix(core): patch worker logic (v1.1.1)
- Re-queue auth tasks on 'Executable doesn't exist' error - Record session duration metrics in extraction phase
This commit is contained in:
parent
53bf4b7518
commit
2834a3446a
1 changed files with 14 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import time
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
import redis.asyncio as redis
|
import redis.asyncio as redis
|
||||||
|
|
@ -90,6 +91,13 @@ class TaskWorker:
|
||||||
MetricsCollector.record_auth_success()
|
MetricsCollector.record_auth_success()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if "Executable doesn't exist" in str(e):
|
||||||
|
logger.warning(f"Browser binary missing. Re-queueing task for {session_id}")
|
||||||
|
# Push back to redis (right push to back of queue, or left to retry immediate? usually back is safer)
|
||||||
|
# But user said "re-queue the task to Redis".
|
||||||
|
await self.redis.rpush("tasks", json.dumps({"type": "auth", "url": url, "session_id": session_id}))
|
||||||
|
return
|
||||||
|
|
||||||
logger.error(f"Auth failed: {e}")
|
logger.error(f"Auth failed: {e}")
|
||||||
MetricsCollector.record_auth_failure(str(e))
|
MetricsCollector.record_auth_failure(str(e))
|
||||||
await self.recovery.handle_invalidation(session_id, "auth_failure")
|
await self.recovery.handle_invalidation(session_id, "auth_failure")
|
||||||
|
|
@ -110,6 +118,12 @@ class TaskWorker:
|
||||||
html = await client.fetch(url)
|
html = await client.fetch(url)
|
||||||
logger.info(f"Extracted {len(html)} bytes from {url} using Session {session_id}")
|
logger.info(f"Extracted {len(html)} bytes from {url} using Session {session_id}")
|
||||||
|
|
||||||
|
# Calculate duration
|
||||||
|
duration = time.time() - state.timestamp
|
||||||
|
MetricsCollector.record_session_lifetime(duration)
|
||||||
|
|
||||||
|
logger.info(f"Extracted {len(html)} bytes from {url} using Session {session_id} (Duration: {duration:.2f}s)")
|
||||||
|
|
||||||
MetricsCollector.record_extraction("success")
|
MetricsCollector.record_extraction("success")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Extraction failed: {e}")
|
logger.error(f"Extraction failed: {e}")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue