o
    h                     @   sr  d dl mZ d dl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 d dlmZ d d	lmZmZ d d
lmZmZ d dlmZmZmZ errd dlmZmZmZmZmZ d dlmZmZm Z  d dlm!Z! ededef dZ"zd dl#m$Z$m%Z%m&Z&m'Z' d dl(m)Z)m*Z*m+Z+ W n e,y   edw e)e*e+fZ-G dd deZ.dd Z/dd Z0dd Z1dd Z2dd  Z3dS )!    )absolute_importN)datetime)reraise)TYPE_CHECKING)Hub)OP)_should_send_default_pii)DidNotEnableIntegration)TransactionTRANSACTION_SOURCE_TASK)capture_internal_exceptionsevent_from_exceptionSENSITIVE_DATA_SUBSTITUTE)AnyCallableOptionalUnionTypeVar)EventProcessorEventHint)ExcInfoF.)bound)HueyResultResultGroupTask)CancelExecution	RetryTaskTaskLockedExceptionzHuey is not installedc                   @   s   e Zd ZdZedd ZdS )HueyIntegrationhueyc                   C   s   t   t  d S N)patch_enqueuepatch_execute r'   r'   _/var/www/html/aiguide_backend/venv/lib/python3.10/site-packages/sentry_sdk/integrations/huey.py
setup_once(   s   
zHueyIntegration.setup_onceN)__name__
__module____qualname__
identifierstaticmethodr)   r'   r'   r'   r(   r"   %   s    r"   c                     s   t j  fdd} | t _d S )Nc                    s^   t j}|td u r | |S |jtj|jd  | |W  d    S 1 s(w   Y  d S )N)opdescription)r   currentget_integrationr"   
start_spanr   QUEUE_SUBMIT_HUEYname)selftaskhubold_enqueuer'   r(   _sentry_enqueue3   s   
$z&patch_enqueue.<locals>._sentry_enqueue)r   enqueue)r;   r'   r9   r(   r%   /   s   

r%   c                        fdd}|S )Nc                    s   t  > | di } j|d<  j jk|d< | di } jt r% jntt r, j	nt jp1d j d|d< W d    | S 1 sDw   Y  | S )Ntagshuey_task_idhuey_task_retryextrar   )r7   argskwargsretryzhuey-job)
r   
setdefaultiddefault_retriesretriesr5   r   rB   r   rC   )eventhintr>   rA   r7   r'   r(   event_processorB   s$   

z._make_event_processor.<locals>.event_processorr'   )r7   rL   r'   rK   r(   _make_event_processor@   s   rM   c                 C   sl   t j}| d tv r|jjd d S |jjd t| |jr"|jjnd t	j
ddd\}}|j||d d S )Nr   abortedinternal_errorF)typehandled)client_options	mechanism)rJ   )r   r1   HUEY_CONTROL_FLOW_EXCEPTIONSscopetransaction
set_statusr   clientoptionsr"   r-   capture_event)exc_infor8   rI   rJ   r'   r'   r(   _capture_exception^   s   

r\   c                    r=   )Nc                     sd   t j}|td u r | i |S z
 | i |}W |S  ty1   t }t| t|  Y |S w r$   )	r   r1   r2   r"   	Exceptionsysr[   r\   r   )rB   rC   r8   resultr[   funcr'   r(   _sentry_executeq   s   
z+_wrap_task_execute.<locals>._sentry_executer'   )ra   rb   r'   r`   r(   _wrap_task_executeo   s   rc   c                     s   t j d fdd	} | t _d S )Nc              	      s  t j}|td u r | ||S | e}t  d|_|  |t	| W d    n1 s1w   Y  t
|jdtjtd}t|ddsOt|j|_d|_||  | ||W  d    W  d    S 1 slw   Y  W d    d S 1 s|w   Y  d S )Nr#   ok)r5   statusr/   source_sentry_is_patchedFT)r   r1   r2   r"   
push_scoper   _nameclear_breadcrumbsadd_event_processorrM   r   r5   r   QUEUE_TASK_HUEYr   getattrrc   executerg   start_transaction)r6   r7   	timestampr8   rU   rV   old_executer'   r(   rb      s0   

"z&patch_execute.<locals>._sentry_executer$   )r   _execute)rb   r'   rq   r(   r&      s   
r&   )4
__future__r   r^   r   sentry_sdk._compatr   sentry_sdk._typesr   
sentry_sdkr   sentry_sdk.constsr   sentry_sdk.hubr   sentry_sdk.integrationsr	   r
   sentry_sdk.tracingr   r   sentry_sdk.utilsr   r   r   typingr   r   r   r   r   r   r   r   r   r   huey.apir   r   r   r   huey.exceptionsr   r    r!   ImportErrorrT   r"   r%   rM   r\   rc   r&   r'   r'   r'   r(   <module>   s:    

