��\� � @ 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 m Z d d l m Z d d l m Z Gd d � d e � Z d d � Z d d � Z d S)� )�absolute_importN)�Hub)�Integration)�capture_internal_exceptions�event_from_exception)�JobTimeoutException)�Workerc @ s( e Z d Z d Z e d d � � Z d S)� RqIntegration�rqc sL t j � � f d d � } | t _ t j � � f d d � } | t _ d S)Nc s� t j } | j t � } | d k r7 � | | | | � S| j � �B } | j � | j t t j | � � � � | | | | � } Wd QRX| j r� | j j � | S)N) r �current�get_integrationr Z push_scopeZclear_breadcrumbsZadd_event_processor�_make_event_processor�weakref�refZis_horse�client�flush)�self�job�args�kwargs�hubZintegrationZscope�rv)�old_perform_job� �/rq.py�sentry_patched_perform_job s z<RqIntegration.setup_once.<locals>.sentry_patched_perform_jobc s t | � � | | | | � S)N)�_capture_exception)r r �exc_infor )�old_handle_exceptionr r �sentry_patched_handle_exception9 s zARqIntegration.setup_once.<locals>.sentry_patched_handle_exception)r Zperform_jobZhandle_exception)r r r )r r r � setup_once s zRqIntegration.setup_onceN)�__name__� __module__�__qualname__Z identifier�staticmethodr r r r r r s r c s � f d d � } | S)Nc s� � � } | d k r� t � � | j | d <Wd QRXt � �N | j d i � } d | j d | j d | j d | j d | j i | d <Wd QRXd | k r� t � �2 t | d d t � r� d d | j g | d <Wd QRX| S)NZtransaction�extraZjob_id�funcr r �descriptionzrq-jobr r r r Zfingerprint) r � func_name� setdefault�idr r r'