o
    0 i                     @   s4  d dl Z d dlZd dlmZ d dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZ d dlmZmZmZmZmZ 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 W n eyc   edw d dl m!Z! e!rd dl m"Z"m#Z# d dl$m%Z%m&Z& d dlm'Z' d dlm(Z( G dd de	Z)dd Z*dd Z+dS )    N)OP)continue_trace)_check_minimum_versionDidNotEnableIntegration)ignore_logger)TransactionSource)capture_internal_exceptionsensure_integration_enabledevent_from_exceptionformat_timestampparse_version)Queue)JobTimeoutException)VERSION)Worker)	JobStatuszRQ not installed)TYPE_CHECKING)AnyCallable)EventEventProcessor)ExcInfo)Jobc                   @   s&   e Zd ZdZde Zedd ZdS )RqIntegrationrqzauto.queue.c                     sz   t t} tt|  tjttfdd}|t_tjfdd}|t_tj	 tt  fdd}|t_	t
d d S )Nc              	      s   t  d}|  |tt| t|j	dpi t
jdtjtjd}t  |j|_W d    n1 s7w   Y  t j|d|id  | |g|R i |}W d    n1 s\w   Y  W d    n1 skw   Y  | jryt    |S )N_sentry_trace_headerszunknown RQ task)opnamesourceoriginrq_job)Zcustom_sampling_context)
sentry_sdkZ	new_scopeZclear_breadcrumbsZadd_event_processor_make_event_processorweakrefrefr   metagetr   ZQUEUE_TASK_RQr   ZTASKr   r    r	   	func_namer   Zstart_transactionZis_horse
get_clientflush)selfjobargskwargsscopeZtransactionrv)old_perform_job f/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/sentry_sdk/integrations/rq.pysentry_patched_perform_job1   s0   

z<RqIntegration.setup_once.<locals>.sentry_patched_perform_jobc                    sT   t |do|jo|jdk}|jtjkp|j}|r|st|  | |g|R i |S )Nretries_leftr   )hasattrr5   Z_statusr   ZFAILEDZ	is_failed_capture_exception)r+   r,   exc_infor.   retryfailed)old_handle_exceptionr2   r3   sentry_patched_handle_exceptionU   s   
zARqIntegration.setup_once.<locals>.sentry_patched_handle_exceptionc                    s6   t  }|jd urt| |jd<  | |fi |S )Nr   )r"   Zget_current_scopespandictZiter_trace_propagation_headersr&   )r+   r,   r.   r/   )old_enqueue_jobr2   r3   sentry_patched_enqueue_jobf   s   

z<RqIntegration.setup_once.<locals>.sentry_patched_enqueue_jobz	rq.worker)r   
RQ_VERSIONr   r   r   Zperform_jobr
   Zhandle_exceptionr   Zenqueue_jobr   )versionr4   r<   r@   r2   )r?   r;   r1   r3   
setup_once)   s   

zRqIntegration.setup_onceN)__name__
__module____qualname__
identifierr    staticmethodrC   r2   r2   r2   r3   r   %   s
    
r   c                    s    fdd}|S )Nc                    s     }|d urEt  3 | di }|j|j|j|j|jd}|jr(t|j|d< |j	r2t|j	|d< ||d< W d    n1 s@w   Y  d|v rvt  " t
|d d trfdd	|jg| d
< W d    | S W d    | S 1 sqw   Y  | S )Nextra)Zjob_idfuncr-   r.   descriptionenqueued_at
started_atzrq-jobr8   r   r   r   fingerprint)r	   
setdefaultidr(   r-   r.   rK   rL   r   rM   
issubclassr   )eventhintr,   rI   r!   weak_jobr2   r3   event_processorx   s6   


z._make_event_processor.<locals>.event_processorr2   )rU   rV   r2   rT   r3   r#   v   s   r#   c                 K   s4   t  }t| |jdddd\}}t j||d d S )Nr   F)typeZhandled)Zclient_optionsZ	mechanism)rS   )r"   r)   r   optionsZcapture_event)r8   r.   clientrR   rS   r2   r2   r3   r7      s   
r7   ),r$   r"   Zsentry_sdk.constsr   Zsentry_sdk.apir   Zsentry_sdk.integrationsr   r   r   Zsentry_sdk.integrations.loggingr   Zsentry_sdk.tracingr   Zsentry_sdk.utilsr	   r
   r   r   r   Zrq.queuer   Zrq.timeoutsr   Z
rq.versionr   rA   Z	rq.workerr   Zrq.jobr   ImportErrortypingr   r   r   Zsentry_sdk._typesr   r   r   r   r   r#   r7   r2   r2   r2   r3   <module>   s4    Q!