
    `f                        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mZmZ d	d
lmZmZ d	dlmZmZ d	dlmZ d	dlmZmZmZ d	dlmZmZ 	 ddl Z n# e!$ r dZ Y nw xY wdZ"dZ#d Z$ed             Z%ed             Z& G d d          Z'ej(         G d de'                      Z)ej(         G d de'                      Z*ej(         G d de*                      Z+ej(         G d de)                      Z,ddZ-dS ) z3Task results/state and results for groups of tasks.    N)deque)contextmanager)proxy)isoparse)cached_property)Thenablebarrierpromise   )current_appstates)_set_task_join_will_blocktask_join_will_block)app_or_default)ImproperlyConfiguredIncompleteStreamTimeoutError)DependencyGraphGraphFormatter)
ResultBaseAsyncResult	ResultSetGroupResultEagerResultresult_from_tuplezNever call result.get() within a task!
See https://docs.celeryq.dev/en/latest/userguide/tasks.html#avoid-launching-synchronous-subtasks
c                  J    t                      rt          t                    d S N)r   RuntimeErrorE_WOULDBLOCK     ?/var/www/html/env/lib/python3.11/site-packages/celery/result.pyassert_will_not_blockr#   $   s(     )<((() )r!   c               #      K   t                      } t          d           	 d V  t          |            d S # t          |            w xY wNFr   r   reset_values    r"   allow_join_resultr)   )   sV      &((Ke$$$/!+.....!+....	   6 Ac               #      K   t                      } t          d           	 d V  t          |            d S # t          |            w xY wNTr&   r'   s    r"   denied_join_resultr-   3   sV      &((Kd###/!+.....!+....r*   c                       e Zd ZdZdZdS )r   zBase class for results.N)__name__
__module____qualname____doc__parentr    r!   r"   r   r   =   s        !! FFFr!   r   c                      e Zd ZdZdZeZdZdZ	 	 	 d8dZe	d             Z
e
j        d             Z
d9dZd Zd	 Zd
 Zd Z	 	 d:dZ	 	 d:dZdddddddddej        ej        fdZeZd Zd Zd;dZd Zd;dZd Zd Zd Zd Z d<dZ!e!Z"d Z#d=dZ$d Z%d Z&d Z'd  Z(d! Z)d" Z*d# Z+d$ Z,e-d%             Z.e	d&             Z/e	d'             Z0d( Z1d) Z2d* Z3d+ Z4e	d,             Z5e5Z6e	d-             Z7e	d.             Z8e8Z9e	d/             Z:e:j        d0             Z:e	d1             Z;e	d2             Z<e	d3             Z=e	d4             Z>e	d5             Z?e	d6             Z@e	d7             ZAdS )>r   zxQuery task state.

    Arguments:
        id (str): See :attr:`id`.
        backend (Backend): See :attr:`backend`.
    Nc                    |t          dt          |                     t          |p| j                  | _        || _        |p| j        j        | _        || _        t          | j        d          | _	        d | _
        d| _        d S )Nz#AsyncResult requires valid id, not TweakF)
ValueErrortyper   appidbackendr3   r
   _on_fulfilledon_ready_cache_ignored)selfr;   r<   	task_namer:   r3   s         r"   __init__zAsyncResult.__init__X   s     :@d2hh@@B B B!#/222$("2 2>>>r!   c                 4    t          | d          r| j        S dS )z+If True, task result retrieval is disabled.r@   F)hasattrr@   rA   s    r"   ignoredzAsyncResult.ignoredf   s#     4$$ 	!= ur!   c                     || _         dS )z%Enable/disable task result retrieval.N)r@   )rA   values     r"   rG   zAsyncResult.ignoredm   s     r!   Fc                 p    | j                             | |           | j                            ||          S )Nr6   )r<   add_pending_resultr>   thenrA   callbackon_errorr7   s       r"   rL   zAsyncResult.thenr   s5    ''4'888}!!(H555r!   c                 :    | j                             |            |S r   r<   remove_pending_resultrA   results     r"   r=   zAsyncResult._on_fulfilledv   s    **4000r!   c                 N    | j         }| j        |o|                                fd fS r   )r3   r;   as_tuple)rA   r3   s     r"   rV   zAsyncResult.as_tuplez   s*    5FOO$5$56<<r!   c                     g }| j         }|                    | j                   |'|                    |                                           |S )zReturn as a list of task IDs.)r3   appendr;   extendas_list)rA   resultsr3   s      r"   rZ   zAsyncResult.as_list~   sI    twNN6>>++,,,r!   c                     d| _         | j        r| j                                         | j                            | j                   dS )z/Forget the result of this task and its parents.N)r?   r3   forgetr<   r;   rF   s    r"   r]   zAsyncResult.forget   sE    ; 	!K   DG$$$$$r!   c                 Z    | j         j                            | j        |||||           dS )a  Send revoke signal to all workers.

        Any worker receiving the task, or having reserved the
        task, *must* ignore it.

        Arguments:
            terminate (bool): Also terminate the process currently working
                on the task (if any).
            signal (str): Name of signal to send to process if terminate.
                Default is TERM.
            wait (bool): Wait for replies from workers.
                The ``timeout`` argument specifies the seconds to wait.
                Disabled by default.
            timeout (float): Time in seconds to wait for replies when
                ``wait`` is enabled.
        
connection	terminatesignalreplytimeoutN)r:   controlrevoker;   rA   r`   ra   rb   waitrd   s         r"   rf   zAsyncResult.revoke   s@    $ 	J*3F&*G 	  	= 	= 	= 	= 	=r!   c                 P    | j         j                            ||||||           dS )a7  Send revoke signal to all workers only for tasks with matching headers values.

        Any worker receiving the task, or having reserved the
        task, *must* ignore it.
        All header fields *must* match.

        Arguments:
            headers (dict[str, Union(str, list)]): Headers to match when revoking tasks.
            terminate (bool): Also terminate the process currently working
                on the task (if any).
            signal (str): Name of signal to send to process if terminate.
                Default is TERM.
            wait (bool): Wait for replies from workers.
                The ``timeout`` argument specifies the seconds to wait.
                Disabled by default.
            timeout (float): Time in seconds to wait for replies when
                ``wait`` is enabled.
        r_   N)r:   re   revoke_by_stamped_headers)rA   headersr`   ra   rb   rh   rd   s          r"   rj   z%AsyncResult.revoke_by_stamped_headers   sC    ( 	227z=Fv9=w 	3 	P 	P 	P 	P 	Pr!   T      ?c           
         | j         rdS |	rt                       t                      }|r3|r1| j        r*t          | j        d          }|                                  |r|                    |           | j        r|r|                     |           | j        S | j	        
                    |            | j	                            | |||||||          S )a  Wait until task is ready, and return its result.

        Warning:
           Waiting for tasks within a task may lead to deadlocks.
           Please read :ref:`task-synchronous-subtasks`.

        Warning:
           Backends use resources to store and transmit results. To ensure
           that resources are released, you must eventually call
           :meth:`~@AsyncResult.get` or :meth:`~@AsyncResult.forget` on
           EVERY :class:`~@AsyncResult` instance returned after calling
           a task.

        Arguments:
            timeout (float): How long to wait, in seconds, before the
                operation times out. This is the setting for the publisher
                (celery client) and is different from `timeout` parameter of
                `@app.task`, which is the setting for the worker. The task
                isn't terminated even if timeout occurs.
            propagate (bool): Re-raise exception if the task failed.
            interval (float): Time to wait (in seconds) before retrying to
                retrieve the result.  Note that this does not have any effect
                when using the RPC/redis result store backends, as they don't
                use polling.
            no_ack (bool): Enable amqp no ack (automatically acknowledge
                message).  If this is :const:`False` then the message will
                **not be acked**.
            follow_parents (bool): Re-raise any exception raised by
                parent tasks.
            disable_sync_subtasks (bool): Disable tasks to wait for sub tasks
                this is the default configuration. CAUTION do not enable this
                unless you must.

        Raises:
            celery.exceptions.TimeoutError: if `timeout` isn't
                :const:`None` and the result does not arrive within
                `timeout` seconds.
            Exception: If the remote call raised an exception then that
                exception will be re-raised in the caller process.
        NTr6   )rN   )rd   intervalon_intervalno_ack	propagaterN   
on_message)rG   r#   r
   r3   _maybe_reraise_parent_errorrL   r?   maybe_throwrT   r<   rK   wait_for_pending)rA   rd   rq   rn   rp   follow_parentsrN   rr   ro   disable_sync_subtasksEXCEPTION_STATESPROPAGATE_STATES_on_intervals                r"   getzAsyncResult.get   s	   Z < 	F  	$!###yy 	/i 	/DK 	/"4#C$OOOL,,... 	+k***; 	 4  ( 333;''---|,,'$! - 
 
 	
r!   c                     t          t          |                                                     D ]}|                                 d S r   )reversedlist_parentsrt   rA   nodes     r"   rs   z'AsyncResult._maybe_reraise_parent_error  sH    T$--//2233 	 	D	 	r!   c              #   :   K   | j         }|r|V  |j         }|d S d S r   r3   r   s     r"   r   zAsyncResult._parents
  sC      { 	JJJ;D  	 	 	 	 	r!   c              +   d   K   |                      |          D ]\  }}| |j        di |fV  dS )a  Collect results as they return.

        Iterator, like :meth:`get` will wait for the task to complete,
        but will also follow :class:`AsyncResult` and :class:`ResultSet`
        returned by the task, yielding ``(result, value)`` tuples for each
        result in the tree.

        An example would be having the following tasks:

        .. code-block:: python

            from celery import group
            from proj.celery import app

            @app.task(trail=True)
            def A(how_many):
                return group(B.s(i) for i in range(how_many))()

            @app.task(trail=True)
            def B(i):
                return pow2.delay(i)

            @app.task(trail=True)
            def pow2(i):
                return i ** 2

        .. code-block:: pycon

            >>> from celery.result import ResultBase
            >>> from proj.tasks import A

            >>> result = A.delay(10)
            >>> [v for v in result.collect()
            ...  if not isinstance(v, (ResultBase, tuple))]
            [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

        Note:
            The ``Task.trail`` option must be enabled
            so that the list of children is stored in ``result.children``.
            This is the default but enabled explicitly for illustration.

        Yields:
            Tuple[AsyncResult, Any]: tuples containing the result instance
            of the child task, and the return value of that task.
        intermediateNr    iterdepsr{   )rA   r   kwargs_Rs        r"   collectzAsyncResult.collect  sV      \ MM|M<< 	% 	%DAqUQU__V__$$$$$	% 	%r!   c                 f    d }|                                  D ]\  }}|                                }|S r   r   )rA   rI   r   r   s       r"   get_leafzAsyncResult.get_leafA  s6    MMOO 	 	DAqEEGGEEr!   c              #     K   t          d | fg          }| }|rn|                                \  }|fV                                  r)|                    fdj        pg D                        n|rt                      |ld S d S )Nc              3       K   | ]}|fV  	d S r   r    ).0childr   s     r"   	<genexpr>z'AsyncResult.iterdeps.<locals>.<genexpr>P  s'      LLudE]LLLLLLr!   )r   popleftreadyrY   childrenr   )rA   r   stackis_incomplete_streamr3   r   s        @r"   r   zAsyncResult.iterdepsG  s      d|n%%#// 	- ==??LFD$,zz|| -LLLL8KLLLLLLL' -*,,,  	- 	- 	- 	- 	-r!   c                 (    | j         | j        j        v S )zReturn :const:`True` if the task has executed.

        If the task is still running, pending, or is waiting
        for retry then :const:`False` is returned.
        )stater<   READY_STATESrF   s    r"   r   zAsyncResult.readyU  s     zT\666r!   c                 ,    | j         t          j        k    S )z7Return :const:`True` if the task executed successfully.)r   r   SUCCESSrF   s    r"   
successfulzAsyncResult.successful]      zV^++r!   c                 ,    | j         t          j        k    S )z(Return :const:`True` if the task failed.)r   r   FAILURErF   s    r"   failedzAsyncResult.faileda  r   r!   c                 *     | j         j        |i | d S r   )r>   throwrA   argsr   s      r"   r   zAsyncResult.throwe  s"    T,V,,,,,r!   c                 ,   | j         |                                 n| j         }|d         |d         |                    d          }}}|t          j        v r+|r)|                     ||                     |                     | || j        |           |S )NstatusrT   	traceback)r?   _get_task_metar{   r   ry   r   _to_remote_tracebackr;   )rA   rq   rN   cacher   rI   tbs          r"   rt   zAsyncResult.maybe_throwh  s    )-)<##%%%$+(OU8_eii.D.D uF+++	+JJud77;;<<<HTWe$$$r!   c                     |rIt           D| j        j        j        r5t           j                            |                                          S d S d S d S r   )tblibr:   conftask_remote_tracebacks	Tracebackfrom_stringas_traceback)rA   r   s     r"   r   z AsyncResult._to_remote_tracebacks  sV     	B%#(L#?..r22??AAA	B 	B####r!   c                     t          |pt          | j        d                    }|                     |          D ]2\  }}|                    |           |r|                    ||           3|S )Noval)rootshape)	formatterr   )r   r   r;   r   add_arcadd_edge)rA   r   r   graphr3   r   s         r"   build_graphzAsyncResult.build_graphw  s    M>twf#M#M#M
 
 
 !MM|MDD 	- 	-LFDMM$ -vt,,,r!   c                 *    t          | j                  S z`str(self) -> self.id`.strr;   rF   s    r"   __str__zAsyncResult.__str__      47||r!   c                 *    t          | j                  S z`hash(self) -> hash(self.id)`.hashr;   rF   s    r"   __hash__zAsyncResult.__hash__      DG}}r!   c                 B    dt          |           j         d| j         dS )N<: >)r9   r/   r;   rF   s    r"   __repr__zAsyncResult.__repr__  s&    44::&44$'4444r!   c                     t          |t                    r|j        | j        k    S t          |t                    r|| j        k    S t          S r   )
isinstancer   r;   r   NotImplementedrA   others     r"   __eq__zAsyncResult.__eq__  sH    e[)) 	$8tw&&s## 	$DG##r!   c                 \    |                      | j        | j        d | j        | j                  S r   )	__class__r;   r<   r:   r3   rF   s    r"   __copy__zAsyncResult.__copy__  s+    ~~GT\44;
 
 	
r!   c                 8    | j         |                                 fS r   r   __reduce_args__rF   s    r"   
__reduce__zAsyncResult.__reduce__      ~t335555r!   c                 .    | j         | j        d d | j        fS r   )r;   r<   r3   rF   s    r"   r   zAsyncResult.__reduce_args__  s    wdD$+==r!   c                 L    | j         | j                             |            dS dS )z9Cancel pending operations when the instance is destroyed.NrQ   rF   s    r"   __del__zAsyncResult.__del__  s.    <#L..t44444 $#r!   c                 *    |                                  S r   )r   rF   s    r"   r   zAsyncResult.graph  s    !!!r!   c                     | j         j        S r   )r<   supports_native_joinrF   s    r"   r   z AsyncResult.supports_native_join  s    |00r!   c                 P    |                                                      d          S )Nr   r   r{   rF   s    r"   r   zAsyncResult.children  s"    ""$$((444r!   c                     |rZ|d         }|t           j        v rD|                     | j                            |                    }|                     |            |S |S )Nr   )r   r   
_set_cacher<   meta_from_decodedr>   )rA   metar   ds       r"   _maybe_set_cachezAsyncResult._maybe_set_cache  s^     	NE+++OODL$B$B4$H$HIId###r!   c                     | j         2|                     | j                            | j                            S | j         S r   )r?   r   r<   get_task_metar;   rF   s    r"   r   zAsyncResult._get_task_meta  s8    ;(()C)CDG)L)LMMM{r!   c                 F    t          |                                 g          S r   )iterr   rA   r   s     r"   
_iter_metazAsyncResult._iter_meta  s    T((**+,,,r!   c                 f     |                     d          }|r fd|D             |d<   | _        |S )Nr   c                 :    g | ]}t          |j                  S r    )r   r:   )r   r   rA   s     r"   
<listcomp>z*AsyncResult._set_cache.<locals>.<listcomp>  s3       7<!%22  r!   )r{   r?   )rA   r   r   s   `  r"   r   zAsyncResult._set_cache  sV    55$$ 	   @H  AjM r!   c                 6    |                                  d         S )zTask return value.

        Note:
            When the task has been executed, this contains the return value.
            If the task raised an exception, this will be the exception
            instance.
        rT   r   rF   s    r"   rT   zAsyncResult.result  s     ""$$X..r!   c                 P    |                                                      d          S )z#Get the traceback of a failed task.r   r   rF   s    r"   r   zAsyncResult.traceback  s$     ""$$((555r!   c                 6    |                                  d         S )a  The tasks current state.

        Possible values includes:

            *PENDING*

                The task is waiting for execution.

            *STARTED*

                The task has been started.

            *RETRY*

                The task is to be retried, possibly because of failure.

            *FAILURE*

                The task raised an exception, or has exceeded the retry limit.
                The :attr:`result` attribute then contains the
                exception raised by the task.

            *SUCCESS*

                The task executed successfully.  The :attr:`result` attribute
                then contains the tasks return value.
        r   r   rF   s    r"   r   zAsyncResult.state  s    : ""$$X..r!   c                     | j         S )zCompat. alias to :attr:`id`.r;   rF   s    r"   task_idzAsyncResult.task_id  s     wr!   c                     || _         d S r   r   )rA   r;   s     r"   r   zAsyncResult.task_id  s    r!   c                 P    |                                                      d          S )Nnamer   rF   s    r"   r   zAsyncResult.name  "    ""$$((000r!   c                 P    |                                                      d          S )Nr   r   rF   s    r"   r   zAsyncResult.args  r   r!   c                 P    |                                                      d          S )Nr   r   rF   s    r"   r   zAsyncResult.kwargs  "    ""$$((222r!   c                 P    |                                                      d          S )Nworkerr   rF   s    r"   r  zAsyncResult.worker  r  r!   c                     |                                                      d          }|r)t          |t          j                  st	          |          S |S )zUTC date and time.	date_done)r   r{   r   datetimer   )rA   r  s     r"   r  zAsyncResult.date_done  sS     ''))--k::	 	'Z	83DEE 	'I&&&r!   c                 P    |                                                      d          S )Nretriesr   rF   s    r"   r  zAsyncResult.retries  s"    ""$$((333r!   c                 P    |                                                      d          S )Nqueuer   rF   s    r"   r
  zAsyncResult.queue  s"    ""$$((111r!   )NNNNr%   NFNFN)F)TN)FN)Br/   r0   r1   r2   r:   r   r;   r<   rC   propertyrG   setterrL   r=   rV   rZ   r]   rf   rj   r   rx   ry   r{   rh   rs   r   r   r   r   r   r   r   r   rt   maybe_reraiser   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rT   infor   r   r   r   r   r   r   r  r  r  r
  r    r!   r"   r   r   D   s         C  L 
B G#'"&      X ^  ^6 6 6 6  = = =  % % % ?C#'= = = =, [_6:P P P P0 $tD#4#4	G
 G
 G
 G
P D    /% /% /% /%b  - - - -7 7 7, , ,, , ,- - -     MB B B       5 5 5  
 
 

6 6 6> > >5 5 5
 " " _" 1 1 X1 5 5 X5    
- - -   / / X/ D6 6 X6 / / X/: F  X ^  ^ 1 1 X1 1 1 X1 3 3 X3 3 3 X3   X 4 4 X4 2 2 X2 2 2r!   r   c                   N   e Zd ZdZdZdZd%dZd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd&dZeZd Zd Zd Zd Z	 	 d'dZd Zd Z	 	 	 d(dZ	 	 	 d(dZd)dZ	 	 d*dZ	 	 	 	 d+dZd Zd Zd Zd Z d  Z!e"d!             Z#e"d"             Z$e$j%        d#             Z$e"d$             Z&dS ),r   zpA collection of results.

    Arguments:
        results (Sequence[AsyncResult]): List of result instances.
    Nc                    || _         || _        t          t          |           f          | _        |pt          |          | _        | j        r0| j                            t          | j        d                     d S d S )N)r   Tr6   )	_appr[   r
   r   r>   r	   _on_fullrL   	_on_ready)rA   r[   r:   ready_barrierr   s        r"   rC   zResultSet.__init__1  s    	eDkk^444%9)9)9= 	CMwt~DAAABBBBB	C 	Cr!   c                     || j         vr=| j                             |           | j        r| j                            |           dS dS dS )zvAdd :class:`AsyncResult` as a new member of the set.

        Does nothing if the result is already a member.
        N)r[   rX   r  addrS   s     r"   r  zResultSet.add9  s_    
 %%L'''} *!!&))))) &%* *r!   c                 J    | j         j        r|                                  d S d S r   )r<   is_asyncr>   rF   s    r"   r  zResultSet._on_readyC  s*    <  	MMOOOOO	 	r!   c                     t          |t                    r| j                            |          }	 | j                            |           dS # t          $ r t          |          w xY w)z~Remove result from the set; it must be a member.

        Raises:
            KeyError: if the result isn't a member.
        N)r   r   r:   r   r[   remover8   KeyErrorrS   s     r"   r  zResultSet.removeG  su     fc"" 	2X))&11F	#L''''' 	# 	# 	#6"""	#s   A A'c                 T    	 |                      |           dS # t          $ r Y dS w xY w)zbRemove result from the set if it is a member.

        Does nothing if it's not a member.
        N)r  r  rS   s     r"   discardzResultSet.discardT  sA    
	KK 	 	 	DD	s    
