Ë
    ýµCj�	  ã                   óæ   — d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ  e«       Z ee«      Zej-                  d
ddeii¬«       ee«      fdededefd„«       Zy)u  
GET /api/v1/tasks/{task_id}

Polling endpoint for both real Celery tasks and synthetic cache-hit
"tasks" (see analyze.py for why cache hits get a synthetic task id â€”
it keeps the client integration to a single polling pattern regardless
of whether the result came from cache or a fresh computation).

Accepts either a logged-in customer (JWT) or a service API key â€” same
dual-auth pattern as /analyze (see app/core/dual_auth.py), since this
is the immediate next call a SaaS dashboard user makes after submitting
an analysis.
é    )ÚAsyncResult)Ú	APIRouterÚDepends)ÚAuthContextÚget_auth_context)ÚTaskNotFoundError)Ú
get_logger)ÚErrorResponse)Úcache_service)Ú
celery_appz/tasks/{task_id}i”  Úmodel)Ú	responsesÚtask_idÚauthÚreturnc              ƒ   óÀ  K  — | j                  d«      r5t        j                  d| › �«      ƒ d {  –—† }|€t        d¬«      ‚| d|d dœS t	        | t
        ¬«      }|j                  dk(  r| d	d d dœS |j                  d
k(  r| dd d dœS |j                  dk(  r| d|j                  d dœS |j                  dk(  r t        j                  d| › d�«       | dd ddœS | dd d dœS 7 Œ¬­w)Nzcached-ztask_result:zWThis cached result has expired or does not exist. Please submit a new analysis request.)ÚmessageÚ	completed)r   ÚstatusÚresultÚerror)ÚappÚPENDINGÚqueuedÚSTARTEDÚrunningÚSUCCESSÚFAILUREzTask z reported failure stateÚfailedz]Analysis could not be completed. Please try again or contact support if the problem persists.)
Ú
startswithr   Úgetr   r   r   Ústater   ÚloggerÚwarning)r   r   Úcachedr   s       úGC:\Crop_Prediction\Backend\crop-ai-system\app\api\v1\endpoints\tasks.pyÚget_task_statusr'      s  è ø€ ð
 ×Ñ˜)Ô$Ü$×(Ñ(¨<¸°yÐ)AÓB×BˆØˆ>Ü#ð@ôð ð #¨kÀVÐVZÑ[Ð[ä˜¤jÔ1€Fà‡|�|�yÒ Ø"¨hÀ$ÐQUÑVÐVà‡|�|�yÒ Ø"¨iÀ4ÐRVÑWÐWà‡|�|�yÒ Ø"¨kÀVÇ]Á]Ð]aÑbÐbà‡|�|�yÒ Ü�‰˜˜w˜iÐ'>Ð?Ô@àØØð0ñ	
ð 	
ð ¨)¸tÈdÑSÐSð; Cús   ‚-C¯C°B-CN)Ú__doc__Úcelery.resultr   Úfastapir   r   Úapp.core.dual_authr   r   Úapp.core.exceptionsr   Úapp.core.logging_configr	   Úapp.schemas.responser
   Úapp.services.cache_servicer   Úapp.workers.celery_appr   ÚrouterÚ__name__r#   r!   ÚstrÚdictr'   © ó    r&   ú<module>r7      sŽ   ðñõ &ß &ç <Ý 1Ý .Ý .Ý 4Ý -á	‹€Ù	�HÓ	€ð ‡�ØØ�W˜mÐ,Ð-ð ó ñ =DÐDTÓ<Uñ T 3ð T¨kð TÐZ^ò Tó	ñTr6   