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__/gcs.cpython-39.pyc
a

��Sh{0�@spdZddlmZddlmZmZddlmZddlmZddl	m
Z
ddlmZddl
mZdd	lmZdd
lmZmZddlmZmZddlmZd
dlmZzTddlZddlmZddlmZddl m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'Wne(�ydZ#Yn0zddl"m)Z)m*Z*Wne(�y>dZ)dZ*Yn0dZ+ee,�Z-Gdd�de�Z.Gdd�de.�Z/dS)z5Google Cloud Storage result store backend for Celery.�)�ThreadPoolExecutor)�datetime�	timedelta)�getpid)�RLock)�bytes_to_str)�
dictfilter)�url_to_parts)�maybe_signature)�
ChordError�ImproperlyConfigured)�GroupResult�allow_join_result)�
get_logger�)�KeyValueStoreBackendN��retry)�Conflict)�if_exception_type)�storage)�Client)�
DEFAULT_RETRY)�	firestore�firestore_admin_v1)�
GCSBackendcspeZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Ze	dd
��Z
e	dd��Zdd�Zdd�Z
dd�Z�ZS)�GCSBackendBasez)Google Cloud Storage task result backend.cststd��t�jfi|��t�|_t�|_t|_	d|_
|jj}|j
rd|��}|jfit|���|�d�|_|js~td��|�d�|_|js�td��|�dd��d�|_t|�d	d
��|_t|�d�p�d�|_|jdkr�td
|j�d���n"|j�r|���std|j����dS)Nz8You must install google-cloud-storage to use gcs backend�
gcs_bucketz:Missing bucket name: specify gcs_bucket to use gcs backendZgcs_projectz6Missing project:specify gcs_project to use gcs backend�
gcs_base_path��/Zgcs_threadpool_maxsize�
Zgcs_ttlrz
Invalid ttl: z# must be greater than or equal to 0z>Missing lifecycle rule to use gcs backend with ttl on bucket: )rr�super�__init__r�_client_lockr�_pidr�
_retry_policy�_client�app�conf�url�_params_from_url�updater�get�bucket_name�project�strip�	base_path�int�_threadpool_maxsize�float�ttl� _is_bucket_lifecycle_rule_exists)�self�kwargsr)Z
url_params��	__class__��=/usr/local/lib/python3.9/site-packages/celery/backends/gcs.pyr#-sJ���
�
��zGCSBackendBase.__init__cCs@t|�}|�|�}z|j|jd�WStjjy:YdS0dS�Nr)r�	_get_blobZdownload_as_bytesr&r�blobZNotFound�r7�keyr?r;r;r<r-Us
zGCSBackendBase.getcCsBt|�}|�|�}|jr.t��t|jd�|_|j||jd�dS)N��secondsr)	rr>r5r�utcnowrZcustom_timeZupload_from_stringr&)r7rA�valuer?r;r;r<�set]s

zGCSBackendBase.setcCs,t|�}|�|�}|��r(|j|jd�dSr=)rr>�exists�deleter&r@r;r;r<rHds
zGCSBackendBase.deletecCs<t��"}t|�|j|��Wd�S1s.0YdS�N)r�list�mapr-)r7�keys�poolr;r;r<�mgetjszGCSBackendBase.mgetcCs�|j��|jr.|jt�kr.|jWd�St|jd�|_t�|_tjj|j	|j	dd�}|jj
}|�d|�|jj
�d|�|jWd�S1s�0YdS)zReturns a storage client.N�r/�)�pool_connections�pool_maxsize�max_retrieszhttps://)r$r'r%rrr/�requests�adapters�HTTPAdapterr3Z_http�mountZ
_auth_request�session)r7�adapterZclient_httpr;r;r<�clientns�zGCSBackendBase.clientcCs|j�|j�SrI)rZ�bucketr.�r7r;r;r<r[�szGCSBackendBase.bucketcCs&|jr|j�d|��n|}|j�|�S)Nr )r1r[r?)r7rAZkey_bucket_pathr;r;r<r>�szGCSBackendBase._get_blobcCs4|j}|��|jD]}|dddkrdSqdS)N�action�type�DeleteTF)r[�reloadZlifecycle_rules)r7r[Zruler;r;r<r6�s
z/GCSBackendBase._is_bucket_lifecycle_rule_existscCst|j�}|j|jd�|j�S)N)rr)r	r*�hostname�path�query)r7Z	url_partsr;r;r<r+�s
��zGCSBackendBase._params_from_url)�__name__�
__module__�__qualname__�__doc__r#r-rFrHrN�propertyrZr[r>r6r+�
__classcell__r;r;r9r<r*s(

rcs�eZdZdZdZdZdZdZdZ�fdd�Z	e
dd	��Zd
d�Z�fdd
�Z
eed�dd�Zdd�Zdd�Zdd�Zdd�Zdd�Z�ZS)rzWGoogle Cloud Storage task result backend.

    Uses Firestore for chord ref count.
    TZceleryZchord_countZ
