
    h                        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 dZ"dZ#d Z$ed        Z%ed        Z& G d d      Z'ejP                   G d de'             Z)ejP                   G d de'             Z*ejP                   G d de*             Z+ejP                   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)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                  6    t               rt        t              y N)r   RuntimeErrorE_WOULDBLOCK     I/var/www/Befach/backend/env/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-   3   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backendr3   r
   _on_fulfilledon_ready_cache_ignored)selfr;   r<   	task_namer:   r3   s         r"   __init__zAsyncResult.__init__X   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@   rA   s    r"   ignoredzAsyncResult.ignoredf   s     4$== r!   c                     || _         y)z%Enable/disable task result retrieval.N)r@   )rA   values     r"   rG   zAsyncResult.ignoredm   s     r!   c                 t    | j                   j                  | |       | j                  j                  ||      S )Nr6   )r<   add_pending_resultr>   thenrA   callbackon_errorr7   s       r"   rL   zAsyncResult.thenr   s0    ''4'8}}!!(H55r!   c                 <    | j                   j                  |        |S r   r<   remove_pending_resultrA   results     r"   r=   zAsyncResult._on_fulfilledv   s    **40r!   c                 ^    | j                   }| j                  |xr |j                         fd fS r   )r3   r;   as_tuple)rA   r3   s     r"   rV   zAsyncResult.as_tuplez   s+    5FOO$56<<r!   c                     g }| j                   }|j                  | j                         ||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~   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?   r3   forgetr<   r;   rF   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)r:   controlrevoker;   )rA   r`   ra   rb   waitrd   s         r"   rf   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)r:   re   revoke_by_stamped_headers)rA   headersr`   ra   rb   rg   rd   s          r"   ri   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.
        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   rp   rm   ro   follow_parentsrN   rq   rn   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_parentsrs   rA   nodes     r"   rr   z'AsyncResult._maybe_reraise_parent_error  s(    T$--/23D 4r!   c              #   P   K   | j                   }|r| |j                   }|ry y wr   r3   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    iterdepsrz   )rA   r   kwargs_Rs        r"   collectzAsyncResult.collect  s9     \ MM|M<DAqUQUU_V_$$ =s   24c                 Z    d }| j                         D ]  \  }}|j                         } |S r   r   )rA   rI   r   r   s       r"   get_leafzAsyncResult.get_leafA  s+    MMODAq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>P  s     LudE]Ls   )r   popleftreadyrY   childrenr   )rA   r   stackis_incomplete_streamr3   r   s        @r"   r   zAsyncResult.iterdepsG  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_STATESrF   s    r"   r   zAsyncResult.readyU  s     zzT\\6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]      zzV^^++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 | y r   )r>   throwrA   argsr   s      r"   r   zAsyncResult.throwe  s    T,V,r!   c                     | j                   | j                         n| j                   }|d   |d   |j                  d      }}}|t        j                  v r#|r!| j                  || j                  |             | || j                  |       |S )NstatusrT   	traceback)r?   _get_task_metarz   r   rx   r   _to_remote_tracebackr;   )rA   rp   rN   cacher   rI   tbs          r"   rs   zAsyncResult.maybe_throwh  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   )tblibr:   conftask_remote_tracebacks	Tracebackfrom_stringas_traceback)rA   r   s     r"   r   z AsyncResult._to_remote_tracebacks  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)rA   r   r   graphr3   r   s         r"   build_graphzAsyncResult.build_graphw  s_    M>twwf#M
 !MM|MDLFDMM$vt, E r!   c                 ,    t        | j                        S z`str(self) -> self.id`.strr;   rF   s    r"   __str__zAsyncResult.__str__      477|r!   c                 ,    t        | j                        S z`hash(self) -> hash(self.id)`.hashr;   rF   s    r"   __hash__zAsyncResult.__hash__      DGG}r!   c                 N    dt        |       j                   d| j                   dS )N<: >)r9   r/   r;   rF   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rA   others     r"   __eq__zAsyncResult.__eq__  s>    e[)88tww&&s#DGG##r!   c                 |    | j                  | j                  | j                  d | j                  | j                        S r   )	__class__r;   r<   r:   r3   rF   s    r"   __copy__zAsyncResult.__copy__  s.    ~~GGT\\44;;
 	