''c                 T      j                              fd|D                        dS )z Extend from iterable of results.c              3   .   K   | ]}|j         v|V  d S r   r[   )r   rrA   s     r"   r   z#ResultSet.update.<locals>.<genexpr>`  s/      HH!!4<2G2GA2G2G2G2GHHr!   N)r[   rY   )rA   r[   s   ` r"   updatezResultSet.update^  s4    HHHHwHHHHHHHHr!   c                     g | j         dd<   dS )z!Remove all results from this set.Nr!  rF   s    r"   clearzResultSet.clearb  s    QQQr!   c                 >    t          d | j        D                       S )zReturn true if all tasks successful.

        Returns:
            bool: true if all of the tasks finished
                successfully (i.e. didn't raise an exception).
        c              3   >   K   | ]}|                                 V  d S r   )r   r   rT   s     r"   r   z'ResultSet.successful.<locals>.<genexpr>m  s.      BB66$$&&BBBBBBr!   allr[   rF   s    r"   r   zResultSet.successfulf  s#     BBT\BBBBBBr!   c                 >    t          d | j        D                       S )zReturn true if any of the tasks failed.

        Returns:
            bool: true if one of the tasks failed.
                (i.e., raised an exception)
        c              3   >   K   | ]}|                                 V  d S r   )r   r(  s     r"   r   z#ResultSet.failed.<locals>.<genexpr>v  s*      >>v6==??>>>>>>r!   anyr[   rF   s    r"   r   zResultSet.failedo  s#     >>>>>>>>r!   Tc                 H    | j         D ]}|                    ||           d S )N)rN   rq   )r[   rt   )rA   rN   rq   rT   s       r"   rt   zResultSet.maybe_throwx  s=    l 	G 	GFIFFFF	G 	Gr!   c                 >    t          d | j        D                       S )zReturn true if any of the tasks are incomplete.

        Returns:
            bool: true if one of the tasks are still
                waiting for execution.
        c              3   @   K   | ]}|                                  V  d S r   r   r(  s     r"   r   z$ResultSet.waiting.<locals>.<genexpr>  s-      AA&v||~~%AAAAAAr!   r-  rF   s    r"   waitingzResultSet.waiting}  s#     AADLAAAAAAr!   c                 >    t          d | j        D                       S )zDid all of the tasks complete? (either by success of failure).

        Returns:
            bool: true if all of the tasks have been executed.
        c              3   >   K   | ]}|                                 V  d S r   r2  r(  s     r"   r   z"ResultSet.ready.<locals>.<genexpr>  s*      ==f6<<>>======r!   r)  rF   s    r"   r   zResultSet.ready  s#     ========r!   c                 >    t          d | j        D                       S )a  Task completion count.

        Note that `complete` means `successful` in this context. In other words, the
        return value of this method is the number of ``successful`` tasks.

        Returns:
            int: the number of complete (i.e. successful) tasks.
        c              3   X   K   | ]%}t          |                                          V  &d S r   )intr   r(  s     r"   r   z,ResultSet.completed_count.<locals>.<genexpr>  s6      GG3v((**++GGGGGGr!   )sumr[   rF   s    r"   completed_countzResultSet.completed_count  s#     GG$,GGGGGGr!   c                 B    | j         D ]}|                                 dS )z?Forget about (and possible remove the result of) all the tasks.N)r[   r]   rS   s     r"   r]   zResultSet.forget  s,    l 	 	FMMOOOO	 	r!   Fc                 n    | j         j                            d | j        D             |||||           dS )a[  Send revoke signal to all workers for all tasks in the set.

        Arguments:
            terminate (bool): Also terminate the process currently working
                on the task (if any).
            signal (str): Name of signal to send to process if terminate.
                Default is TERM.
            wait (bool): Wait for replies from worker.
                The ``timeout`` argument specifies the number of seconds
                to wait.  Disabled by default.
            timeout (float): Time in seconds to wait for replies when
                the ``wait`` argument is enabled.
        c                     g | ]	}|j         
