Yohohohohohooho | Sanrei Aya
Sanrei Aya


Server : LiteSpeed
System : Linux barito.iixcp.rumahweb.net 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64
User : elvh3918 ( 1528)
PHP Version : 8.2.31
Disable Function : mail
Directory :  /usr/local/lib/python3.9/site-packages/celery/backends/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/local/lib/python3.9/site-packages/celery/backends/__pycache__/redis.cpython-39.pyc
a

��Sh�g�@s�dZddlZddlmZddlmZddlmZmZm	Z	ddl
mZddlm
Z
ddlmZdd	lmZmZdd
lmZddlmZddlmZdd
lmZmZmZddlmZmZddl m!Z!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(m)Z)ddl*m+Z+zddl,Z-ddl.m/Z/Wne0�y,dZ-dZ/Yn0zddl1Z-Wne0�yNYn0dZ2dZ3dZ4dZ5dZ6dZ7dZ8dZ9dZ:e$e;�Z<Gdd �d e)�Z=Gd!d"�d"e+e(�Z>e?e-d#d��r�Gd$d%�d%e-j@jAe-jB�ZCGd&d'�d'e>�ZDdS)(zRedis result store backend.�N)�contextmanager)�partial)�	CERT_NONE�
CERT_OPTIONAL�
CERT_REQUIRED)�unquote)�retry_over_time)�cached_property)�
_parse_url�maybe_sanitize_url)�states)�task_join_will_block)�maybe_signature)�BackendStoreError�
ChordError�ImproperlyConfigured)�GroupResult�allow_join_result)�_regen�
dictfilter)�
get_logger)�humanize_seconds�)�AsyncBackendMixin�BaseResultConsumer)�BaseKeyValueStoreBackend)�get_redis_error_classes)�RedisBackend�SentinelBackendzW
You need to install the redis library in order to use the Redis result store backend.
zp
You need to install the redis library with support of sentinel in order to use the Redis result store backend.
z�
Setting ssl_cert_reqs=CERT_OPTIONAL when connecting to redis means that celery might not validate the identity of the redis broker when connecting. This leaves you vulnerable to man in the middle attacks.
z�
Setting ssl_cert_reqs=CERT_NONE when connecting to redis means that celery will not validate the identity of the redis broker when connecting. This leaves you vulnerable to man in the middle attacks.
z�
SSL connection parameters have been provided but the specified URL scheme is redis://. A Redis SSL connection URL should use the scheme rediss://.
zv
A rediss:// URL must have parameter ssl_cert_reqs and this must be set to CERT_REQUIRED, CERT_OPTIONAL, or CERT_NONE
z+Connection to Redis lost: Retry (%s/%s) %s.z�
Retry limit exceeded while trying to reconnect to the Celery redis result store backend. The Celery application must be restarted.
cs�eZdZdZ�fdd�Z�fdd�Zdd�Zedd	��Zd
d�Z	�fdd
�Z
dd�Zdd�Zdd�Z
ddd�Zdd�Zdd�Zdd�Z�ZS)�ResultConsumerNcsFt�j|i|��|jj|_|jj|_|jj|_|jj	|_
t�|_dS�N)
�super�__init__�backendZget_key_for_task�_get_key_for_taskZ
decode_result�_decode_result�ensure�_ensure�connection_errors�_connection_errors�set�
subscribed_to��self�args�kwargs��	__class__��?/usr/local/lib/python3.9/site-packages/celery/backends/redis.pyr"Ss



zResultConsumer.__init__c
shz&|jjj��|jdur$|j��Wn2tyX}zt�t	|��WYd}~n
d}~00t
���dSr )r#�client�connection_pool�reset�_pubsub�close�KeyError�logger�warning�strr!�
on_after_fork)r-�er0r2r3r=[s
$zResultConsumer.on_after_forkcCs�d|_|jjj��|jrT|jj�|j�}dd�|D�}|D]}|�|�|�d�q<|jjj	dd�|_|jr||jj
|j�n*|jj�d|jj�|j_
|jj
�|jj�dS)NcSsg|]}|r|�qSr2r2)�.0�metar2r2r3�
<listcomp>k�z4ResultConsumer._reconnect_pubsub.<locals>.<listcomp>T�Zignore_subscribe_messages�pubsub)r7r#r4r5r6r+�mget�on_state_changer%rD�	subscribe�get_connectionZ
shard_hint�
connectionZregister_connect_callbackZ
on_connect)r-Zmetasr@r2r2r3�_reconnect_pubsubds ��z ResultConsumer._reconnect_pubsubccsXz
dVWnH|jyRz|�|jd�Wn |jyLt�t��Yn0Yn0dS)Nr2)r)r'rJr:�critical�E_RETRY_LIMIT_EXCEEDED�r-r2r2r3�reconnect_on_error|s

