o
    Zh                     @   s<  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
mZ d dlmZ d dlmZ d d	l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 yg   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 )    )absolute_importN)OP)continue_trace)Hub)DidNotEnableIntegration)ignore_logger)TRANSACTION_SOURCE_TASK)capture_internal_exceptions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edd ZdS )RqIntegrationrqc                     s   t t} | d u rtdt| dk rtdtjfdd}|t_tjfdd}|t_tj  fdd	}|t_t	d
 d S )NzUnparsable RQ version: {})r      zRQ 0.6 or newer is required.c           
   	      s.  t j}|t}|d u r | |g|R i |S |j}|d us!J | a}|  |tt	
| t|jdp<i tjdtd}t  |j|_W d    n1 sUw   Y  |j|d|id  | |g|R i |}	W d    n1 szw   Y  W d    n1 sw   Y  | jr|  |	S )N_sentry_trace_headerszunknown RQ task)opnamesourcerq_job)Zcustom_sampling_context)r   currentget_integrationr   clientZ
push_scopeZclear_breadcrumbsZadd_event_processor_make_event_processorweakrefrefr   metagetr   ZQUEUE_TASK_RQr	   r
   	func_namer   Zstart_transactionZis_horseflush)
selfjobargskwargshubZintegrationr$   scopeZtransactionrv)old_perform_job Q/var/www/html/lang_env/lib/python3.10/site-packages/sentry_sdk/integrations/rq.pysentry_patched_perform_job7   s8   


z<RqIntegration.setup_once.<locals>.sentry_patched_perform_jobc                    s2   |j tjks	|jrt|  | |g|R i |S )N)Z_statusr   ZFAILEDZ	is_failed_capture_exception)r,   r-   exc_infor/   )old_handle_exceptionr4   r5   sentry_patched_handle_exceptiona   s   zARqIntegration.setup_once.<locals>.sentry_patched_handle_exceptionc                    sD   t j}|td ur|jjd urt| |jd<  | |fi |S )Nr   )	r   r"   r#   r   r1   spandictZiter_trace_propagation_headersr(   )r,   r-   r/   r0   )old_enqueue_jobr4   r5   sentry_patched_enqueue_jobn   s   
z<RqIntegration.setup_once.<locals>.sentry_patched_enqueue_jobz	rq.worker)
r   
RQ_VERSIONr   formatr   Zperform_jobZhandle_exceptionr   Zenqueue_jobr   )versionr6   r:   r>   r4   )r=   r9   r3   r5   
setup_once)   s   &	zRqIntegration.setup_onceN)__name__
__module____qualname__
identifierstaticmethodrB   r4   r4   r4   r5   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/   rJ   rK   r   rL   
issubclassr   )eventhintr-   rH   r!   weak_jobr4   r5   event_processor   s6   


z._make_event_processor.<locals>.event_processorr4   )rT   rU   r4   rS   r5   r%   ~   s   r%   c                 K   sJ   t j}|td u rd S |j}t| |jdddd\}}|j||d d S )Nr   F)typeZhandled)Zclient_optionsZ	mechanism)rR   )r   r"   r#   r   r$   r   optionsZcapture_event)r8   r/   r0   r$   rQ   rR   r4   r4   r5   r7      s   
r7   )-
__future__r   r&   Zsentry_sdk.constsr   Zsentry_sdk.apir   Zsentry_sdk.hubr   Zsentry_sdk.integrationsr   r   Zsentry_sdk.integrations.loggingr   Zsentry_sdk.tracingr	   Zsentry_sdk.utilsr
   r   r   r   Zrq.queuer   Zrq.timeoutsr   Z
rq.versionr   r?   Z	rq.workerr   Zrq.jobr   ImportErrorZsentry_sdk._typesr   typingr   r   r   r   r   r   r   r%   r7   r4   r4   r4   r5   <module>   s6    X!