S r    r   r   r"  s     r"   r   z$ResultSet.revoke.<locals>.<listcomp>  s     < < <! < < <r!   )r`   rd   ra   rb   rc   N)r:   re   rf   r[   rg   s         r"   rf   zResultSet.revoke  sT     	 < <t| < < <+5w*3F$ 	  	P 	P 	P 	P 	Pr!   c                 *    t          | j                  S r   )r   r[   rF   s    r"   __iter__zResultSet.__iter__  s    DL!!!r!   c                     | j         |         S )z`res[i] -> res.results[i]`.r!  )rA   indexs     r"   __getitem__zResultSet.__getitem__  s    |E""r!   rl   c	           
      N     | j         r| j        n| j        ||||||||          S )zSee :meth:`join`.

        This is here for API compatibility with :class:`AsyncResult`,
        in addition it uses :meth:`join_native` if available for the
        current result backend.
        )rd   rq   rn   rN   rp   rr   rw   ro   )r   join_nativejoin)	rA   rd   rq   rn   rN   rp   rr   rw   ro   s	            r"   r{   zResultSet.get  sE     MD$=L  49y!9N#	
 
 
 	
r!   c	           	      v   |rt                       t          j                    }	d}
|t          d          g }| j        D ]x}d}
|r.|t          j                    |	z
  z
  }
|
dk    rt          d          |                    |
|||||          }|r ||j        |           c|                    |           y|S )a  Gather the results of all tasks as a list in order.

        Note:
            This can be an expensive operation for result store
            backends that must resort to polling (e.g., database).

            You should consider using :meth:`join_native` if your backend
            supports it.

        Warning:
            Waiting for tasks within a task may lead to deadlocks.
            Please see :ref:`task-synchronous-subtasks`.

        Arguments:
            timeout (float): The number of seconds to wait for results
                before the operation times out.
            propagate (bool): If any of the tasks raises an exception,
                the exception will be re-raised when this flag is set.
            interval (float): Time to wait (in seconds) before retrying to
                retrieve a result from the set.  Note that this does not have
                any effect when using the amqp result store backend,
                as it does not use polling.
            callback (Callable): Optional callback to be called for every
                result received.  Must have signature ``(task_id, value)``
                No results will be returned by this function if a callback
                is specified.  The order of results is also arbitrary when a
                callback is used.  To get access to the result object for
                a particular id you'll have to generate an index first:
                ``index = {r.id: r for r in gres.results.values()}``
                Or you can create new result objects on the fly:
                ``result = app.AsyncResult(task_id)`` (both will
                take advantage of the backend cache anyway).
            no_ack (bool): Automatic message acknowledgment (Note that if this
                is set to :const:`False` then the messages
                *will not be acknowledged*).
            disable_sync_subtasks (bool): Disable tasks to wait for sub tasks
                this is the default configuration. CAUTION do not enable this
                unless you must.

        Raises:
            celery.exceptions.TimeoutError: if ``timeout`` isn't
                :const:`None` and the operation takes longer than ``timeout``
                seconds.
        Nz,Backend does not support on_message callbackg        zjoin operation timed out)rd   rq   rn   rp   ro   rw   )	r#   time	monotonicr   r[   r   r{   r;   rX   )rA   rd   rq   rn   rN   rp   rr   rw   ro   
time_start	remainingr[   rT   rI   s                 r"   rF  zResultSet.join  s   ^ ! 	$!###^%%
	!&>@ @ @ l 	& 	&FI C#t~'7'7*'DE	##&'ABBBJJ!Y!&k&;   E
  &E****u%%%%r!   c                 8    | j                             ||          S r   r>   rL   rM   s       r"   rL   zResultSet.then      }!!(H555r!   c                 B    | j                             | |||||          S )a0  Backend optimized version of :meth:`iterate`.

        .. versionadded:: 2.2

        Note that this does not support collecting the results
        for different task types using different backends.

        This is currently only supported by the amqp, Redis and cache
        result backends.
        )rd   rn   rp   rr   ro   )r<   iter_native)rA   rd   rn   rp   rr   ro   s         r"   rP  zResultSet.iter_native  s2     |''hv!{ ( 
 
 	
r!   c	                    |rt                       |rdnd t          | j                  D             }	|rdn%d t          t	          |                     D             }
|                     |||||          D ]\  }}t          |t                    r/g }|D ])}|                    |	                                           *n |d         }|r|d         t          j        v r||r |||           x||
|	|         <   |
S )a-  Backend optimized version of :meth:`join`.

        .. versionadded:: 2.2

        Note that this does not support collecting the results
        for different task types using different backends.

        This is currently only supported by the amqp, Redis and cache
        result backends.
        Nc                 $    i | ]\  }}|j         |S r    r   )r   irT   s      r"   
<dictcomp>z)ResultSet.join_native.<locals>.<dictcomp>7  s-     -
 -
 -
&QFIq-
 -
 -
r!   c                     g | ]}d S r   r    )r   r   s     r"   r   z)ResultSet.join_native.<locals>.<listcomp>:  s    $D$D$DaT$D$D$Dr!   rT   r   )r#   	enumerater[   rangelenrP  r   r~   rX   r{   r   ry   )rA   rd   rq   rn   rN   rp   rr   ro   rw   order_indexaccr   r   rI   children_results                  r"   rE  zResultSet.join_native'  sR    ! 	$!###& 
dd -
 -
*3DL*A*A-
 -
 -
 Ddd$D$D5T3C3C$D$D$D!--gx.8+G G 	2 	2MGT$%%  '+ 8 8OLL!4!4!6!677778 X  h63J!J!JK 2%((((,1K())
r!   c                 ^    d  | j         j        d | j        D             fddi|D             S )Nc              3       K   | ]	\  }}|V  
d S r   r    )r   r   r   s      r"   r   z'ResultSet._iter_meta.<locals>.<genexpr>L  s6        D      r!   c                     h | ]	}|j         
S r    r   r>  s     r"   	<setcomp>z'ResultSet._iter_meta.<locals>.<setcomp>M  s    (((aQT(((r!   max_iterationsr   )r<   get_manyr[   r   s     r"   r   zResultSet._iter_metaK  s\     $9DL$9((4<(((%
 %
9:%
>D%
 %
    	r!   c                 $    d | j         D             S )Nc              3   ~   K   | ]8}|j                             |j                  r|j        t          j        v 4|V  9d S r   )r<   	is_cachedr;   r   r   ry   )r   ress     r"   r   z0ResultSet._failed_join_report.<locals>.<genexpr>Q  sW       6 6;((006	V444 44446 6r!   r!  rF   s    r"   _failed_join_reportzResultSet._failed_join_reportP  s$    6 6t| 6 6 6 	6r!   c                 *    t          | j                  S r   )rX  r[   rF   s    r"   __len__zResultSet.__len__U  s    4<   r!   c                 Z    t          |t                    r|j        | j        k    S t          S r   )r   r   r[   r   r   s     r"   r   zResultSet.__eq__X  s)    eY'' 	1=DL00r!   c                 |    dt          |           j         dd                    d | j        D                        dS )Nr   z: [, c              3   $   K   | ]}|j         V  d S r   r   r>  s     r"   r   z%ResultSet.__repr__.<locals>.<genexpr>^  s$      4P4PaQT4P4P4P4P4P4Pr!   ]>)r9   r/   rF  r[   rF   s    r"   r   zResultSet.__repr__]  sA    T4::&TT4994P4P4<4P4P4P+P+PTTTTr!   c                 J    	 | j         d         j        S # t          $ r Y d S w xY wNr   )r[   r   
IndexErrorrF   s    r"   r   zResultSet.supports_native_join`  s8    	<?77 	 	 	DD	s    
""c                     | j         1| j        r| j        d         j        nt          j                    | _         | j         S ro  )r  r[   r:   r   _get_current_objectrF   s    r"   r:   zResultSet.appg  s=    904 ;a,,$8:: Iyr!   c                     || _         d S r   )r  )rA   r:   s     r"   r:   zResultSet.appn  s    			r!   c                 L    | j         r| j         j        n| j        d         j        S ro  )r:   r<   r[   rF   s    r"   r<   zResultSet.backendr  s"    #'8Htxa1HHr!   NNr,   r  )NTrl   NTNTNr%   )Nrl   TNN)NTrl   NTNNT)'r/   r0   r1   r2   r  r[   rC   r  r  r  r  r#  r%  r   r   rt   r  r3  r   r:  r]   rf   r@  rC  r{   rF  rL   rP  rE  r   rf  rh  r   r   r  r   r:   r  r<   r    r!   r"   r   r   $  s         D GC C C C* * *  # # #  I I I  C C C? ? ?G G G G  MB B B> > >	H 	H 	H  
 ?C#'P P P P&" " "# # # :=3748
 
 
 
  ;>4859H H H HT6 6 6 6 >B15
 
 
 
$ 378<15*." " " "H  
6 6 6
! ! !  
U U U   X   X 	Z  Z I I XI I Ir!   r   c                        e Zd ZdZdZdZd fd	Z fdZddZddZ	d Z
d Zd	 ZeZd
 Zd Zd Zd Zd Zed             Zedd            Z xZS )r   az  Like :class:`ResultSet`, but with an associated id.

    This type is returned by :class:`~celery.group`.

    It enables inspection of the tasks state and return values as
    a single entity.

    Arguments:
        id (str): The id of the group.
        results (Sequence[AsyncResult]): List of result instances.
        parent (ResultBase): Parent result of this group.
    Nc                 X    || _         || _         t                      j        |fi | d S r   )r;   r3   superrC   )rA   r;   r[   r3   r   r   s        r"   rC   zGroupResult.__init__  s6    ++F+++++r!   c                 |    | j                             |            t                                                       d S r   )r<   rR   rx  r  )rA   r   s    r"   r  zGroupResult._on_ready  s5    **4000r!   c                 P    |p| j         j                            | j        |           S )zSave group-result for later retrieval using :meth:`restore`.

        Example:
            >>> def save_and_restore(result):
            ...     result.save()
            ...     result = GroupResult.restore(result.id)
        )r:   r<   
