
    >iɊ                        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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dZ dZ!d Z"ed        Z#ed        Z$ G d d      Z%ejL                   G d de%             Z'ejL                   G d de%             Z(ejL                   G d de(             Z)ejL                   G d de'             Z*ddZ+y# e$ r dZY w xY w)z3Task results/state and results for groups of tasks.    N)deque)contextmanager)proxy)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                  6    t               rt        t              y N)r   RuntimeErrorE_WOULDBLOCK     i/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/celery/result.pyassert_will_not_blockr"   #   s    <(( r    c               #   v   K   t               } t        d       	 d  t        |        y # t        |        w xY wwNFr   r   reset_values    r!   allow_join_resultr(   (   s/     &(Ke$/!+.!+.   9) 969c               #   v   K   t               } t        d       	 d  t        |        y # t        |        w xY wwNTr%   r&   s    r!   denied_join_resultr,   2   s/     &(Kd#/!+.!+.r)   c                       e Zd ZdZdZy)r   zBase class for results.N)__name__
__module____qualname____doc__parentr   r    r!   r   r   <   s    ! Fr    r   c                      e Zd ZdZdZeZdZdZ	 	 	 d7dZe	d        Z
e
j                  d        Z
d8dZd Zd Zd	 Zd
 Z	 	 d9dZ	 	 d9d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                  d/        Z:e	d0        Z;e	d1        Z<e	d2        Z=e	d3        Z>e	d4        Z?e	d5        Z@e	d6        ZAy)=r   zxQuery task state.

    Arguments:
        id (str): See :attr:`id`.
        backend (Backend): See :attr:`backend`.
    Nc                     |t        dt        |             t        |xs | j                        | _        || _        |xs | j                  j
                  | _        || _        t        | j                  d      | _	        d | _
        d| _        y )Nz#AsyncResult requires valid id, not TweakF)
ValueErrortyper   appidbackendr2   r	   _on_fulfilledon_ready_cache_ignored)selfr:   r;   	task_namer9   r2   s         r!   __init__zAsyncResult.__init__W   s     :5d2hZ@B B!#/22$(("2"2 2 2>r    c                 4    t        | d      r| j                  S y)z+If True, task result retrieval is disabled.r?   F)hasattrr?   r@   s    r!   ignoredzAsyncResult.ignorede   s     4$== r    c                     || _         y)z%Enable/disable task result retrieval.N)r?   )r@   values     r!   rF   zAsyncResult.ignoredl   s     r    c                 t    | j                   j                  | |       | j                  j                  ||      S )Nr5   )r;   add_pending_resultr=   thenr@   callbackon_errorr6   s       r!   rK   zAsyncResult.thenq   s0    ''4'8}}!!(H55r    c                 <    | j                   j                  |        |S r   r;   remove_pending_resultr@   results     r!   r<   zAsyncResult._on_fulfilledu   s    **40r    c                 ^    | j                   }| j                  |xr |j                         fd fS r   )r2   r:   as_tuple)r@   r2   s     r!   rU   zAsyncResult.as_tupley   s+    5FOO$56<<r    c                     g }| j                   }|j                  | j                         ||j                  |j	                                |S )zReturn as a list of task IDs.)r2   appendr:   extendas_list)r@   resultsr2   s      r!   rY   zAsyncResult.as_list}   s>    twwNN6>>+,r    c                     d| _         | j                  r| j                  j                          | j                  j                  | j                         y)z/Forget the result of this task and its parents.N)r>   r2   forgetr;   r:   rE   s    r!   r\   zAsyncResult.forget   s6    ;;KK DGG$r    c                 n    | j                   j                  j                  | j                  |||||       y)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)r9   controlrevoker:   )r@   r_   r`   ra   waitrc   s         r!   re   zAsyncResult.revoke   s3    $ 	J*3F&*G 	  	=r    c                 Z    | j                   j                  j                  ||||||       y)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)r9   rd   revoke_by_stamped_headers)r@   headersr_   r`   ra   rf   rc   s          r!   rh   z%AsyncResult.revoke_by_stamped_headers   s0    ( 	227z=Fv9=w 	3 	Pr    T      ?c           
         | j                   ry|	r
