
    (ph-                     ^    S SK r S SKJr  S SKJrJr  S SKJr   " S S5      rS
S\	S\4S	 jjr
g)    N)Optional)InvalidCacheBackendErrorcaches)Confc                       \ rS rSrSS\4S jjrS rS rS rS r	S	 r
S
 rS rS rS rS rS rS\4S jrS rS\S\S\4S jrS\4S jrS\S\\   4S jr\S 5       r\SS\4S jj5       rSrg)Broker	   Nlist_keyc                     U=(       d    [         R                  nU R                  U5      U l        Xl        U R                  5       U l        S U l        g N)r   CLUSTER_NAMEget_connection
connectionr
   	get_cachecache_info)selfr
   s     L/var/www/html/venv/lib/python3.13/site-packages/django_q/brokers/__init__.py__init__Broker.__init__
   s>    0t00--h7 ^^%

    c                 2    U R                   U R                  4$ r   )r
   r   r   s    r   __getstate__Broker.__getstate__   s    }}djj((r   c                     Uu  U l         U l        U R                  U R                   5      U l        U R	                  5       U l        g r   )r
   r   r   r   r   r   )r   states     r   __setstate__Broker.__setstate__   s4    $)!tz--dmm<^^%
r   c                     g)z=
Puts a task onto the queue
:type task: str
:return: task id
N )r   tasks     r   enqueueBroker.enqueue   s     	r   c                     g)zI
Gets a task from the queue
:return: tuple with task id and task message
Nr!   r   s    r   dequeueBroker.dequeue"       
 	r   c                     g)z+
:return: the amount of tasks in the queue
Nr!   r   s    r   
queue_sizeBroker.queue_size)        	r   c                     g)zA
:return: the number of tasks currently awaiting acknowledgement
Nr!   r   s    r   	lock_sizeBroker.lock_size/       r   c                     g)z#
Deletes the queue from the broker
Nr!   r   s    r   delete_queueBroker.delete_queue4   r,   r   c                     g)z
Purges the queue of any tasks
Nr!   r   s    r   purge_queueBroker.purge_queue:   r,   r   c                     g)zB
Deletes a task from the queue
:param task_id: the id of the task
Nr!   r   task_ids     r   deleteBroker.delete@   r(   r   c                     g)zg
Acknowledges completion of the task and removes it from the queue.
:param task_id: the id of the task
Nr!   r8   s     r   acknowledgeBroker.acknowledgeG   r(   r   c                     g)z/
Fails a task message
:param task_id:
:return:
Nr!   r8   s     r   failBroker.failN   r0   r   returnc                     g)z@
Checks whether the broker connection is available
:rtype: bool
Nr!   r   s    r   pingBroker.pingU   r(   r   c                     U R                   $ )z
Shows the broker type
)r   r   s    r   infoBroker.info\   s     zzr   keyvaluetimeoutc                 2   U R                   (       d  gU R                   R                  [        R                  / 5      nX;  a  UR	                  U5        U R                   R                  [        R                  U5        U R                   R                  XU5      $ )zd
Saves a cluster statistic to the cache provider
:type key: str
:type value: str
:type timeout: int
N)r   getr   Q_STATappendset)r   rI   rJ   rK   key_lists        r   set_statBroker.set_statb   sc     zz::>>$++r2OOC 

t{{H-zz~~c'22r   c                 \    U R                   (       d  gU R                   R                  U5      $ )zY
Gets a cluster statistic from the cache provider
:type key: str
:return: a cluster Stat
N)r   rM   )r   rI   s     r   get_statBroker.get_statq   s!     zzzz~~c""r   patternc                    U R                   (       d  gU R                   R                  [        R                  5      nU(       a  [	        U5      S:X  a  / $ / nU HI  nU R                   R                  U5      nU(       a  UR                  U5        M8  UR                  U5        MK     U R                   R                  [        R                  U5        U$ )zi
Returns a list of all cluster stats from the cache provider
:type pattern: str
:return: a list of Stats
Nr   )r   rM   r   rN   lenrO   removerP   )r   rW   rQ   statsrI   stats         r   	get_statsBroker.get_stats{   s     zz::>>$++.3x=A-IC::>>#&DT"$  	

t{{H-r   c                  R     [         [        R                     $ ! [         a     gf = f)z;
Gets the current cache provider
:return: a cache provider
N)r   r   CACHEr   r!   r   r   r   Broker.get_cache   s(    	$**%%' 		s    
&&c                     g)zc
Gets a connection to the broker
:param list_key: Optional queue name
:return: a broker connection
r   r!   r
   s    r   r   Broker.get_connection   s     r   )r   r   r   r
   r   )__name__
__module____qualname____firstlineno__strr   r   r   r#   r&   r*   r.   r2   r5   r:   r=   r@   boolrD   rG   intrR   rU   r   listr]   staticmethodr   r   __static_attributes__r!   r   r   r   r   	   s     )&

d 3C 3 3c 3#C # $ *     r   r   r
   rB   c                    U =(       d    [         R                  n [         R                  (       aI  [         R                  R                  SS5      u  p[        R
                  " U5      n[        X25      nU" U S9$ [         R                  (       a  SSKJ	n  UR                  U S9$ [        [         R                  [        5      (       a  SSKJn  UR                  U S9$ [         R                   (       a  SSKJn  UR!                  U S9$ [         R$                  (       a  SSKJn  UR)                  U S9$ SS	KJn	  U	R-                  U S9$ )
zu
Gets the configured broker type
:param list_key: optional queue name
:type list_key: str
:return: a broker instance
.   rc   r   )ironmq)aws_sqs)orm)mongo)redis_broker)r   r   BROKER_CLASSrsplit	importlibimport_modulegetattrIRON_MQdjango_q.brokersrr   IronMQBroker
isinstanceSQSdictrs   SqsORMrt   MONGOru   Mongorv   Redis)
r
   modulefuncmbrokerrr   rs   rt   ru   rv   s
             r   
get_brokerr      s     ,4,,H((//Q7##F+!x((	+""H"55	DHHd	#	#,{{H{--	(www))	*{{H{-- 	2!!8!44r   r   )ry   typingr   django.core.cacher   r   django_q.confr   r   ri   r   r!   r   r   <module>r      s1      > Y Yx&5 &5 &5r   