z!ResultConsumer.reconnect_on_errorcCs |dtjvr|�|d�dS)N�status�task_id)rZREADY_STATES�
cancel_for)r-r@r2r2r3�_maybe_cancel_ready_task�sz'ResultConsumer._maybe_cancel_ready_taskcst��||�|�|�dSr )r!rFrR)r-r@�messager0r2r3rF�szResultConsumer.on_state_changecKs |jjjdd�|_|�|�dS)NTrC)r#r4rDr7�
_consume_from)r-Zinitial_task_idr/r2r2r3�start�s�zResultConsumer.startcKs.|jfi|��D]}|dur|�|d�qdSr )Z
_iter_metarF)r-�resultr/r@r2r2r3�on_wait_for_pending�sz"ResultConsumer.on_wait_for_pendingcCs|jdur|j��dSr )r7r8rMr2r2r3�stop�s
zResultConsumer.stopcCsv|jrd|���D|jj|d�}|rD|ddkrD|�|�|d�|�Wd�qr1sX0Yn|rrt�|�dS)N)�timeout�typerS�data)r7rNZget_messagerFr%�time�sleep)r-rYrSr2r2r3�drain_events�s
6zResultConsumer.drain_eventscCs"|jdur|�|�S|�|�dSr )r7rUrT�r-rPr2r2r3�consume_from�s

zResultConsumer.consume_fromcCsX|�|�}||jvrT|j�|�|���|j�|�Wd�n1sJ0YdSr )r$r+�addrNr7rG�r-rP�keyr2r2r3rT�s



zResultConsumer._consume_fromcCsT|�|�}|j�|�|jrP|���|j�|�Wd�n1sF0YdSr )r$r+�discardr7rNZunsubscriberbr2r2r3rQ�s


zResultConsumer.cancel_for)N)�__name__�
__module__�__qualname__r7r"r=rJrrNrRrFrUrWrXr^r`rTrQ�
__classcell__r2r2r0r3rPs	


	rcsNeZdZdZeZeZerejndZdZdZ	dZ
dZd>�fdd�	Zdd�Z
d	d
�Ze�fdd��Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z�fdd�Zdd�Zdd �Zd!d"�Zd#d$�Zejejfd%d&�Z d'd(�Z!d)d*�Z"ed+d,��Z#ed-d.��Z$d?d/d0�Z%d1d2�Z&d3d4�Z'd5d6�Z(e)d7d8��Z*ed9d:��Z+d@�fd<d=�	Z,�Z-S)ArzyRedis task result store.

    It makes use of the following commands:
    GET, MGET, DEL, INCRBY, EXPIRE, SET, SETEX
    NTi c	s t�jfdti|��|jjj}	|jdur6tt�	���|rLd|vrL|d}}|p\|	d�p\|j