t                t               }|r5|r3| j                  r't        | j                  d      }| j	                          |r|j                  |       | j                  r |r| j                  |       | j                  S | j                  j                  |        | 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.
        NTr5   )rM   )rc   intervalon_intervalno_ack	propagaterM   
on_message)rF   r"   r	   r2   _maybe_reraise_parent_errorrK   r>   maybe_throwrS   r;   rJ   wait_for_pending)r@   rc   ro   rl   rn   follow_parentsrM   rp   rm   disable_sync_subtasksEXCEPTION_STATESPROPAGATE_STATES_on_intervals                r!   getzAsyncResult.get   s    Z << !#yiDKK"4#C#C$OL,,.k*;;  ( 3;;''-||,,'$! - 
 	
r    c                 r    t        t        | j                                     D ]  }|j                           y r   )reversedlist_parentsrr   r@   nodes     r!   rq   z'AsyncResult._maybe_reraise_parent_error  s-    T$--/23 	D	r    c              #   P   K   | j                   }|r| |j                   }|ry y wr   r2   r~   s     r!   r}   zAsyncResult._parents	  s%     {{J;;D s   !&&c              +   l   K   | j                  |      D ]  \  }}| |j                  di |f  yw)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   iterdepsry   )r@   r   kwargs_Rs        r!   collectzAsyncResult.collect  s>     \ MM|M< 	%DAqUQUU_V_$$	%s   24c                 Z    d }| j                         D ]  \  }}|j                         } |S r   r   )r@   rH   r   r   s       r!   get_leafzAsyncResult.get_leaf@  s0    MMO 	DAqEEGE	r    c              #      K   t        d | fg      }| }|rb|j                         \  }|f j                         r)|j                  fdj                  xs g D               n|r
t               |ray y w)Nc              3   &   K   | ]  }|f 
 y wr   r   ).0childr   s     r!   	<genexpr>z'AsyncResult.iterdeps.<locals>.<genexpr>O  s     LudE]Ls   )r   popleftreadyrX   childrenr   )r@   r   stackis_incomplete_streamr2   r   s        @r!   r   zAsyncResult.iterdepsF  sq     d|n%#// ==?LFD$,zz|L8KLL'*,, s   A4A:8A:c                 F    | 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_STATESrE   s    r!   r   zAsyncResult.readyT  s     zzT\\6666r    c                 <    | j                   t        j                  k(  S )z7Return :const:`True` if the task executed successfully.)r   r   SUCCESSrE   s    r!   