expires_atcshtrtstd��t�jfi|��t�|_d|_|jj	�
d|j�|_|�
�sdtd|j�d|j����dS)Nz:You must install google-cloud-firestore to use gcs backend�firestore_projectzHMissing TTL policy to use gcs backend with ttl on Firestore collection: z
 project: )rrrr"r#r�_firestore_lock�_firestore_clientr(r)r-r/rj� _is_firestore_ttl_policy_enabled�_collection_name)r7r8r9r;r<r#�s$�����zGCSBackend.__init__cCsj|j�N|jr.|jt�kr.|jWd�Stj|jd�|_t�|_Wd�n1sZ0Y|jS)zReturns a firestore client.NrO)rkrlr%rrrrjr\r;r;r<�firestore_client�s�&zGCSBackend.firestore_clientcCsdt��}d|j�d|j�d|j��}tj|d�}|j|d�}|j}|ob|jtj	j
jjtj	j
jj
hvS)Nz	projects/z&/databases/(default)/collectionGroups/z/fields/)�name)�request)rZFirestoreAdminClientrjrn�_field_expiresZGetFieldRequest�	get_field�
ttl_config�stateZFieldZ	TtlConfig�StateZACTIVEZCREATING)r7rZrprq�fieldrtr;r;r<rm�s
���

�z+GCSBackend._is_firestore_ttl_policy_enabledcs4|�|d���}|�|d�t�j||fi|��S)Nri�Q)�get_key_for_chord�decode�_expire_chord_keyr"�_apply_chord_incr)r7Zheader_result_args�bodyr8rAr9r;r<r{�szGCSBackend._apply_chord_incr)rA�returnc
CsF|�|�}|j|jt�d�idtjtt�ddddd�d�}|j	dj
S)	NrTg�?g�f@g@)�	predicate�initial�maximum�
multiplier�timeout)�mergerr)�_firestore_documentrF�_field_countrZ	Incrementr�RetryrrZtransform_resultsZ
integer_value)r7rA�doc�respr;r;r<�incr�s
��zGCSBackend.incrcKs�|j}|j}|sdS|�|�}|�|�}|j�d�}	|	dur\|�||�}
|
durTdSt|
�}	||	krtt�	d|��nx||	k�r�|�||�}
|
dur�dSt
|j|d�}|
j}�z*z:t�� ||j
jdd�}
Wd�n1s�0YWn~t�yf}zdzt|
���}d�||�}Wnt�y2t|�}Yn0t�d||�|�|t|��WYd}~ndd}~00z|�|
�WnJt�y�}z0t�d||�|�|td	|����WYd}~n
d}~00W|
��|�|�n|
��|�|�0dS)
a~Chord part return callback.

        Called for each task in the chord.
        Increments the counter stored in Firestore.
        If the counter reaches the number of tasks in the chord, the callback
        is called.
        If the callback raises an exception, the chord is marked as errored.
        If the callback returns a value, the chord is marked as successful.
        NZ
chord_sizez/Chord counter incremented too many times for %r�r(T)r��	propagatezDependency {0.id} raised {1!r}�Chord %r raised: %rzCallback error: )r(�grouprxr��chordr-�
_restore_deps�len�logger�warningr
Zjoin_nativerr)Zresult_chord_join_timeout�	Exception�nextZ_failed_join_report�format�
StopIteration�repr�	exception�chord_error_from_stackr�delayrH�_delete_chord_key)r7rqru�resultr8r(�gidrA�val�size�deps�callback�j�ret�excZculprit�reasonr;r;r<�on_chord_part_return�sf


�
�(�&��zGCSBackend.on_chord_part_returnc
Cs�|j}ztj||d�}WnXtyp}z@t|j|d�}t�d||�|�|t	d|����WYd}~dSd}~00|dur�zt
|��WnXt
y�}z@t|j|d�}t�d||�|�|t	d|�d���WYd}~n
d}~00|S)N)�backendr�r�zCannot restore group: zChord callback %r raised: %rzGroupResult z no longer exists)r(r
�restorer�r
r�r�r�r�r�
ValueError)r7r�rqr(r�r�r�r;r;r<r�7s,��zGCSBackend._restore_depscCs|�|�}|��dSrI)r�rH)r7rAr�r;r;r<r�Os
zGCSBackend._delete_chord_keycCs4t��t|d�}|�|�}|j|j|idd�dS)z�Set TTL policy for a Firestore document.

        Firestore ttl data is typically deleted within 24 hours after its
        expiration date.
        rBT)r�N)rrDrr�rFrr)r7rA�expiresZval_expiresr�r;r;r<rzSs
zGCSBackend._expire_chord_keycCs|j�|j��t|��SrI)roZ
collectionrn�documentr)r7rAr;r;r<r�]s
��zGCSBackend._firestore_document)rdrerfrgZimplements_incrZsupports_native_joinrnr�rrr#rhrormr{�bytesr2r�r�r�r�rzr�rir;r;r9r<r�s"
A
r)0rg�concurrent.futuresrrr�osr�	threadingrZkombu.utils.encodingrZkombu.utils.functionalrZkombu.utils.urlr	Z
celery.canvasr
Zcelery.exceptionsrrZ
celery.resultr
rZcelery.utils.logr�baserrTZgoogle.api_corerZgoogle.api_core.exceptionsrZgoogle.api_core.retryrZgoogle.cloudrZgoogle.cloud.storagerZgoogle.cloud.storage.retryr�ImportErrorrr�__all__rdr�rrr;r;r;r<�<module>s>

v

Yohohohohohooho | Sanrei Aya