2026-02-27 20:06:46 +03:30
|
|
|
"""
|
|
|
|
|
تسکهای Celery برای RAG
|
|
|
|
|
"""
|
|
|
|
|
from config.celery import app
|
|
|
|
|
|
|
|
|
|
from .ingest import ingest
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.task
|
|
|
|
|
def rag_ingest_task(recreate: bool = True):
|
|
|
|
|
"""
|
|
|
|
|
embed و ذخیره دیتای همه کاربران در Qdrant.
|
|
|
|
|
هر چند ساعت یکبار اجرا شود (از طریق Celery Beat).
|
|
|
|
|
recreate=True: collection از نو ساخته میشود تا دیتای قدیمی حذف شود.
|
|
|
|
|
"""
|
|
|
|
|
result = ingest(recreate=recreate)
|
|
|
|
|
return result
|
2026-03-19 22:54:29 +03:30
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.task(bind=True)
|
|
|
|
|
def irrigation_recommendation_task(
|
|
|
|
|
self,
|
|
|
|
|
sensor_uuid: str,
|
|
|
|
|
plant_name: str | None = None,
|
|
|
|
|
growth_stage: str | None = None,
|
|
|
|
|
irrigation_method_name: str | None = None,
|
|
|
|
|
query: str | None = None,
|
|
|
|
|
) -> dict:
|
|
|
|
|
"""
|
|
|
|
|
تسک Celery برای تولید توصیه آبیاری.
|
|
|
|
|
دادههای سنسور، گیاه و روش آبیاری را از DB بارگذاری کرده
|
|
|
|
|
و از سرویس RAG توصیه میگیرد.
|
|
|
|
|
"""
|
|
|
|
|
from rag.services.irrigation import get_irrigation_recommendation
|
|
|
|
|
|
|
|
|
|
self.update_state(
|
|
|
|
|
state="PROGRESS",
|
|
|
|
|
meta={"message": "در حال پردازش توصیه آبیاری..."},
|
|
|
|
|
)
|
|
|
|
|
result = get_irrigation_recommendation(
|
|
|
|
|
sensor_uuid=sensor_uuid,
|
|
|
|
|
plant_name=plant_name,
|
|
|
|
|
growth_stage=growth_stage,
|
|
|
|
|
irrigation_method_name=irrigation_method_name,
|
|
|
|
|
query=query,
|
|
|
|
|
)
|
|
|
|
|
result["status"] = "completed"
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.task(bind=True)
|
|
|
|
|
def fertilization_recommendation_task(
|
|
|
|
|
self,
|
|
|
|
|
sensor_uuid: str,
|
|
|
|
|
plant_name: str | None = None,
|
|
|
|
|
growth_stage: str | None = None,
|
|
|
|
|
query: str | None = None,
|
|
|
|
|
) -> dict:
|
|
|
|
|
"""
|
|
|
|
|
تسک Celery برای تولید توصیه کودهی.
|
|
|
|
|
دادههای سنسور و گیاه را از DB بارگذاری کرده
|
|
|
|
|
و از سرویس RAG توصیه میگیرد.
|
|
|
|
|
"""
|
|
|
|
|
from rag.services.fertilization import get_fertilization_recommendation
|
|
|
|
|
|
|
|
|
|
self.update_state(
|
|
|
|
|
state="PROGRESS",
|
|
|
|
|
meta={"message": "در حال پردازش توصیه کودهی..."},
|
|
|
|
|
)
|
|
|
|
|
result = get_fertilization_recommendation(
|
|
|
|
|
sensor_uuid=sensor_uuid,
|
|
|
|
|
plant_name=plant_name,
|
|
|
|
|
growth_stage=growth_stage,
|
|
|
|
|
query=query,
|
|
|
|
|
)
|
|
|
|
|
result["status"] = "completed"
|
|
|
|
|
return result
|