successfulzAsyncResult.successful\      zzV^^++r    c                 <    | j                   t        j                  k(  S )z(Return :const:`True` if the task failed.)r   r   FAILURErE   s    r!   failedzAsyncResult.failed`  r   r    c                 <     | j                   j                  |i | y r   )r=   throwr@   argsr   s      r!   r   zAsyncResult.throwd  s    T,V,r    c                     | j                   | j                         n| j                   }|d   |d   |j                  d      }}}|t        j                  v r#|r!| j                  || j                  |             | || j                  |       |S )NstatusrS   	traceback)r>   _get_task_metary   r   rw   r   _to_remote_tracebackr:   )r@   ro   rM   cacher   rH   tbs          r!   rr   zAsyncResult.maybe_throwg  s    )-)<##%$++(OU8_eii.D uF+++	JJud77;<TWWe$r    c                     |rUt         N| j                  j                  j                  r-t         j                  j                  |      j                         S y y y r   )tblibr9   conftask_remote_tracebacks	Tracebackfrom_stringas_traceback)r@   r   s     r!   r   z AsyncResult._to_remote_tracebackr  sC    %#(L(L??..r2??AA )M#2r    c                     t        |xs t        | j                  d            }| j                  |      D ]+  \  }}|j	                  |       |s|j                  ||       - |S )Noval)rootshape)	formatterr   )r   r   r:   r   add_arcadd_edge)r@   r   r   graphr2   r   s         r!   build_graphzAsyncResult.build_graphv  sc    M>twwf#M
 !MM|MD 	-LFDMM$vt,	- r    c                 ,    t        | j                        S z`str(self) -> self.id`.strr:   rE   s    r!   __str__zAsyncResult.__str__      477|r    c                 ,    t        | j                        S z`hash(self) -> hash(self.id)`.hashr:   rE   s    r!   __hash__zAsyncResult.__hash__      DGG}r    c                 N    dt        |       j                   d| j                   dS )N<: >)r8   r.   r:   rE   s    r!   __repr__zAsyncResult.__repr__  s&    4:&&'r$''!44r    c                     t        |t              r|j                  | j                  k(  S t        |t              r|| j                  k(  S t        S r   )
isinstancer   r:   r   NotImplementedr@   others     r!   __eq__zAsyncResult.__eq__  s>    e[)88tww&&s#DGG##r    c                 |    | j                  | j                  | j                  d | j                  | j                        S r   )	__class__r:   r;   r9   r2   rE   s    r!   __copy__zAsyncResult.__copy__  s.    ~~GGT\\44;;
 	
r    c                 :    | j                   | j                         fS r   r   __reduce_args__rE   s    r!   
__reduce__zAsyncResult.__reduce__      ~~t33555r    c                 L    | j                   | j                  d d | j                  fS r   )r:   r;   r2   rE   s    r!   r   zAsyncResult.__reduce_args__  s    wwdD$++==r    c                 T    | j                   | j                   j                  |        yy)z9Cancel pending operations when the instance is destroyed.NrP   rE   s    r!   __del__zAsyncResult.__del__  s#    <<#LL..t4 $r    c                 "    | j                         S r   )r   rE   s    r!   r   zAsyncResult.graph  s    !!r    c                 .    | j                   j                  S r   )r;   supports_native_joinrE   s    r!   r   z AsyncResult.supports_native_join  s    ||000r    c                 @    | j                         j                  d      S Nr   r   ry   rE   s    r!   r   zAsyncResult.children  s    ""$((44r    c                     |rT|d   }|t         j                  v r=| j                  | j                  j	                  |            }| j                  |        |S |S )Nr   )r   r   
_set_cacher;   meta_from_decodedr=   )r@   metar   ds       r!   _maybe_set_cachezAsyncResult._maybe_set_cache  sO    NE+++OODLL$B$B4$HId#r    c                     | j                   4| j                  | j                  j                  | j                              S | j                   S r   )r>   r   r;   get_task_metar:   rE   s    r!   r   zAsyncResult._get_task_meta  s:    ;;(()C)CDGG)LMM{{r    c                 6    t        | j                         g      S r   )iterr   )r@   r   s     r!   
_iter_metazAsyncResult._iter_meta  s    T((*+,,r    c                     |j                  d      }|r'|D cg c]  }t        || j                         c}|d<   || _        |S c c}w r   )ry   r   r9   r>   )r@   r   r   r   s       r!   r   zAsyncResult._set_cache  sK    55$@H7<!%2AjM 	s   Ac                 (    | j                         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.
        rS   r   rE   s    r!   rS   zAsyncResult.result  s     ""$X..r    c                 @    | j                         j                  d      S )z#Get the traceback of a failed task.r   r   rE   s    r!   r   zAsyncResult.traceback  s     ""$((55r    c                 (    | j                         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   rE   s    r!   r   zAsyncResult.state  s    : ""$X..r    c                     | j                   S )zCompat. alias to :attr:`id`.r:   rE   s    r!   task_idzAsyncResult.task_id  s     wwr    c                     || _         y r   r   )r@   r:   s     r!   r   zAsyncResult.task_id  s	    r    c                 @    | j                         j                  d      S )Nnamer   rE   s    r!   r   zAsyncResult.name      ""$((00r    c                 @    | j                         j                  d      S )Nr   r   rE   s    r!   r   zAsyncResult.args  r   r    c                 @    | j                         j                  d      S )Nr   r   rE   s    r!   r   zAsyncResult.kwargs
      ""$((22r    c                 @    | j                         j                  d      S )Nworkerr   rE   s    r!   r   zAsyncResult.worker  r   r    c                     | j                         j                  d      }|r9t        |t        j                        st        j                  j	                  |      S |S )zUTC date and time.	date_done)r   ry   r   datetimefromisoformat)r@   r  s     r!   r  zAsyncResult.date_done  sL     '')--k:	Z	83D3DE$$229==r    c                 @    | j                         j                  d      S )Nretriesr   rE   s    r!   r  zAsyncResult.retries  s    ""$((33r    c                 @    | j                         j                  d      S )Nqueuer   rE   s    r!   r  zAsyncResult.queue  s    ""$((11r    )NNNNr$   NFNFN)F)TN)FN)Br.   r/   r0   r1   r9   r   r:   r;   rB   propertyrF   setterrK   r<   rU   rY   r\   re   rh   r   rv   rw   ry   rf   rq   r}   r   r   r   r   r   r   r   rr   maybe_reraiser   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rS   infor   r   r   r   r   r   r   r   r  r  r  r   r    r!   r   r   C   s    C  L 
B G#'"&   ^^ 6=% ?C#'=, [_6:P0 $tD#44#44	G
P D/%b-7,,-  MB5

6>5
 " " 1 1 5 5
- / / D6 6 / /: F  ^^  1 1 1 1 3 3 3 3   4 4 2 2r    r   c                   >   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$jJ                  d         Z$e"d!        Z&y))r   zpA collection of results.

    Arguments:
        results (Sequence[AsyncResult]): List of result instances.
    Nc                     || _         || _        t        t        |       f      | _        |xs t        |      | _        | j                  r1| j                  j                  t        | j                  d             y y )N)r   Tr5   )	_apprZ   r	   r   r=   r   _on_fullrK   	_on_ready)r@   rZ   r9   ready_barrierr   s        r!   rB   zResultSet.__init__0  s\    	eDk^4%9)9==MMwt~~DAB r    c                     || j                   vrD| j                   j                  |       | j                  r| j                  j                  |       yyy)zvAdd :class:`AsyncResult` as a new member of the set.

        Does nothing if the result is already a member.
        N)rZ   rW   r  addrR   s     r!   r  zResultSet.add8  sE    
 %LL'}}!!&)  &r    c                 R    | j                   j                  r| j                          y y r   )r;   is_asyncr=   rE   s    r!   r  zResultSet._on_readyB  s    <<  MMO !r    c                     t        |t              r| j                  j                  |      }	 | j                  j                  |       y# 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   r9   r   rZ   remover7   KeyErrorrR   s     r!   r  zResultSet.removeF  sS     fc"XX))&1F	#LL' 	#6""	#s   A	 	Ac                 F    	 | j                  |       y# t        $ r Y y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  rR   s     r!   discardzResultSet.discardS  s%    
	KK 		s    	  c                 N      j                   j                   fd|D               y)z Extend from iterable of results.c              3   @   K   | ]  }|j                   vs|  y wr   rZ   )r   rr@   s     r!   r   z#ResultSet.update.<locals>.<genexpr>_  s     H!!4<<2GAHs   N)rZ   rX   )r@   rZ   s   ` r!   updatezResultSet.update]  s    HwHHr    c                 "    g | j                   dd y)z!Remove all results from this set.Nr  rE   s    r!   clearzResultSet.cleara  s    Q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   | ]  }|j                           y wr   )r   r   rS   s     r!   r   z'ResultSet.successful.<locals>.<genexpr>l  s     B66$$&B   allrZ   rE   s    r!   r   zResultSet.successfule  s     BT\\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   | ]  }|j                           y wr   )r   r%  s     r!   r   z#ResultSet.failed.<locals>.<genexpr>u  s     >v6==?>r&  anyrZ   rE   s    r!   r   zResultSet.failedn  s     >>>>r    c                 L    | j                   D ]  }|j                  ||        y )N)rM   ro   )rZ   rr   )r@   rM   ro   rS   s       r!   rr   zResultSet.maybe_throww  s*    ll 	GFIF	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   | ]  }|j                            y wr   r   r%  s     r!   r   z$ResultSet.waiting.<locals>.<genexpr>  s     A&v||~%As   r+  rE   s    r!   waitingzResultSet.waiting|  s     ADLL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   | ]  }|j                           y wr   r0  r%  s     r!   r   z"ResultSet.ready.<locals>.<genexpr>  s     =f6<<>=r&  r'  rE   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   N   K   | ]  }t        |j                                 y wr   )intr   r%  s     r!   r   z,ResultSet.completed_count.<locals>.<genexpr>  s     G3v((*+Gs   #%)sumrZ   rE   s    r!   completed_countzResultSet.completed_count  s     G$,,GGGr    c                 F    | j                   D ]  }|j                           y)z?Forget about (and possible remove the result of) all the tasks.N)rZ   r\   rR   s     r!   r\   zResultSet.forget  s    ll 	FMMO	r    c                     | j                   j                  j                  | j                  D cg c]  }|j                   c}|||||       yc c}w )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.
        )r_   rc   r`   ra   rb   N)r9   rd   re   rZ   r:   )r@   r_   r`   ra   rf   rc   r  s          r!   re   zResultSet.revoke  sF     	t|| <! <+5w*3F$ 	  	P <s   Ac                 ,    t        | j                        S r   )r   rZ   rE   s    r!   __iter__zResultSet.__iter__  s    DLL!!r    c                      | j                   |   S )z`res[i] -> res.results[i]`.r  )r@   indexs     r!   __getitem__zResultSet.__getitem__  s    ||E""r    c	           
      f     | 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.
        )rc   ro   rl   rM   rn   rp   ru   rm   )r   join_nativejoin)	r@   rc   ro   rl   rM   rn   rp   ru   rm   s	            r!   ry   zResultSet.get  s=     MD$=$=  499y!9N#	
 	