save_groupr;   rA   r<   s     r"   savezGroupResult.save  s&     +48+77FFFr!   c                 R    |p| j         j                            | j                   dS )z.Remove this result if it was previously saved.N)r:   r<   delete_groupr;   r|  s     r"   deletezGroupResult.delete  s(    		$DH$2247;;;;;r!   c                 8    | j         |                                 fS r   r   rF   s    r"   r   zGroupResult.__reduce__  r   r!   c                     | j         | j        fS r   )r;   r[   rF   s    r"   r   zGroupResult.__reduce_args__  s    w$$r!   c                 8    t          | j        p| j                  S r   )boolr;   r[   rF   s    r"   __bool__zGroupResult.__bool__  s    DG+t|,,,r!   c                     t          |t                    r0|j        | j        k    o|j        | j        k    o|j        | j        k    S t          |t
                    r|| j        k    S t          S r   )r   r   r;   r[   r3   r   r   r   s     r"   r   zGroupResult.__eq__  sn    e[)) 	$DG# ,-,+
 s## 	$DG##r!   c           	          dt          |           j         d| j         dd                    d | j        D                        dS )Nr   r   z [rk  c              3   $   K   | ]}|j         V  d S r   r   r>  s     r"   r   z'GroupResult.__repr__.<locals>.<genexpr>  s$      >Z>Zqt>Z>Z>Z>Z>Z>Zr!   rm  )r9   r/   r;   rF  r[   rF   s    r"   r   zGroupResult.__repr__  sK    ^4::&^^$'^^TYY>Z>ZT\>Z>Z>Z5Z5Z^^^^r!   c                 *    t          | j                  S r   r   rF   s    r"   r   zGroupResult.__str__  r   r!   c                 *    t          | j                  S r   r   rF   s    r"   r   zGroupResult.__hash__  r   r!   c                 r    | j         | j        o| j                                        fd | j        D             fS )Nc                 6    g | ]}|                                 S r    )rV   r>  s     r"   r   z(GroupResult.as_tuple.<locals>.<listcomp>  s     000aQZZ\\000r!   )r;   r3   rV   r[   rF   s    r"   rV   zGroupResult.as_tuple  s>    Wdk<dk&:&:&<&<=004<000
 	
r!   c                     | j         S r   r!  rF   s    r"   r   zGroupResult.children  s
    |r!   c                     |p't          | j        t                    s| j        nt          }|p|j        }|                    |          S )z&Restore previously saved group result.)r   r:   r  r   r<   restore_group)clsr;   r<   r:   s       r"   restorezGroupResult.restore  sM      
%cgx88ICGGk 	 (S[$$R(((r!   )NNNr   ru  )r/   r0   r1   r2   r;   r[   rC   r  r}  r  r   r   r  __nonzero__r   r   r   r   rV   r  r   classmethodr  __classcell__)r   s   @r"   r   r   w  sU         
B G, , , , , ,
    G G G G< < < <6 6 6% % %- - -K	 	 	_ _ _    
 
 
   X ) ) ) [) ) ) ) )r!   r   c                       e Zd ZdZddZddZd Zd Zd Zd	 Z	d
 Z
	 	 ddZeZd Zd Zd Zed             Zed             Zed             ZeZed             Zed             ZdS )r   z.Result that we know has already been executed.Nc                     || _         || _        || _        || _        || _        t                      | _        |                     |            d S r   )r;   _result_state
