
     h9                         d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ 	 dd	lmZ dd
lmZ n# e$ r dxZZY nw xY wdZ G d de          ZdS )zArangoDb result store backend.    N)	timedelta)cached_property)
_parse_url)ImproperlyConfigured   )KeyValueStoreBackend)
connection)AQLQueryError)ArangoDbBackendc                        e Zd ZdZdZdZdZdZdZdZ	dZ
dZeZd fd	Zed	             Zed
             Zed             Zd Zd Zd Zd Zd Z xZS )r   a  ArangoDb backend.

    Sample url
    "arangodb://username:password@host:port/database/collection"
    *arangodb_backend_settings* is where the settings are present
    (in the app.conf)
    Settings should contain the host, port, username, password, database name,
    collection name else the default will be chosen.
    Default database name and collection name is celery.

    Raises
    ------
    celery.exceptions.ImproperlyConfigured:
        if module :pypi:`pyArango` is not available.

    z	127.0.0.18529celeryNhttpFc                 (    t                      j        |i | t          t          d          || _        |dx}x}x}x}x}}	n6t          |          \  }
}}}}	}}|dx}}n|                    d          \  }}| j        j        	                    dd          }|%t          |t                    st          d          ni }|p|	                    d| j                  | _        t          |p|	                    d| j                            | _        |	                    d| j                  | _        |	                    d	| j                  | _        |p|	                    d
| j                  | _        |p|	                    d| j                  | _        |p|	                    d| j                  | _        |	p|	                    d| j                  | _        d                    | j        | j        | j                  | _        d| _        dS )z8Parse the url or load the settings from settings object.NzEYou need to install the pyArango library to use the ArangoDb backend./arangodb_backend_settingsz5ArangoDb backend settings should be grouped in a dicthostporthttp_protocolverifydatabase
collectionusernamepasswordz{http_protocol}://{host}:{port})r   r   r   )super__init__py_arango_connectionr   urlr   splitappconfget
isinstancedictr   intr   r   r   r   r   r   r   formatarangodb_url_connection)selfr   argskwargsr   r   r   r   r   r   _schemadatabase_collection_queryconfig	__class__s                 T/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/celery/backends/arangodb.pyr   zArangoDbBackend.__init__8   s&   $)&)))'&$  
 ;HLLDL4L(LZL(XX
 3tXx#V"*(,,::':'@'@'E'E$*""#>EEfd++ *K  
 F9FJJvty99	=

649 = =>>	#ZZ9KLLjj4;77 IFJJz4=$I$IC&**\4?CC 	 IFJJz4=$I$I IFJJz4=$I$I=DD,4949 E 
 
      c                     | j         1t          j        | j        | j        | j        | j                  | _         | j         S )zConnect to the arangodb server.N)	arangoURLr   r   r   )r(   r   
Connectionr'   r   r   r   r)   s    r1   r	   zArangoDbBackend.connectiong   sE     #3>+dmt{     D r2   c                 &    | j         | j                 S )z&Database Object to the given database.)r	   r   r6   s    r1   dbzArangoDbBackend.dbq   s     t}--r2   c                 ,    t          | j                  S )N)seconds)r   expiresr6   s    r1   expires_deltazArangoDbBackend.expires_deltav   s    ....r2   c                    	 t          j        d                    | j        |                     | j                            d                    | j        |                    }|j        d         d         }|d S t          j        |          S # t          $ r}t          j
        |           Y d }~d S d }~wt          $ r}t          j
        |           Y d }~d S d }~ww xY w)Nz*RETURN DOCUMENT("{collection}/{key}").task)r   keyresultr   )loggingdebugr&   r   r8   AQLQueryresponsejsondumpsr
   error	Exception)r)   r>   queryr?   aql_errerrs         r1   r"   zArangoDbBackend.getz   s   	M<CC#C D    
 G$$<CC#C D   E
 ^H-a0F~t:f%%% 	 	 	M'"""44444 	 	 	M#44444	s*   A7B ;B 
