feat: add VedAstro gateway job worker
This commit is contained in:
@@ -953,6 +953,13 @@ class JyotishAPIHandler(BaseHTTPRequestHandler):
|
||||
elif path == '/api/vedastro_gateway/enqueue':
|
||||
result = self._compute_vedastro_gateway_enqueue(body)
|
||||
self._json(result)
|
||||
elif path.startswith('/api/vedastro_gateway/jobs/') and path.endswith('/run'):
|
||||
job_id = path.split('/')[-2]
|
||||
result = self._compute_vedastro_gateway_run_job(job_id)
|
||||
if result is None:
|
||||
self._error_json('Not found', 404, 'ERR_NOT_FOUND')
|
||||
else:
|
||||
self._json(result)
|
||||
elif path == '/api/professional_reading':
|
||||
result = self._compute_professional_reading(body)
|
||||
self._json(result)
|
||||
@@ -1784,6 +1791,11 @@ class JyotishAPIHandler(BaseHTTPRequestHandler):
|
||||
reference_date=str(reference_date),
|
||||
)
|
||||
|
||||
def _compute_vedastro_gateway_run_job(self, job_id):
|
||||
from scripts.vedastro_gateway import run_gateway_job
|
||||
|
||||
return run_gateway_job(str(job_id))
|
||||
|
||||
def _compute_vedastro_gateway_run(self, body):
|
||||
from scripts.vedastro_gateway import run_gateway_packet
|
||||
|
||||
|
||||
@@ -143,6 +143,31 @@ def complete_gateway_job(job_id: str, result: dict[str, Any]) -> dict[str, Any]:
|
||||
return _write_job(job)
|
||||
|
||||
|
||||
def run_gateway_job(job_id: str) -> dict[str, Any] | None:
|
||||
job = get_gateway_job(job_id)
|
||||
if job is None:
|
||||
return None
|
||||
if job.get("status") == "completed":
|
||||
return job
|
||||
job["status"] = "running"
|
||||
job["updated_at"] = _now_iso()
|
||||
_write_job(job)
|
||||
request = job.get("request") if isinstance(job.get("request"), dict) else {}
|
||||
try:
|
||||
result = run_gateway_packet(
|
||||
request.get("case") if isinstance(request.get("case"), dict) else {},
|
||||
question=str(request.get("question") or ""),
|
||||
themes=request.get("themes") if isinstance(request.get("themes"), list) else [],
|
||||
reference_date=str(request.get("reference_date") or ""),
|
||||
)
|
||||
except Exception as exc:
|
||||
job["status"] = "failed"
|
||||
job["updated_at"] = _now_iso()
|
||||
job["error"] = {"type": exc.__class__.__name__, "message": str(exc)}
|
||||
return _write_job(job)
|
||||
return complete_gateway_job(job_id, result)
|
||||
|
||||
|
||||
def gateway_status() -> dict[str, Any]:
|
||||
config = build_gateway_config()
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user