_traceback_namer
   r>   )rA   r;   	ret_valuer   r   r   s         r"   rC   zEagerResult.__init__  sJ      #
		dr!   Fc                 8    | j                             ||          S r   rM  rM   s       r"   rL   zEagerResult.then  rN  r!   c                     | j         S r   )r?   rF   s    r"   r   zEagerResult._get_task_meta  s
    {r!   c                 8    | j         |                                 fS r   r   rF   s    r"   r   zEagerResult.__reduce__  r   r!   c                 6    | j         | j        | j        | j        fS r   )r;   r  r  r  rF   s    r"   r   zEagerResult.__reduce_args__  s    t{DODDr!   c                 :    |                                  \  }} || S r   )r   )rA   r  r   s      r"   r   zEagerResult.__copy__  s!    OO%%	TsDzr!   c                     dS r,   r    rF   s    r"   r   zEagerResult.ready  s    tr!   Tc                     |rt                       |                                 r| j        S | j        t          j        v r>|r5t          | j        t                    r| j        nt          | j                  | j        S d S r   )r#   r   rT   r   r   ry   r   	Exception)rA   rd   rq   rw   r   s        r"   r{   zEagerResult.get  s      	$!###?? 	;Z6222 H%/K&, &, Hdkk1:4;1G1GH;	 32r!   c                     d S r   r    rF   s    r"   r]   zEagerResult.forget  s    r!   c                 (    t           j        | _        d S r   )r   REVOKEDr  r   s      r"   rf   zEagerResult.revoke
  s    nr!   c                     d| j          dS )Nz<EagerResult: r   r   rF   s    r"   r   zEagerResult.__repr__  s    *****r!   c                 D    | j         | j        | j        | j        | j        dS )N)r   rT   r   r   r   )r;   r  r  r  r  rF   s    r"   r?   zEagerResult._cache  s,     wlkJ
 
 	