r    c	           	      b   |r
t                t        j                         }	d}
|t        d      g }| j                  D ]n  }d}
|r*|t        j                         |	z
  z
  }
|
dk  rt        d      |j                  |
|||||      }|r ||j                  |       ^|j                  |       p |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)rc   ro   rl   rn   rm   ru   )	r"   time	monotonicr   rZ   r   ry   r:   rW   )r@   rc   ro   rl   rM   rn   rp   ru   rm   
time_start	remainingrZ   rS   rH   s                 r!   rB  zResultSet.join  s    ^ !!#^^%
	!&>@ @ ll 	&FI#t~~'7*'DE	#&'ABBJJ!Y!&k&;  E
 E*u%	& r    c                 :    | j                   j                  ||      S r   r=   rK   rL   s       r!   rK   zResultSet.then      }}!!(H55r    c                 D    | j                   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.
        )rc   rl   rn   rp   rm   )r;   iter_native)r@   rc   rl   rn   rp   rm   s         r!   rL  zResultSet.iter_native  s/     ||''hv!{ ( 
 	
r    c	                    |r
t                |rdn2t        | j                        D 	
ci c]  \  }	}
|
j                  |	 c}
}	}|rdn!t	        t        |             D cg c]  }d c}}| j                  |||||      D ]p  \  }}t        |t              r)g }|D ]!  }|j                  |j                                # n|d   }|r|d   t        j                  v r||r
 |||       i||||   <   r |S c c}
}	w c c}w )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.
        NrS   r   )r"   	enumeraterZ   r:   rangelenrL  r   r|   rW   ry   r   rw   )r@   rc   ro   rl   rM   rn   rp   rm   ru   irS   order_indexr   accr   r   rH   children_results                     r!   rA  zResultSet.join_native&  s
    !!#&d*3DLL*A-
