HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //usr/local/lib/python3.9/site-packages/celery/backends/__pycache__/elasticsearch.cpython-39.pyc
a

X>hn%�@s�dZddlmZmZddlmZddlmZddlmZddl	m
Z
ddlmZzdd	l
Z
Wneyrd	Z
Yn0zdd	lZWney�d	ZYn0d
ZdZGdd
�d
e�Zd	S)z#Elasticsearch result store backend.�)�datetime�timezone��bytes_to_str)�
_parse_url)�states)�ImproperlyConfigured�)�KeyValueStoreBackendN)�ElasticsearchBackendzVYou need to install the elasticsearch library to use the Elasticsearch result backend.cs�eZdZdZdZdZdZdZdZdZ	dZ
dZdZd	Z
d&�fd
d�	Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z�fdd�Z�fdd�Zdd�Zd d!�Zd"d#�Zed$d%��Z�ZS)'rz�Elasticsearch Backend.

    Raises:
        celery.exceptions.ImproperlyConfigured:
            if module :pypi:`elasticsearch` is not available.
    �celeryN�http�	localhosti�#F�
�cs<t�j|i|��||_|jjj}tdur2tt��d}}}}}	}
}|r�t	|�\}}}	}
}}}
|dkrtd}|r�|�
d�}|�d�\}}
}|p�|j|_|p�|j
|_
|p�|j|_|p�|j|_|	p�|j|_|
p�|j|_|p�|j|_|d�p�|j|_|d�}|du�r||_|d�}|du�r&||_|dd�|_d|_dS)N�
elasticsearch�/Zelasticsearch_retry_on_timeoutZelasticsearch_timeoutZelasticsearch_max_retriesZelasticsearch_save_meta_as_textT)�super�__init__�urlZapp�conf�getrr�
E_LIB_MISSINGr�strip�	partition�index�doc_type�scheme�host�port�username�password�es_retry_on_timeout�
es_timeout�es_max_retries�es_save_meta_as_text�_server)�selfr�args�kwargs�_getrrrrrr r!�path�_r#r$��	__class__��G/usr/local/lib/python3.9/site-packages/celery/backends/elasticsearch.pyr1s<

�

zElasticsearchBackend.__init__cCs2t|tjj�r|jdvrdSt|tjj�r.dSdS)N>zN/Ai�i�i�i��TF)�
isinstancer�
exceptionsZApiError�status_codeZTransportError)r'�excr/r/r0�exception_safe_to_retryZs
z,ElasticsearchBackend.exception_safe_to_retryc	Cs^zB|�|�}z|dr&|ddWWSWnttfy>Yn0WntjjyXYn0dS)N�found�_source�result)r*�	TypeError�KeyErrorrr3�
NotFoundError)r'�key�resr/r/r0rhs

zElasticsearchBackend.getcCs2|jr|jj|j||jd�S|jj|j|d�SdS�N)r�idr)rr@)r�serverrr�r'r=r/r/r0r*ss��zElasticsearchBackend._getcCs`|d�t�tj���dd��d�}z|j||d�Wn$tjj	yZ|�
|||�Yn0dS)Nz{}Zi����)r9z
@timestamp)r@�body)�formatr�nowr�utc�	isoformat�_indexrr3�
ConflictError�_update)r'r=�value�staterCr/r/r0�_set_with_state�s���
z$ElasticsearchBackend._set_with_statecCs|�||d�S�N)rM)r'r=rKr/r/r0�set�szElasticsearchBackend.setcKsldd�|��D�}|jrB|jjft|�|j|j|ddid�|��S|jjft|�|j|ddid�|��SdS)NcSsi|]\}}t|�|�qSr/r��.0�k�vr/r/r0�
<dictcomp>��z/ElasticsearchBackend._index.<locals>.<dictcomp>Zop_type�create�r@rrrC�params�r@rrCrX)�itemsrrArr)r'r@rCr)r/r/r0rH�s&��	��zElasticsearchBackend._indexc
Ks�dd�|��D�}z0|j|d�}|�d�s@|j||fi|��WSWn*tjjyl|j||fi|��YS0z|�|dd�}Wntt	fy�Yn80|dt
jkr�ddiS|dt
jvr�|t
j
vr�ddiS|�d	d
�}|�dd
�}|j�r$|jjft|�|j|jd|i||d
�d�|��}	n,|jjft|�|jd|i||d
�d�|��}	|	ddk�r�tj�dt�ddt��dt�|j|j|j��d��|	S)auUpdate state in a conflict free manner.

        If state is defined (not None), this will not update ES server if either:
        * existing state is success
        * existing state is a ready state and current state in not a ready state

        This way, a Retry state cannot override a Success or Failure, and chord_unlock
        will not retry indefinitely.
        cSsi|]\}}t|�|�qSr/rrPr/r/r0rT�rUz0ElasticsearchBackend._update.<locals>.<dictcomp>)r=r7r8r9�statusZnoopZ_seq_nor	Z
_primary_term�doc)Zif_primary_termZ	if_seq_norWrYz(conflicting update occurred concurrentlyr1zHTTP/1.1rN)rZr*rrHrr3r<Z
decode_resultr:r;r�SUCCESSZREADY_STATESZUNREADY_STATESrrA�updaterrrI�elastic_transportZApiResponseMetaZHttpHeadersZ
NodeConfigrrr)
r'r@rCrLr)Zres_getZmeta_present_on_backendZseq_noZ	prim_termr>r/r/r0rJ�s\

��	��
���zElasticsearchBackend._updatecsp|jrt��|�St|t�s(t��|�S|�d�rH|�|d�d|d<|�d�rh|�|d�d|d<|SdS)Nr9��	traceback)r%r�encoder2�dictr�_encode)r'�datar-r/r0rb�s


zElasticsearchBackend.encodecsl|jrt��|�St|t�s(t��|�S|�d�rFt��|d�|d<|�d�rdt��|d�|d<|SdS)Nr9ra)r%r�decoder2rcr)r'�payloadr-r/r0rf�s


zElasticsearchBackend.decodecs�fdd�|D�S)Ncsg|]}��|��qSr/)r)rQr=�r'r/r0�
<listcomp>rUz-ElasticsearchBackend.mget.<locals>.<listcomp>r/)r'�keysr/rhr0�mgetszElasticsearchBackend.mgetcCs4|jr|jj|j||jd�n|jj|j|d�dSr?)rrA�deleterrBr/r/r0rlszElasticsearchBackend.deletecCsLd}|jr|jr|j|jf}tj|j�d|j�d|j��|j|j|j	|d�S)z$Connect to the Elasticsearch server.Nz://�:)Zretry_on_timeout�max_retries�timeout�	http_auth)
r r!rZ
Elasticsearchrrrr"r$r#)r'rpr/r/r0�_get_server
s�z ElasticsearchBackend._get_servercCs|jdur|��|_|jSrN)r&rqrhr/r/r0rAs

zElasticsearchBackend.server)N)�__name__�
__module__�__qualname__�__doc__rrrrrr r!r"r#r$rr6rr*rMrOrHrJrbrfrkrlrq�propertyrA�
__classcell__r/r/r-r0rs4)
B
r)rurrZkombu.utils.encodingrZkombu.utils.urlrrrZcelery.exceptionsr�baser
r�ImportErrorr_�__all__rrr/r/r/r0�<module>s"