CB33C CCc                 v   	 t          j        d                    | j        ||                     | j                            d                    | j        ||                     dS # t          $ r}t          j        |           Y d}~dS d}~wt          $ r}t          j        |           Y d}~dS d}~ww xY w)z<Insert a doc with value into task attribute and _key as key.z:INSERT {{ task: {task}, _key: "{key}" }} INTO {collection})r   r>   taskN	r@   rA   r&   r   r8   rB   r
   rF   rG   )r)   r>   valuerI   rJ   s        r1   setzArangoDbBackend.set   s    	ML#Ce      GL#Ce         	# 	# 	#M'""""""""" 	 	 	M#	s$   A$A( (
B82BB8B33B8c                    	 t          j        |          }t          j        d                    | j        |                     | j                            d                    | j        |                    }g }	 |                    |j	        d                    |
                                 5# t          $ r d |D             }|cY S t          $ r1}t          j        |           d gt          |          z  cY d }~S d }~wt          $ r1}t          j        |           d gt          |          z  cY d }~S d }~ww xY w)Nzy
                FOR key in {keys}
                    RETURN DOCUMENT(CONCAT("{collection}/", key).task
                )r   keysTr?   c                 >    g | ]}||nt          j        |          S N)rD   rE   ).0r?   s     r1   
<listcomp>z(ArangoDbBackend.mget.<locals>.<listcomp>   s:        !.dj.@.@  r2   )rD   rE   r@   rA   r&   r   r8   rB   extendrC   	nextBatchStopIterationr
   rF   lenrG   )r)   rQ   	json_keysrH   resultsvaluesrI   rJ   s           r1   mgetzArangoDbBackend.mget   s   !	&
4((IM F#Y   	   G$$ F#Y   	 E G"u~h7888!!!"  	 	 	 %  F MMM 	& 	& 	&M'"""6CII%%%%%%% 	& 	& 	&M#6CII%%%%%%%	&s6   B.B0 0D=
	D=&C?9D=?D=&D82D=8D=c                 r   	 t          j        d                    || j                             | j                            d                    || j                             d S # t          $ r}t          j        |           Y d }~d S d }~wt          $ r}t          j        |           Y d }~d S d }~ww xY w)Nz*REMOVE {{ _key: "{key}" }} IN {collection})r>   r   rM   )r)   r>   rI   rJ   s       r1   deletezArangoDbBackend.delete   s    	M<CC D    
 G<CC D      
  	# 	# 	#M'""""""""" 	 	 	M#	s$   A"A& &
B60B

B6B11B6c                    | j                                         | j        z
                                  }	 d                    | j        |          }t          j        |           | j        	                    |           dS # t          $ r}t          j        |           Y d}~dS d}~wt          $ r}t          j        |           Y d}~dS d}~ww xY w)zDelete expired meta-data.zcFOR item IN {collection} FILTER item.task.date_done < "{remove_before}" REMOVE item IN {collection})r   remove_beforeN)r    nowr<   	isoformatr&   r   r@   rA   r8   rB   r
   rF   rG   )r)   ra   rH   rI   rJ   s        r1   cleanupzArangoDbBackend.cleanup   s    $*<<GGII	. f}fMM	 
 M%   GU##### 	# 	# 	#M'""""""""" 	 	 	M#	s$   A
B 
CB%%C2CCrS   )__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   strkey_tr   propertyr	   r8   r   r<   r"   rO   r]   r_   rd   __classcell__)r0   s   @r1   r   r      s        " DDHJHHMF E-  -  -  -  -  - ^     X  . . X. / / _/  .  ("& "& "&H  "      r2   r   )rh   rD   r@   datetimer   kombu.utils.objectsr   kombu.utils.urlr   celery.exceptionsr   baser   pyArangor	   r   pyArango.theExceptionsr
   ImportError__all__r    r2   r1   <module>rw      s   $ $         / / / / / / & & & & & & 2 2 2 2 2 2 & & & & & &0;;;;;;4444444 0 0 0+//===0 O O O O O* O O O O Os   7 	AA