&QFIIqL-
 d5T3C$DaT$D!--gx.8+G 	2MGT$%'+ 8OLL!4!4!678 Xh63J3J!JK%(,1K()	2 
%-
 %Es   C4	C:c                     d  | j                   j                  | j                  D ch c]  }|j                   c}fddi|D        S c c}w )Nc              3   &   K   | ]	  \  }}|  y wr   r   )r   r   r   s      r!   r   z'ResultSet._iter_meta.<locals>.<genexpr>K  s      D s   max_iterationsr
   )r;   get_manyrZ   r:   )r@   r   r  s      r!   r   zResultSet._iter_metaJ  sN    $9DLL$9$9<<(aQTT(%
9:%
>D%
  	(s   A	
c                 (    d | j                   D        S )Nc              3      K   | ]G  }|j                   j                  |j                        r |j                  t        j
                  v r| I y wr   )r;   	is_cachedr:   r   r   rw   )r   ress     r!   r   z0ResultSet._failed_join_report.<locals>.<genexpr>P  s?      6;;((0		V444  6s   AAr  rE   s    r!   _failed_join_reportzResultSet._failed_join_reportO  s    6t|| 6 	6r    c                 ,    t        | j                        S r   )rP  rZ   rE   s    r!   __len__zResultSet.__len__T  s    4<<  r    c                 `    t        |t              r|j                  | j                  k(  S t        S r   )r   r   rZ   r   r   s     r!   r   zResultSet.__eq__W  s%    eY'==DLL00r    c                 z    dt        |       j                   ddj                  d | j                  D               dS )Nr   z: [, c              3   4   K   | ]  }|j                     y wr   r   r   r  s     r!   r   z%ResultSet.__repr__.<locals>.<genexpr>]  s     4PaQTT4P   ]>)r8   r.   rB  rZ   rE   s    r!   r   zResultSet.__repr__\  s7    4:&&'s4994P4<<4P+P*QQSTTr    c                 T    	 | j                   d   j                  S # t        $ r Y y w xY wNr   )rZ   r   
IndexErrorrE   s    r!   r   zResultSet.supports_native_join_  s-    	<<?777 		s    	''c                     | j                   >| j                  r| j                  d   j                  nt        j                         | _         | j                   S rh  )r  rZ   r9   r   _get_current_objectrE   s    r!   r9   zResultSet.appf  s@    9904a,,$88: Iyyr    c                     || _         y r   )r  )r@   r9   s     r!   r9   zResultSet.appm  s	    	r    c                 x    | j                   r| j                   j                  S | j                  d   j                  S rh  )r9   r;   rZ   rE   s    r!   r;   zResultSet.backendq  s+    #'88txxHa1H1HHr    NNr+   r  )NTrj   NTNTNr$   )Nrj   TNN)NTrj   NTNNT)'r.   r/   r0   r1   r  rZ   rB   r  r  r  r  r   r"  r   r   rr   r  r1  r   r8  r\   re   r<  r?  ry   rB  rK   rL  rA  r   r]  r_  r   r   r	  r   r9   r
  r;   r   r    r!   r   r   #  s:    D GC*#IC?G  MB>	H
 ?C#'P&"# :=3748
  ;>4859HT6 >B15
$ 378<15*."H
6
!
U     	ZZ  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                 B    || _         || _        t        |   |fi | y r   )r:   r2   superrB   )r@   r:   rZ   r2   r   r   s        r!   rB   zGroupResult.__init__  s#    +F+r    c                 X    | j                   j                  |        t        |           y r   )r;   rQ   rq  r  )r@   r   s    r!   r  zGroupResult._on_ready  s     **40r    c                 j    |xs | j                   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)
        )r9   r;   
save_groupr:   r@   r;   s     r!   savezGroupResult.save  s*     +488++77FFr    c                 j    |xs | j                   j                  j                  | j                         y)z.Remove this result if it was previously saved.N)r9   r;   delete_groupr:   ru  s     r!   deletezGroupResult.delete  s#    		$DHH$$22477;r    c                 :    | j                   | j                         fS r   r   rE   s    r!   r   zGroupResult.__reduce__  r   r    c                 2    | j                   | j                  fS r   )r:   rZ   rE   s    r!   r   zGroupResult.__reduce_args__  s    ww$$r    c                 H    t        | j                  xs | j                        S r   )boolr:   rZ   rE   s    r!   __bool__zGroupResult.__bool__  s    DGG+t||,,r    c                 
   t        |t              rO|j                  | j                  k(  xr4 |j                  | j                  k(  xr |j                  | j                  k(  S t        |t
              r|| j                  k(  S t        S r   )r   r   r:   rZ   r2   r   r   r   s     r!   r   zGroupResult.__eq__  sl    e[)DGG# ,-,+
 s#DGG##r    c           	          dt        |       j                   d| j                   ddj                  d | j                  D               dS )Nr   r   z [rb  c              3   4   K   | ]  }|j                     y wr   r   rd  s     r!   r   z'GroupResult.__repr__.<locals>.<genexpr>  s     >Zqtt>Zre  rf  )r8   r.   r:   rB  rZ   rE   s    r!   r   zGroupResult.__repr__  sA    4:&&'r$''"TYY>ZT\\>Z5Z4[[]^^r    c                 ,    t        | j                        S r   r   rE   s    r!   r   zGroupResult.__str__  r   r    c                 ,    t        | j                        S r   r   rE   s    r!   r   zGroupResult.__hash__  r   r    c                     | j                   | j                  xr | j                  j                         f| j                  D cg c]  }|j                          c}fS c c}w r   )r:   r2   rU   rZ   )r@   r  s     r!   rU   zGroupResult.as_tuple  sI    WWdkk<dkk&:&:&<=#'<<0aQZZ\0
 	
0s   Ac                     | j                   S r   r  rE   s    r!   r   zGroupResult.children  s    ||r    c                     |xs, t        | j                  t              s| j                  nt        }|xs |j                  }|j                  |      S )z&Restore previously saved group result.)r   r9   r	  r   r;   restore_group)clsr:   r;   r9   s       r!   restorezGroupResult.restore  sH      
%cggx8CGGk 	 (S[[$$R((r    )NNNr   rn  )r.   r/   r0   r1   r:   rZ   rB   r  rv  ry  r   r   r~  __nonzero__r   r   r   r   rU   r	  r   classmethodr  __classcell__)r   s   @r!   r   r   v  s     
B G,
G<6%-K	_
   ) )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y)r   z.Result that we know has already been executed.Nc                 |    || _         || _        || _        || _        t	               | _        | j                  |        y r   )r:   _result_state
_tracebackr	   r=   )r@   r:   	ret_valuer   r   s        r!   rB   zEagerResult.__init__  s5      #	dr    c                 :    | j                   j                  ||      S r   rI  rL   s       r!   rK   zEagerResult.then  rJ  r    c                     | j                   S r   )r>   rE   s    r!   r   zEagerResult._get_task_meta  s    {{r    c                 :    | j                   | j                         fS r   r   rE   s    r!   r   zEagerResult.__reduce__  r   r    c                 ^    | j                   | j                  | j                  | j                  fS r   r:   r  r  r  rE   s    r!   r   zEagerResult.__reduce_args__  s!    t{{DOODDr    c                 2    | j                         \  }} || S r   )r   )r@   r  r   s      r!   r   zEagerResult.__copy__  s    OO%	TDzr    c                      yr+   r   rE   s    r!   r   zEagerResult.ready  s    r    c                    |r
t                | j                         r| j                  S | j                  t        j
                  v rI|r;t        | j                  t              r| j                  t        | j                        | j                  S y r   )r"   r   rS   r   r   rw   r   	Exception)r@   rc   ro   ru   r   s        r!   ry   zEagerResult.get  sr     !#??;;ZZ6222%/KK&,dkk H1:4;;1GH;;	 3r    c                      y r   r   rE   s    r!   r\   zEagerResult.forget  s    r    c                 .    t         j                  | _        y r   )r   REVOKEDr  r   s      r!   re   zEagerResult.revoke  s    nnr    c                 "    d| j                    dS )Nz<EagerResult: r   r   rE   s    r!   r   zEagerResult.__repr__  s    y**r    c                 `    | j                   | j                  | j                  | j                  dS )N)r   rS   r   r   r  rE   s    r!   r>   zEagerResult._cache  s*     wwllkk	
 	