r!   c                     | j         S )zThe tasks return value.)r  rF   s    r"   rT   zEagerResult.result  s     |r!   c                     | j         S )zThe tasks state.)r  rF   s    r"   r   zEagerResult.state  s     {r!   c                     | j         S )z!The traceback if the task failed.)r  rF   s    r"   r   zEagerResult.traceback%  s     r!   c                     dS r%   r    rF   s    r"   r   z EagerResult.supports_native_join*  s    ur!   ru  r%   )NTT)r/   r0   r1   r2   rC   rL   r   r   r   r   r   r{   rh   r]   rf   r   r  r?   rT   r   r   r   r   r    r!   r"   r   r     sl       88	 	 	 	6 6 6 6  6 6 6E E E     +/"&    D  % % %+ + + 
 
 X
   X   X F  X   X  r!   r   c                 <   t                    j        }t          | t                    so| \  }}t          |t          t
          f          r|n|df\  }}|rt          |          }|$                    |fd|D             |          S  |||          S | S )zDeserialize result from tuple.Nc                 0    g | ]}t          |          S r    )r   )r   r   r:   s     r"   r   z%result_from_tuple.<locals>.<listcomp>=  s$    FFFu&uc22FFFr!   r   )r   r   r   r   r~   tupler   r   )r"  r:   Resultre  nodesr;   r3   s    `     r"   r   r   /  s     

C_Fa$$ )
U&sT5M::KSSd
F 	4&vs33F??FFFFFFF #   
 vb((((Hr!   r   ).r2   r  rH  collectionsr   
contextlibr   weakrefr   dateutil.parserr   kombu.utils.objectsr   viner   r	   r
    r   r   r  r   r   r:   r   
exceptionsr   r   r   utils.graphr   r   r   ImportError__all__r   r#   r)   r-   r   registerr   r   r   r   r   r    r!   r"   <module>r     s   9 9         % % % % % %       $ $ $ $ $ $ / / / / / / + + + + + + + + + + ! ! ! ! ! ! ! ! C C C C C C C C       L L L L L L L L L L 8 8 8 8 8 8 8 8LLLL   EEE
) ) )
 / / / / / /        
\2 \2 \2 \2 \2* \2 \2 \2~ 
OI OI OI OI OI
 OI OI OId
 
\) \) \) \) \)) \) \) \)~ 
T T T T T+ T T Tn     s   A! !A+*A+