|_
||_|	d�}
|	d�}|	d�}|	d�}
|	d�}|	d	�p�d
|	d�p�d|	d
�p�d|	d�|j
|
o�t|
�|p�d|o�t|�d�|_
|	d�}|r�||j
d<|r�||j
d<|
�r|
|j
d<|	d�}|�r2|j
�|�|j|j
d<|�rH|�||j
�|_
d|j
v�r�t|j
dtj��r�d}ttttttd�}|j
�d|�}|�||�}||��v�r�tt��|tk�r�t�t�n|tk�r�t�t�||j
d<||_t�r�t�nd\|_|_ |�!||j|j"|j#|j$�|_%dS)NZexpires_typez://Zredis_max_connectionsZredis_socket_timeoutZredis_socket_connect_timeoutZredis_retry_on_timeoutZredis_socket_keepaliveZ#redis_backend_health_check_intervalZ
redis_host�	localhostZ
redis_porti�Zredis_dbrZredis_passwordF)�host�port�db�password�max_connections�socket_timeout�retry_on_timeout�socket_connect_timeoutZredis_username�username�health_check_interval�socket_keepaliveZredis_backend_use_ssl�connection_class�MISSING)rrr�required�optional�none�
ssl_cert_reqs)r2r2)&r!r"�int�app�conf�get�redisr�E_REDIS_MISSING�striprn�_ConnectionPool�float�
connparams�update�connection_class_ssl�_params_from_url�
issubclass�
SSLConnectionrrr�values�
ValueError�%E_REDIS_SSL_CERT_REQS_MISSING_INVALIDr:r;�W_REDIS_SSL_CERT_OPTIONAL�W_REDIS_SSL_CERT_NONE�urlrr(Zchannel_errorsr�acceptZ_pending_resultsZ_pending_messages�result_consumer)r-rjrkrlrmrnr�r5r/�_getrorqrprtrsrr�sslZssl_cert_reqs_missingZssl_string_to_constantrzr0r2r3r"�s�


��




�


��



�

�zRedisBackend.__init__cs�t|�\}}}}}}�t|fit||||��dd�d�����|dkr���|jjd|d����dd���dd���d�n|�d	<gd
�}	|dkr�t�fdd
�|	D��s�t�fdd
�|	D��r�tt	��|dk�rtj
�d<|	D] }
��|
d�}|r�t|��|
<q��d	��pd}t
|t��r.|�d�n|}t|��d	<���D],\}
}|
tjjv�rFtjj|
|��|
<�qF�����S)NZvirtual_host)rjrkrrrmrl�socket�/)ru�pathrjrkrqrl)Zssl_ca_certsZssl_certfileZssl_keyfilerzrc3s|]}|�vVqdSr r2�r?rc)r�r2r3�	<genexpr>NrBz0RedisBackend._params_from_url.<locals>.<genexpr>c3s|]}|�vVqdSr r2r�)�queryr2r3r�OrBZredissrur)r
�dictr�popr�rZUnixDomainSocketConnection�anyr��&E_REDIS_SSL_PARAMS_AND_SCHEME_MISMATCHr�rr~�
isinstancer<r�r{�itemsrIZURL_QUERY_ARGUMENT_PARSERS)r-r��defaults�schemerjrkrrrmr�Zssl_param_keysZssl_settingZssl_valrlrc�valuer2)r�r�r3r�3sP�����


�
zRedisBackend._params_from_urlcCst||j�rdSdS)NTF)r�r()r-�excr2r2r3�exception_safe_to_retryjsz$RedisBackend.exception_safe_to_retrycs.t�j}d|jvr*|��}|�|jd�|S)N�retry_policy)r!r��_transport_options�copyr�)r-r�r0r2r3r�os