r    c                     | j                   S )zThe tasks return value.)r  rE   s    r!   rS   zEagerResult.result  s     ||r    c                     | j                   S )zThe tasks state.)r  rE   s    r!   r   zEagerResult.state  s     {{r    c                     | j                   S )z!The traceback if the task failed.)r  rE   s    r!   r   zEagerResult.traceback"  s     r    c                      yr$   r   rE   s    r!   r   z EagerResult.supports_native_join'  s    r    r   r$   )NTT)r.   r/   r0   r1   rB   rK   r   r   r   r   r   ry   rf   r\   re   r   r	  r>   rS   r   r   r   r   r   r    r!   r   r     s    866E +/"& D%+ 
 
     F   r    r   c           
      2   t        |      }|j                  }t        | t              sj| \  }}t        |t        t
        f      r|n|df\  }}|rt        ||      }|,|j                  ||D cg c]  }t        ||       c}|      S  |||      S | S c c}w )zDeserialize result from tuple.Nr   )r   r   r   r   r|   tupler   r   )r  r9   Resultr\  nodesr:   r2   r   s           r!   r   r   ,  s     
C__Fa$
U&sT5M:Sd
F&vs3F??Fu&uc2F #  
 b((H Gs   ,B
r   ),r1   r  rD  collectionsr   
contextlibr   weakrefr   kombu.utils.objectsr   viner   r   r	    r   r   r  r   r   r9   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     s2   9    %  / + + ! C  L L 8
)
 / / / /  
\2* \2 \2~ 
OI
 OI OId
 
\)) \) \)~ 
R+ R Rjq   Es   C( (C21C2