
    `f1                         d 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.    )	timedelta)cached_property)
_parse_url)ImproperlyConfigured   )KeyValueStoreBackend)
connection)AQLQueryErrorN)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                 J/var/www/html/env/lib/python3.11/site-packages/celery/backends/arangodb.pyr   zArangoDbBackend.__init__6   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.connectione   sE     #3>+dmt{     D r2   c                 &    | j         | j                 S )z&Database Object to the given database.)r	   r   r6   s    r1   dbzArangoDbBackend.dbo   s     t}--r2   c                 >    t          | j        dn| j                  S )Nr   )seconds)r   expiresr6   s    r1   expires_deltazArangoDbBackend.expires_deltat   s     dl&:MMMMr2   c                     |d S | j                             dd| j        |d          }t          |          dk    rt	          |          nd S )Nz(RETURN DOCUMENT(@@collection, @key).taskT@collectionkey
rawResultsbindVarsr   )r8   AQLQueryr   lennext)r)   r@   querys      r1   r"   zArangoDbBackend.getx   s`    ;4  6#  ! 
 
 "%jj1nntE{{{$6r2   c                 P    | j                             d| j        ||d           d S )Nz
            UPSERT {_key: @key}
            INSERT {_key: @key, task: @value}
            UPDATE {task: @value} IN @@collection
            )r?   r@   valuerC   r8   rD   r   )r)   r@   rI   s      r1   setzArangoDbBackend.set   sG      $  	 	
 	
 	
 	
 	
r2   c           	   #     K   |d S | j                             dd| j        t          |t                    r|nt	          |          d          }	 |E d {V  	 |                                 n# t          $ r Y d S w xY w0)Nz4FOR k IN @keys RETURN DOCUMENT(@@collection, k).taskT)r?   keysrA   )r8   rD   r   r#   list	nextBatchStopIteration)r)   rN   rG   s      r1   mgetzArangoDbBackend.mget   s      <F  B# *4 6 6FDJJ  ! 
 
	!!!!    		s   A/ /
A=<A=c                 V    |d S | j                             d| j        |d           d S )Nz#REMOVE {_key: @key} IN @@collectionr>   rJ   rK   )r)   r@   s     r1   deletezArangoDbBackend.delete   sJ    ;F1#  	 	
 	
 	
 	
 	
r2   c                     | j         sd S | j                                        | j        z
                                  }| j                            d| j        |d           d S )Nz
            FOR record IN @@collection
                FILTER record.task.date_done < @checkpoint
                REMOVE record IN @@collection
            )r?   
checkpointrJ   )r;   r    nowr<   	isoformatr8   rD   r   )r)   rV   s     r1   cleanupzArangoDbBackend.cleanup   sv    | 	Fhllnnt'99DDFF
  $(  	 
	
 
	
 
	
 
	
 
	
r2   )N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   strkey_tr   propertyr	   r8   r   r<   r"   rL   rR   rT   rY   __classcell__)r0   s   @r1   r   r      s        " DDHJHHMF E-  -  -  -  -  - ^     X  . . X. N N _N7 7 7
 
 
  $	
 	
 	

 
 
 
 
 
 
r2   r   )r]   datetimer   kombu.utils.objectsr   kombu.utils.urlr   celery.exceptionsr   baser   pyArangor	   r   pyArango.theExceptionsr
   ImportError__all__r    r2   r1   <module>rl      s   $ $       / / / / / / & & & & & & 2 2 2 2 2 2 & & & & & &0;;;;;;4444444 0 0 0+//===0 g
 g
 g
 g
 g
* g
 g
 g
 g
 g
s   / 	;;