r!   c                 :    | j                   | j                         fS r   r   __reduce_args__rF   s    r"   
__reduce__zAsyncResult.__reduce__      ~~t33555r!   c                 L    | j                   | j                  d d | j                  fS r   )r;   r<   r3   rF   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.NrQ   rF   s    r"   __del__zAsyncResult.__del__  s#    <<#LL..t4 $r!   c                 "    | j                         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00r!   c                 @    | j                         j                  d      S Nr   r   rz   rF   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>   )rA   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;   rF   s    r"   r   zAsyncResult._get_task_meta  s:    ;;(()C)CDGG)LMM{{r!   c                 6    t        | j                         g      S r   )iterr   )rA   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   )rz   r   r:   r?   )rA   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.
        rT   r   rF   s    r"   rT   zAsyncResult.result  s     ""$X..r!   c                 @    | j                         j                  d      S )z#Get the traceback of a failed task.r   r   rF   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   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     wwr!   c                     || _         y r   r   )rA   r;   s     r"   r   zAsyncResult.task_id  s	    r!   c                 @    | j                         j                  d      S )Nnamer   rF   s    r"   r   zAsyncResult.name      ""$((00r!   c                 @    | j                         j                  d      S )Nr   r   rF   s    r"   r   zAsyncResult.args  r   r!   c                 @    | j                         j                  d      S )Nr   r   rF   s    r"   r   zAsyncResult.kwargs      ""$((22r!   c                 @    | j                         j                  d      S )Nworkerr   rF   s    r"   r   zAsyncResult.worker  r   r!   c                     | j                         j                  d      }|r%t        |t        j                        st	        |      S |S )zUTC date and time.	date_done)r   rz   r   datetimer   )rA   r  s     r"   r  zAsyncResult.date_done  s@     '')--k:	Z	83D3DEI&&r!   c                 @    | j                         j                  d      S )Nretriesr   rF   s    r"   r  zAsyncResult.retries  s    ""$((33r!   c                 @    | j                         j                  d      S )Nqueuer   rF   s    r"   r  zAsyncResult.queue  s    ""$((11r!   )NNNNr%   NFNFN)F)TN)FN)Br/   r0   r1   r2   r:   r   r;   r<   rC   propertyrG   setterrL   r=   rV   rZ   r]   rf   ri   r   rw   rx   rz   rg   rr   r~   r   r   r   r   r   r   r   rs   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#'"&   ^^ 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   Tr6   )	_appr[   r
   r   r>   r	   _on_fullrL   	_on_ready)rA   r[   r:   ready_barrierr   s        r"   rC   zResultSet.__init__1  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)r[   rX   r  addrS   s     r"   r  zResultSet.add9  sE    
 %LL'}}!!&)  &r!   c                 R    | j                   j                  r| j                          y y r   )r<   is_asyncr>   rF   s    r"   r  zResultSet._on_readyC  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   r:   r   r[   remover8   KeyErrorrS   s     r"   r  zResultSet.removeG  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  rS   s     r"   discardzResultSet.discardT  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   r[   )r   rrA   s     r"   r   z#ResultSet.update.<locals>.<genexpr>`  s     H!!4<<2GAHs   N)r[   rY   )rA   r[   s   ` r"   updatezResultSet.update^  s    HwHHr!   c                 "    g | j                   dd y)z!Remove all results from this set.Nr  rF   s    r"   clearzResultSet.clearb  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   rT   s     r"   r   z'ResultSet.successful.<locals>.<genexpr>m  s     B66$$&B   allr[   rF   s    r"   r   zResultSet.successfulf  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>v  s     >v6==?>r&  anyr[   rF   s    r"   r   zResultSet.failedo  s     >>>>r!   c                 L    | j                   D ]  }|j                  ||        y )N)rN   rp   )r[   rs   )rA   rN   rp   rT   s       r"   rs   zResultSet.maybe_throwx  s#    llFIF #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+  rF   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'  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   N   K   | ]  }t        |j                                 y wr   )intr   r%  s     r"   r   z,ResultSet.completed_count.<locals>.<genexpr>  s     G3v((*+Gs   #%)sumr[   rF   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)r[   r]   rS   s     r"   r]   zResultSet.forget  s    llF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`   rd   ra   rb   rc   N)r:   re   rf   r[   r;   )rA   r`   ra   rb   rg   rd   r  s          r"   rf   zResultSet.revoke  sF     	t|| <! <+5w*3F$ 	  	P <s   Ac                 ,    t        | j                        S r   )r   r[   rF   s    r"   __iter__zResultSet.__iter__  s    DLL!!r!   c                      | j                   |   S )z`res[i] -> res.results[i]`.r  )rA   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.
        )rd   rp   rm   rN   ro   rq   rv   rn   )r   join_nativejoin)	rA   rd   rp   rm   rN   ro   rq   rv   rn   s	            r"   rz   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)rd   rp   rm   ro   rn   rv   )	r#   time	monotonicr   r[   r   rz   r;   rX   )rA   rd   rp   rm   rN   ro   rq   rv   rn   
