File size: 1,566 Bytes
c3bf538 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
from celery_worker import celery
from core.database import SessionLocal
from models.analysis_job import AnalysisJob
from tools.advisor_tools import generate_investment_thesis
from uuid import UUID
@celery.task
def run_advisor_analysis(job_id: str):
db = SessionLocal()
job = None
final_result = ""
try:
job = db.query(AnalysisJob).filter(AnalysisJob.id == UUID(job_id)).first()
if not job or not job.result:
raise ValueError(f"Job {job_id} not found or has no result data for the advisor.")
print(f"Status - SUMMARIZING for job {job_id}...")
job.status = "SUMMARIZING"
db.commit()
current_data = job.result
advisor_summary = generate_investment_thesis(current_data)
new_result = current_data.copy()
new_result['advisor_summary'] = advisor_summary
job.result = new_result
job.status = "SUCCESS" # This is the final successful step
db.commit()
print(f"Advisor analysis for job {job_id} completed successfully.")
final_result = str(job.result)
except Exception as e:
print(f"Error during advisor analysis for job {job_id}: {e}")
if job:
job.status = "FAILED"
error_data = job.result if job.result else {}
error_data['error'] = f"Advisor analysis failed: {str(e)}"
job.result = error_data
db.commit()
final_result = f"Error: {e}"
finally:
db.close()
return final_result |