
    Dj=                     :   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 d dl	m
Z
 d dlmZ d dlmZmZmZ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 d dlm Z  e rd 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e      Z(d Z)d Z*y# e$ r	  ed      w xY w)    N)OP)continue_trace)DidNotEnableIntegration)ignore_logger)TRANSACTION_SOURCE_TASK)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                   *    e Zd ZdZde Zed        Zy)RqIntegrationrqzauto.queue.c                     t        t              } | t        dj                  t                    | dk  rt        d      t        j
                  t        t              fd       }|t        _        t        j                  fd}|t        _        t        j                  t        t              fd       }|t        _
        t        d       y )NzUnparsable RQ version: {})r      zRQ 0.6 or newer is required.c                    t        j                         5 }|j                          |j                  t	        t        j                  |                   t        |j                  j                  d      xs i t        j                  dt        t        j                        }t               5  |j                   |_        d d d        t        j$                  |d|i      5   | |g|i |}d d d        d d d        | j&                  r"t        j(                         j+                          S # 1 sw Y   pxY w# 1 sw Y   MxY w# 1 sw Y   QxY w)N_sentry_trace_headerszunknown RQ task)opnamesourceoriginrq_job)custom_sampling_context)
sentry_sdk	new_scopeclear_breadcrumbsadd_event_processor_make_event_processorweakrefrefr   metagetr   QUEUE_TASK_RQr   r   r$   r	   	func_namer"   start_transactionis_horse
get_clientflush)selfjobargskwargsscopetransactionrvold_perform_jobs          ^C:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\sentry_sdk/integrations/rq.pysentry_patched_perform_jobz<RqIntegration.setup_once.<locals>.sentry_patched_perform_job7   s&    %%' E5'')))*?C@P*QR,HHLL!89?R''*2(// 12 5'*}}K$5  11-5sO E )sDTDVDB	EE* }} %%'--/I5 5E EE Es<   BE+D,=!ED8,E,D5	1E8E	=EEc                     t        |d      xr |j                  xr |j                  dkD  }|j                  t        j                  k(  xs |j
                  }|r|st        |        | |g|i |S )Nretries_leftr   )hasattrrA   _statusr   FAILED	is_failed_capture_exception)r6   r7   exc_infor9   retryfailedold_handle_exceptions         r>   sentry_patched_handle_exceptionzARqIntegration.setup_once.<locals>.sentry_patched_handle_exception[   sx     ^, )$$)$$q( 
 [[I$4$44EFe"8,'cGHGGG    c                     t        j                         }|j                  &t        |j	                               |j
                  d<    | |fi |S )Nr    )r'   get_current_scopespandictiter_trace_propagation_headersr.   )r6   r7   r9   r:   old_enqueue_jobs       r>   sentry_patched_enqueue_jobz<RqIntegration.setup_once.<locals>.sentry_patched_enqueue_jobl   sQ     002Ezz%4888:501 #4777rL   z	rq.worker)r   
RQ_VERSIONr   formatr   perform_jobr
   r   handle_exceptionr   enqueue_jobr   )versionr?   rK   rS   rR   rJ   r=   s       @@@r>   
setup_oncezRqIntegration.setup_once)   s      
+?:AA*MNNV=>> ,,	#M?	C	 
D	> 8%66	H #B++	#M?	C	8 
D	8 7k"rL   N)__name__
__module____qualname__
identifierr$   staticmethodrZ    rL   r>   r   r   %   s'    J:,'FO# O#rL   r   c                       fd}|S )Nc                 &           }|t               5  | j                  di       }|j                  |j                  |j                  |j
                  |j                  d}|j                  rt        |j                        |d<   |j                  rt        |j                        |d<   ||d<   d d d        d|v r=t               5  t        |d   d   t              rdd	|j                  g| d
<   d d d        | S | S # 1 sw Y   LxY w# 1 sw Y   | S xY w)Nextra)job_idfuncr8   r9   descriptionenqueued_at
started_atzrq-jobrG   r   r   r   fingerprint)r	   
setdefaultidr1   r8   r9   rf   rg   r   rh   
issubclassr   )eventhintr7   rc   r%   weak_jobs        r>   event_processorz._make_event_processor.<locals>.event_processor~   s   j?,. )(("5!ffMMHH!jj#&?? ??,<S__,MF=)>>+;CNN+KF<("(h)" ,. Xd:.q13FG,02G+WE-(X u-) )$X s   BC:)D:DDr`   )ro   rp   s   ` r>   r+   r+   |   s    8 rL   c                     t        j                         }t        | |j                  ddd      \  }}t        j                  ||       y )Nr   F)typehandled)client_options	mechanism)rn   )r'   r4   r   optionscapture_event)rG   r9   clientrm   rn   s        r>   rF   rF      sB    ""$F&~~E2KE4 U.rL   )+r,   r'   sentry_sdk.constsr   sentry_sdk.apir   sentry_sdk.integrationsr   r   sentry_sdk.integrations.loggingr   sentry_sdk.tracingr   sentry_sdk.utilsr	   r
   r   r   r   rq.queuer   rq.timeoutsr   
rq.versionr   rT   	rq.workerr   rq.jobr   ImportErrortypingr   r   r   sentry_sdk._typesr   r   r   r   r   r+   rF   r`   rL   r>   <module>r      s        ) = 9 6 +/0   !$7(T#K T#nB
/M  +
)
**+s   B B