time_start	remainingr[   rT   rI   s                 r"   rB  zResultSet.join  s    ^ !!#^^%
	!&>@ @ llFI#t~~'7*'DE	#&'ABBJJ!Y!&k&;  E
 E*u% # r!   c                 :    | j                   j                  ||      S r   r>   rL   rM   s       r"   rL   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.
        )rd   rm   ro   rq   rn   )r<   iter_native)rA   rd   rm   ro   rq   rn   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.
        NrT   r   )r#   	enumerater[   r;   rangelenrL  r   r}   rX   rz   r   rx   )rA   rd   rp   rm   rN   ro   rq   rn   rv   irT   order_indexr   accr   r   rI   children_results                     r"   rA  zResultSet.join_native'  s    !!#&d*3DLL*A-
&QFIIqL-
 d5T3C$DaT$D!--gx.8+GMGT$%'+OLL!4!4!67 (, Xh63J3J!JK%(,1K()G 
%-
 %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>L  s      D s   max_iterationsr   )r<   get_manyr[   r;   )rA   r   r  s      r"   r   zResultSet._iter_metaK  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   rx   )r   ress     r"   r   z0ResultSet._failed_join_report.<locals>.<genexpr>Q  s?      6;;((0		V444  6s   AAr  rF   s    r"   _failed_join_reportzResultSet._failed_join_reportP  s    6t|| 6 	6r!   c                 ,    t        | j                        S r   )rP  r[   rF   s    r"   __len__zResultSet.__len__U  s    4<<  r!   c                 `    t        |t              r|j                  | j                  k(  S t        S r   )r   r   r[   r   r   s     r"   r   zResultSet.__eq__X  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   ]>)r9   r/   rB  r[   rF   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   )r[   r   
IndexErrorrF   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  r[   r:   r   _get_current_objectrF   s    r"   r:   zResultSet.appg  s@    9904a,,$88: Iyyr!   c                     || _         y r   )r  )rA   r:   s     r"   r:   zResultSet.appn  s	    	r!   c                 x    | j                   r| j                   j                  S | j                  d   j                  S rh  )r:   r<   r[   rF   s    r"   r<   zResultSet.backendr  s+    #'88txxHa1H1HHr!   NNr,   r  )NTrk   NTNTNr%   )Nrk   TNN)NTrk   NTNNT)'r/   r0   r1   r2   r  r[   rC   r  r  r  r  r   r"  r   r   rs   r  r1  r   r8  r]   rf   r<  r?  rz   rB  rL   rL  rA  r   r]  r_  r   r   r	  r   r:   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;   r3   superrC   )rA   r;   r[   r3   r   r   s        r"   rC   zGroupResult.__init__  s#    +F+r!   c                 X    | j                   j                  |        t        |           y r   )r<   rR   rq  r  )rA   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)
        )r:   r<   
save_groupr;   rA   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)r:   r<   delete_groupr;   ru  s     r"   deletezGroupResult.delete  s#    		$DHH$$22477;r!   c                 :    | j                   | j                         fS r   r   rF   s    r"   r   zGroupResult.__reduce__  r   r!   c                 2    | j                   | j                  fS r   )r;   r[   rF   s    r"   r   zGroupResult.__reduce_args__  s    ww$$r!   c                 H    t        | j                  xs | j                        S r   )boolr;   r[   rF   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;   r[   r3   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  )r9   r/   r;   rB  r[   rF   s    r"   r   zGroupResult.__repr__  sA    4:&&'r$''"TYY>ZT\\>Z5Z4[[]^^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                     | j                   | j                  xr | j                  j                         f| j                  D cg c]  }|j                          c}fS c c}w r   )r;   r3   rV   r[   )rA   r  s     r"   rV   zGroupResult.as_tuple  sI    WWdkk<dkk&:&:&<=#'<<0aQZZ\0
 	
0s   Ac                     | j                   S r   r  rF   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   r:   r	  r   r<   restore_group)clsr;   r<   r:   s       r"   restorezGroupResult.restore  sH      
%cggx8CGGk 	 (S[[$$R((r!   )NNNr   rn  )r/   r0   r1   r2   r;   r[   rC   r  rv  ry  r   r   r~  __nonzero__r   r   r   r   rV   r	  r   classmethodr  __classcell__)r   s   @r"   r   r   w  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
_traceback_namer
   r>   )rA   r;   	ret_valuer   r   r   s         r"   rC   zEagerResult.__init__  s<      #
	dr!   c                 :    | j                   j                  ||      S r   rI  rM   s       r"   rL   zEagerResult.then  rJ  r!   c                     | j                   S r   )r?   rF   s    r"   r   zEagerResult._get_task_meta  s    {{r!   c                 :    | j                   | j                         fS r   r   rF   s    r"   r   zEagerResult.__reduce__  r   r!   c                 ^    | j                   | j                  | j                  | j                  fS r   )r;   r  r  r  rF   s    r"   r   zEagerResult.__reduce_args__  s!    t{{DOODDr!   c                 2    | j                         \  }} || S r   )r   )rA   r  r   s      r"   r   zEagerResult.__copy__  s    OO%	TDzr!   c                      yr,   r    rF   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   rT   r   r   rx   r   	Exception)rA   rd   rp   rv   r   s        r"   rz   zEagerResult.get  sr     !#??;;ZZ6222%/KK&,dkk H1:4;;1GH;;	 3r!   c                      y r   r    rF   s    r"   r]   zEagerResult.forget  s    r!   c                 .    t         j                  | _        y r   )r   REVOKEDr  r   s      r"   rf   zEagerResult.revoke
  s    nnr!   c                 "    d| j                    dS )Nz<EagerResult: r   r   rF   s    r"   r   zEagerResult.__repr__  s    y**r!   c                 v    | 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  s1     wwllkkJJ
 	
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                      yr%   r    rF   s    r"   r   z EagerResult.supports_native_join*  s    r!   rn  r%   )NTT)r/   r0   r1   r2   rC   rL   r   r   r   r   r   rz   rg   r]   rf   r   r	  r?   rT   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  r:   Resultr\  nodesr;   r3   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   ).r2   r  rD  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     s5   9    %  $ / + + ! C  L L 8
)
 / / / /  
\2* \2 \2~ 
OI
 OI OId
 
\)) \) \)~ 
T+ T Tnu   Es   C. .C87C8