zRedisBackend.retry_policycCst�s|j�|�dSr )r
r�r`)r-ZproducerrPr2r2r3�on_task_callxszRedisBackend.on_task_callcCs|j�|�Sr )r4r~�r-rcr2r2r3r~|szRedisBackend.getcCs|j�|�Sr )r4rE)r-�keysr2r2r3rEszRedisBackend.mgetcKs>t|jfi|��}|�d�}t||j|it|j|�fi|��S)N�max_retries)r�r�r~rr(r�on_connection_error)r-Zfunr.�policyr�r�r2r2r3r&�s


��zRedisBackend.ensurecCs*t|�}t�t��||pdt|d��|S)NZInfzin )�nextr:�error�E_LOSTr�r)r-r�r�Z	intervals�retriesZttsr2r2r3r��s�z RedisBackend.on_connection_errorcKs:t|t�r t|�|jkr td��|j|j||ffi|��S)Nz!value too large for Redis backend)r�r<�len�_MAX_STR_VALUE_SIZErr&�_set)r-rcr�r�r2r2r3r*�szRedisBackend.setcCsf|j���H}|jr$|�||j|�n|�||�|�||�|��Wd�n1sX0YdSr )r4�pipeline�expires�setexr*�publish�execute)r-rcr��piper2r2r3r��szRedisBackend._setcst��|�|j�|�dSr )r!�forgetr�rQr_r0r2r3r��szRedisBackend.forgetcCs|j�|�dSr )r4�deleter�r2r2r3r��szRedisBackend.deletecCs|j�|�Sr )r4�incrr�r2r2r3r��szRedisBackend.incrcCs|j�||�Sr )r4�expire)r-rcr�r2r2r3r��szRedisBackend.expirecCs|j�|�|d�d�dS)N�.tr)r4r��get_key_for_group)r-�group_idrVr2r2r3�add_to_chord�szRedisBackend.add_to_chordc	CsB||�\}}}}||vr"|�|�}||vr>td|�d|����|S)NzDependency z raised )Zexception_to_pythonr)	r-�tup�decode�EXCEPTION_STATES�PROPAGATE_STATES�_�tid�state�retvalr2r2r3�_unpack_chord_result�s
z!RedisBackend._unpack_chord_resultcCs|�|�|d�|�dS)N�.s)r*r�)r-r�Z
chord_sizer2r2r3�set_chord_size�szRedisBackend.set_chord_sizecKs>t|dt�s:|jj|�}tdd�|jD��r:|j|d�dS)Nrcss|]}t|t�VqdSr )r�r)r?�nrr2r2r3r��rBz+RedisBackend.apply_chord.<locals>.<genexpr>)r#)r�rr|rr��results�save)r-Zheader_result_args�bodyr/�
header_resultr2r2r3�apply_chord�szRedisBackend.apply_chordcCs|j�dd�S)NZresult_chord_orderedT)r�r~rMr2r2r3�_chord_zset�szRedisBackend._chord_zsetcCs|jj�di�S)NZ result_backend_transport_options)r|r}r~rMr2r2r3r��szRedisBackend._transport_optionscs|j}|j|j|j}}}	|r$|s(dS|	dur4d}	|j}
|�|d�}|�|d�}|�|d�}
|�||�}|�d|||g�}|
����}|j	r�|�
|||	i��|dd�n|�||��
|��|��|
�}|jr�|�||j��||j��|
|j�}|��dd�\}}}}Wd�n1�s0Yt|�p.d�}|�r
�zBt|j|d	�}t|�|}||k�rzt�|�}|du�r�|��|j�r�|jn|j}t�� ||jjd
d�}Wd�n1�s�0Yn||j|j��|
���@}|j	�r�|� |dd�}n|�!|d|�}|��\}Wd�n1�s(0Y��fd
d�|D�}z�z|�"|�Wn�t#�y�}zzt$�%d|j|�|�&|t'd|����WYd}~W|
���*}|�(|��(|��(|
���Wd�n1�s�0YWSd}~00W|
���*}|�(|��(|��(|
���Wd�n1�s(0YnF|
���*}|�(|��(|��(|
���Wd�n1�sn0Y0Wn�t'�y�}z(t$�%d|j|�|�&||�WYd}~Sd}~0t#�y}z2t$�%d|j|�|�&|t'd|����WYd}~Sd}~00dS)Nz+infz.jr�r�rz-inf�r)r|T)rY�	propagate���csg|]}�|���qSr2r2)r?r��r��unpackr2r3rArBz5RedisBackend.on_chord_part_return.<locals>.<listcomp>z Chord callback for %r raised: %rzCallback error: zChord %r raised: %rzJoin error: ))r|�id�group�group_indexr4r�Z
encode_result�encoder�r�ZzaddZzcountZrpushZllenr~r�r�r�r{rZchordr�restoreZon_ready�supports_native_joinZjoin_native�joinrr}Zresult_chord_join_timeoutr�r�ZzrangeZlrange�delay�	Exceptionr:�	exceptionZchord_error_from_stackrr�)r-�requestr�rVr�r/r|r��gidr�r4ZjkeyZtkeyZskey�encodedr�r�r�Z
readycountZ	totaldiffZchord_size_bytes�callback�totalr�Z	join_funcZreslr�r2r�r3�on_chord_part_return�s�
�������8


�
��(
*��
���(�
���*�
���. �z!RedisBackend.on_chord_part_returncKs|��|jfi|��d�S)N)r5)�_get_client�	_get_pool�r-�paramsr2r2r3�_create_client0s�zRedisBackend._create_clientcCs|jjSr )rZStrictRedisrMr2r2r3r�5szRedisBackend._get_clientcKs|jfi|��Sr )�ConnectionPoolr�r2r2r3r�8szRedisBackend._get_poolcCs|jdur|jj|_|jSr )r�rr�rMr2r2r3r�;s

zRedisBackend.ConnectionPoolcCs|jfi|j��Sr )r�r�rMr2r2r3r4AszRedisBackend.clientr2cs(|sin|}t��|t||j|jd��S)N)r�r�)r!�
__reduce__r�r�r�r,r0r2r3r�Es�zRedisBackend.__reduce__)NNNNNNN)N)r2N).rerfrg�__doc__rrr�r�rnZsupports_autoexpirer�r�r"r�r�r	r�r�r~rEr&r�r*r�r�r�r�r�r�rr�r�r�r�r�r�r�r�r�r�r��propertyr�r4r�rhr2r2r0r3r�s^�a7	�



�
_

r�sentinelc@seZdZdZdS)�SentinelManagedSSLConnectionz�Connect to a Redis server using Sentinel + TLS.

        Use Sentinel to identify which Redis server is the current master
        to connect to and when connecting to the Master server, use an
        SSL Connection.
        N)rerfrgr�r2r2r2r3r�Lsr�csfeZdZdZdZeedd�Zer$endZ	�fdd�Z
d�fdd	�	Z�fd
d�Zdd
�Z
dd�Z�ZS)rz!Redis sentinel task result store.�;r�Ncs,|jdurtt����t�j|i|��dSr )r�r�E_REDIS_SENTINEL_MISSINGr�r!r"r,r0r2r3r"`s
zSentinelBackend.__init__FcsD|rt�j|d�Sdd�|jp d�|j�D�}|j�dd�|D��S)zDReturn the server addresses as URIs, sanitizing the password or not.)�include_passwordcss|]}t|�VqdSr )r)r?�chunkr2r2r3r�os�z)SentinelBackend.as_uri.<locals>.<genexpr>�css(|] }|�d�r|dd�n|VqdS)z:///Nr�)�endswith)r?�urir2r2r3r�us�)r!�as_urir��split�_SERVER_URI_SEPARATORr�)r-r�Z
uri_chunksr0r2r3r�fs���zSentinelBackend.as_urics�|�|j�}t|gd�}|D]"}t�j||d�}|d�|�qdD]}|�|�qDdD]2}|drX||ddvrX|dd�|�||<qX|S)N)�hosts)r�r�r�)rjrkrlrm)rlrmr)r�r�r�r!r��appendr�r~)r-r�r��chunksr�r�r[�paramr0r2r3r�zs�z SentinelBackend._params_from_urlcKsV|��}|�d�}|j�dd�}|j�di�}|jjdd�|D�f||d�|��}|S)Nr��min_other_sentinelsr�sentinel_kwargscSsg|]}|d|df�qS)rjrkr2)r?�cpr2r2r3rA�rBz:SentinelBackend._get_sentinel_instance.<locals>.<listcomp>)rr)r�r�r�r~r�ZSentinel)r-r�r�r�rr�sentinel_instancer2r2r3�_get_sentinel_instance�s
���z&SentinelBackend._get_sentinel_instancecKs2|jfi|��}|j�dd�}|j||��d�jS)N�master_name)Zservice_nameZredis_class)rr�r~Z
master_forr�r5)r-r�rrr2r2r3r��s�zSentinelBackend._get_pool)F)rerfrgr�r��getattrrr�r�r�r"r�r�rr�rhr2r2r0r3rWsr)Er�r\�
contextlibr�	functoolsrr�rrr�urllib.parserZkombu.utils.functionalrZkombu.utils.objectsr	Zkombu.utils.urlr
rZceleryrZ
celery._stater
Z
celery.canvasrZcelery.exceptionsrrrZ
celery.resultrrZcelery.utils.functionalrrZcelery.utils.logrZcelery.utils.timerZasynchronousrr�baserZredis.connectionrZkombu.transport.redisr�ImportErrorZredis.sentinel�__all__r�r�r�r�r�r�r�rLrer:rrr	r�ZSentinelManagedConnectionr�r�rr2r2r2r3�<module>sb
k
�

Yohohohohohooho | Sanrei Aya