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

X>hy�@s�dZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZzDdd	l
Z
dd
lmZddlmZmZmZddlmZdd
lmZWn.ey�d	Z
ZZZZZZYn0dZdZdZe
e�ZGdd�de�Zd	S)z3The CosmosDB/SQL backend for Celery (experimental).�)�cached_property)�bytes_to_str)�
_parse_url)�ImproperlyConfigured)�
get_logger�)�KeyValueStoreBackendN)�DocumentClient)�ConnectionPolicy�ConsistencyLevel�
PartitionKind)�HTTPFailure)�RetryOptions)�CosmosDBSQLBackendi�i�cs�eZdZdZd�fdd�	Zedd��Zedd��Zd	d
�Z	dd�Z
ed
d��Zedd��Zdd�Z
edd��Zdd�Zdd�Zdd�Zdd�Z�ZS)rz CosmosDB/SQL backend for Celery.Nc
s�t�j|i|��tdur"td��|jj}	|�|�\|_|_|pF|	d|_	|pT|	d|_
ztt|ph|	d�|_
Wnty�td��Yn0|p�|	d|_|p�|	d|_dS)NzIYou need to install the pydocumentdb library to use the CosmosDB backend.Zcosmosdbsql_database_nameZcosmosdbsql_collection_nameZcosmosdbsql_consistency_levelz"Unknown CosmosDB consistency levelZcosmosdbsql_max_retry_attemptsZcosmosdbsql_max_retry_wait_time)�super�__init__�pydocumentdbrZapp�confr�	_endpoint�_key�_database_name�_collection_name�getattrr�_consistency_level�AttributeError�_max_retry_attempts�_max_retry_wait_time)
�self�urlZ
database_nameZcollection_name�consistency_levelZmax_retry_attemptsZmax_retry_wait_time�args�kwargsr��	__class__��E/usr/local/lib/python3.9/site-packages/celery/backends/cosmosdbsql.pyr!s6	����
��zCosmosDBSQLBackend.__init__cCsZt|�\}}}}}}}|r|s&td��|s.d}|dkr:dnd}|�d|�d|��}||fS)NzInvalid URLi��https�httpz://�:)rr)�clsr�_�host�port�password�schemeZendpointr$r$r%rMszCosmosDBSQLBackend._parse_urlcCsJt�}t|j|jd�|_t|jd|ji||jd�}|�|�|�	|�|S)z�Return the CosmosDB/SQL client.

        If this is the first call to the property, the client is created and
        the database and collection are initialized if they don't yet exist.

        )Zmax_retry_attempt_countZmax_wait_time_in_secondsZ	masterKey)�connection_policyr)
r
rrrr	rrr�_create_database_if_not_exists� _create_collection_if_not_exists)rr/�clientr$r$r%�_client[s��

zCosmosDBSQLBackend._clientc
CsXz|�d|ji�Wn0tyD}z|jtkr0�WYd}~nd}~00t�d|j�dS)N�idzCreated CosmosDB database %s)ZCreateDatabaserr
�status_code�ERROR_EXISTS�LOGGER�info�rr2�exr$r$r%r0ss
�z1CosmosDBSQLBackend._create_database_if_not_existsc
Cslz$|�|j|jdgtjd�d��Wn0tyT}z|jtkr@�WYd}~nd}~00t�	d|j
|j�dS)Nz/id)�paths�kind)r4�partitionKeyz!Created CosmosDB collection %s/%s)ZCreateCollection�_database_linkrrZHashr
r5r6r7r8rr9r$r$r%r1}s���
�z3CosmosDBSQLBackend._create_collection_if_not_existscCs
d|jS)Nzdbs/)r�rr$r$r%r>�sz!CosmosDBSQLBackend._database_linkcCs|jd|jS)Nz/colls/)r>rr?r$r$r%�_collection_link�sz#CosmosDBSQLBackend._collection_linkcCs|jd|S)Nz/docs/)r@�r�keyr$r$r%�_get_document_link�sz%CosmosDBSQLBackend._get_document_linkcCs|r|��rtd��d|iS)Nz(Key cannot be none, empty or whitespace.r=)�isspace�
ValueError)r)rBr$r$r%�_get_partition_key�sz%CosmosDBSQLBackend._get_partition_keyc
Cs|t|�}t�d|j|j|�z|j�|�|�|�|��}Wn2t	yl}z|j
tkrV�WYd}~dSd}~00|�d�SdS)zxRead the value stored at the given key.

        Args:
              key: The key for which to read the value.

        z"Getting CosmosDB document %s/%s/%sN�value)
rr7�debugrrr3ZReadDocumentrCrFr
r5�ERROR_NOT_FOUND�get)rrB�documentr:r$r$r%rJ�s
��
zCosmosDBSQLBackend.getcCs>t|�}t�d|j|j|�|j�|j||d�|�|��dS)z�Store a value for a given key.

        Args:
              key: The key at which to store the value.
              value: The value to store.

        z#Creating CosmosDB document %s/%s/%s)r4rGN)	rr7rHrrr3ZCreateDocumentr@rF)rrBrGr$r$r%�set�s
��zCosmosDBSQLBackend.setcs�fdd�|D�S)zqRead all the values for the provided keys.

        Args:
              keys: The list of keys to read.

        csg|]}��|��qSr$)rJ)�.0rBr?r$r%�
<listcomp>��z+CosmosDBSQLBackend.mget.<locals>.<listcomp>r$)r�keysr$r?r%�mget�szCosmosDBSQLBackend.mgetcCs:t|�}t�d|j|j|�|j�|�|�|�|��dS)zlDelete the value at a given key.

        Args:
              key: The key of the value to delete.

        z#Deleting CosmosDB document %s/%s/%sN)	rr7rHrrr3ZDeleteDocumentrCrFrAr$r$r%�delete�s
��zCosmosDBSQLBackend.delete)NNNNNN)�__name__�
__module__�__qualname__�__doc__r�classmethodrrr3r0r1r>r@rCrFrJrLrQrR�
__classcell__r$r$r"r%rs2�,






	r)rVZkombu.utilsrZkombu.utils.encodingrZkombu.utils.urlrZcelery.exceptionsrZcelery.utils.logr�baserrZpydocumentdb.document_clientr	Zpydocumentdb.documentsr
rrZpydocumentdb.errorsr
Zpydocumentdb.retry_optionsr�ImportError�__all__rIr6rSr7rr$r$r$r%�<module>s0���