
    `f                        d Z ddlZddlmZmZ ddlmZ ddlmZ ddl	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mZmZmZ ddlmZ ddlmZmZ ddlm Z  ddl!m"Z"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z, ddl-m.Z. ddl/m0Z0 dZ1 e"dddddddddd d!d"          Z2d#Z3d$Z4d%Z5e6Z7d-d'Z8d.d(Z9 G d) d*          Z:e j;        j<         G d+ d,                      Z=e=Z>dS )/z=Task implementation: request context and the task base class.    N)ExceptionInfoExceptionWithTraceback)serialization)OperationalError)uuid)current_appstates)_task_stack)_chaingroup	signature)IgnoreImproperlyConfiguredMaxRetriesExceededErrorRejectRetry)class_property)EagerResultdenied_join_result)abstract)mattrgetter
maybe_list)instantiate)gethostname)raise_with_context   )resolve_all)_unpickle_task_v2)appstr)ContextTaskqueuerouting_keyexchangepriorityexpires
serializerdelivery_modecompression
time_limitsoft_time_limit	immediate	mandatoryz$<class {0.__name__} of {app}{flags}>z<unbound {0.__name__}{flags}>z!<@task: {0.name} of {app}{flags}> c                 Z    | r(d                     d                    |                     S |S )Nz ({})z, )formatjoin)flagsdefaults     A/var/www/html/env/lib/python3.11/site-packages/celery/app/task.py	_strflagsr5   +   s-     0~~dii..///N    c                    |t          |          ng }| j        r|                    d          nd  |s| j        rt          nt
          }|                    | t          |          | j        rt          | j                  nd           S )Nzv2 compatible)r2   app)	list__v2_compat__append_appR_BOUND_TASKR_UNBOUND_TASKr0   r5   r   )taskfmtr2   s      r4   	_reprtaskrA   1   s     ,DKKK"E%)%7AELL!!!T <"i;ll^::Ie$$!%4F49    r6   c                       e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&d Z'd Z(d Z)d	 Z*dd
Z+d Z,d Z-e.d             Z/dS )r    z&Task request variables (Task.request).Nr   TFc                 V     | j         |i | | j         | j        |i || _        d S d S N)updateheaders_get_custom_headersselfargskwargss      r4   __init__zContext.__init__c   sF    T$V$$$<343TDVDDDLLL  r6   c                     i } |j         |i | h t          j                                        ddddd}|D ]}|                    |d            |sd S |S )Nlangr?   argsrepr
kwargsreprr)   )rE   r    __dict__keyspop)rI   rJ   rK   rF   celery_keyskeys         r4   rG   zContext._get_custom_headersh   s    ''''i(--//iiii\i[hi 	# 	#CKKT"""" 	4r6   c                 &     | j         j        |i |S rD   )rQ   rE   rH   s      r4   rE   zContext.updater   s    #t}#T4V444r6   c                 4    | j                                         S rD   )rQ   clearrI   s    r4   rX   zContext.clearu   s    }""$$$r6   c                 $    t          | ||          S rD   )getattr)rI   rU   r3   s      r4   getzContext.getx   s    tS'***r6   c                 (    dt          |           dS )Nz
<Context: >)varsrY   s    r4   __repr__zContext.__repr__{   s    +DJJ++++r6   c                    | j         pd\  }}i d| j        d| j        d| j        d| j        d| j        d| j        d| j        d	| j        d
| j	        d| j
        d| j        d|d|d| j        d| j        d| j        d| j        d| j        i}t#          | d          rLt#          | d          r<| j        5| j        .| j        |d<   | j                                        D ]
\  }}|||<   |S )NNNtask_idroot_id	parent_idgroup_idgroup_indexshadowchordchainlink
link_errorr&   r+   r*   rF   retriesreply_toreplaced_task_nestingoriginstampsstamped_headers)	timelimitidrd   re   r   rg   rh   ri   rj   	callbackserrbacksr&   rF   rm   rn   ro   rp   hasattrrq   rr   items)rI   
limit_hard
limit_softexecution_optionskvs         r4   as_execution_optionszContext.as_execution_options~   s   !%!?<
J
tw
t|
 
 
	

 4+
 dk
 TZ
 TZ
 DN
 $-
 t|
 z
 *
 t|
 t|
  !
" $T%?#
$ dk%
 
( 4"" 	-wt5F'G'G 	-{&4+?+K7;7K!"34 K--// - -DAq+,%a((  r6   c                 ,    | j         g | _         | j         S rD   )	_childrenrY   s    r4   childrenzContext.children   s     >!DN~r6   rD   )0__name__
__module____qualname____doc__r   
_protectedrJ   ru   called_directlyrj   ri   correlation_iddelivery_inforv   etar&   r   rg   rF   hostnamert   ignore_resultis_eagerrK   logfileloglevelrp   re   
propertiesrm   rn   ro   rd   rh   tasksetrs   utcrr   rq   rL   rG   rE   rX   r\   r`   r~   propertyr    r6   r4   r    r    <   sV       00IJDIOEENMH
CGEKGH	BMHFGHFIJGHGFGI
COFE E E
  5 5 5% % %+ + + +, , ,! ! !:   X  r6   r    c                   x   e Zd ZdZdZdZeZeZdZdZ	dZ
dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZd	ZdZ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             Z* e+e*e(          Z,e'd             Z-e'd             Z.d Z/d Z0d Z1d Z2d Z3	 	 d5dZ4d Z5	 	 d6dZ6e6Z7	 	 d7dZ8	 	 	 	 d8dZ9d Z:d9dZ;e;Z<d Z=d Z>d Z?d  Z@d! ZAd:d"ZBd# ZCd;d$ZDd<d%ZEd& ZFd' ZGd( ZHd) ZId* ZJd+ ZKd, ZLd- ZMd. ZNd/ ZOd0 ZP eQeP          ZRd1 ZSeQd2             ZejT        d3             ZeQd4             Z dS )=r!   zTask base class.

    Note:
        When called tasks apply the :meth:`run` method.  This method must
        be defined by all tasks (that is unless the :meth:`__call__` method
        is overridden).
    NFzcelery.worker.strategy:defaultzcelery.worker.request:Request      Tr   i   )
)r'   task_serializer)
rate_limittask_default_rate_limit)r%   task_default_priority)track_startedtask_track_started)	acks_latetask_acks_late)acks_on_failure_or_timeouttask_acks_on_failure_or_timeout)reject_on_worker_losttask_reject_on_worker_lost)r   task_ignore_result)store_eager_resulttask_store_eager_result)store_errors_even_if_ignored!task_store_errors_even_if_ignoredc                 ^   | j         dc}| _         || _        |j        }d | _        | j        |j        | _        | j        D ]-\  }}t          | |d           t          | |||                    .|s)| 	                                 ddl
m}  |            | _        |                     |           |S )NTr   )
LocalStack)	__bound__r<   conf_exec_optionstypingstrict_typingfrom_configr[   setattrannotatecelery.utils.threadsr   request_stackon_bound)clsr8   	was_boundr   	attr_nameconfig_namer   s          r4   bindz	Task.bindW  s    #&=$ 	3=x :*CJ&)o 	; 	;"I{sIt,,4Y[(9:::  	-LLNNN777777 *
C 	S
r6   c                     dS )zCalled when the task is bound to an app.

        Note:
            This class method can be defined to do additional actions when
            the task class is bound to an app.
        Nr   )r   r8   s     r4   r   zTask.on_boundq        r6   c                 x    | j         t          | _         | j        s|                     | j                    | j         S rD   )r<   r   r   r   )r   s    r4   _get_appzTask._get_appz  s8    8"CH} 	 HHSXxr6   c                     t          | j        j        |           D ]a}|                                D ]J\  }}|                    d          r|                     |dd          |           9t          | ||           Kbd S )N@r   )resolve_all_annotationsr8   annotationsrx   
startswith
add_aroundr   )r   drU   values       r4   r   zTask.annotate  s    ()<cBB 	- 	-Aggii - -
U>>#&& -NN3qrr7E2222Ce,,,,	-	- 	-r6   c                     t          | |          }t          |dd           r|j        } ||          }||_        t          | ||           d S )N__wrapped__)r[   r   r   )r   attraroundorigmeths        r4   r   zTask.add_around  sZ    sD!!4-- 	$#Dvd||T4     r6   c                    t          j        |            |                     ||           	  | j        |i ||                                  t          j                     S # |                                  t          j                     w xY w)N)rJ   rK   )r
   pushpush_requestrunpop_requestrS   rH   s      r4   __call__zTask.__call__  s    tF333	48T,V,,O Os   A! !)B
c                 t    t          |           j        }|r|t          j        v r|nd }t          | j        |fd fS rD   )typer   sysmodulesr   name)rI   mods     r4   
__reduce__zTask.__reduce__  s@     4jj#9SCK//ccT!DIs#3T::r6   c                      t          d          )z)The body of the task executed by workers.z!Tasks must define the run method.)NotImplementedErrorrH   s      r4   r   zTask.run  s    !"EFFFr6   c                 ,    t          | j        | ||fi |S rD   )r   Strategy)rI   r8   consumerrK   s       r4   start_strategyzTask.start_strategy  s     4=$XHHHHHr6   c                 .    |                      ||          S )ah  Star argument version of :meth:`apply_async`.

        Does not support the extra options enabled by :meth:`apply_async`.

        Arguments:
            *args (Any): Positional arguments passed on to the task.
            **kwargs (Any): Keyword arguments passed on to the task.
        Returns:
            celery.result.AsyncResult: Future promise.
        )apply_asyncrH   s      r4   delayz
Task.delay  s     f---r6   c                    | j         r%	 | j        }	 |	|pdi |pi  n# t          $ r Y nw xY w| j        r#|p|                      |             |||          }n|p|                     |||          }|                                 }
|rt          |
fi |n|
}|                    d| j                   | j	        r|                    d| j	                   | 
                                }|j        j        r|                    |          5 }|                    d          }||j        r|j        }n|j        j        }||f}t#          j        ||          \  }}}t#          j        ||||g          \  }}ddd           n# 1 swxY w Y   t)                      5   | j        ||f|pt-                      ||d|cddd           S # 1 swxY w Y   dS  |j        | j        ||f||||| j        || d|S )	a  Apply tasks asynchronously by sending a message.

        Arguments:
            args (Tuple): The positional arguments to pass on to the task.

            kwargs (Dict): The keyword arguments to pass on to the task.

            countdown (float): Number of seconds into the future that the
                task should execute.  Defaults to immediate execution.

            eta (~datetime.datetime): Absolute time and date of when the task
                should be executed.  May not be specified if `countdown`
                is also supplied.

            expires (float, ~datetime.datetime): Datetime or
                seconds in the future for the task should expire.
                The task won't be executed after the expiration time.

            shadow (str): Override task name used in logs/monitoring.
                Default is retrieved from :meth:`shadow_name`.

            connection (kombu.Connection): Re-use existing broker connection
                instead of acquiring one from the connection pool.

            retry (bool): If enabled sending of the task message will be
                retried in the event of connection loss or failure.
                Default is taken from the :setting:`task_publish_retry`
                setting.  Note that you need to handle the
                producer/connection manually for this to work.

            retry_policy (Mapping): Override the retry policy used.
                See the :setting:`task_publish_retry_policy` setting.

            time_limit (int): If set, overrides the default time limit.

            soft_time_limit (int): If set, overrides the default soft
                time limit.

            queue (str, kombu.Queue): The queue to route the task to.
                This must be a key present in :setting:`task_queues`, or
                :setting:`task_create_missing_queues` must be
                enabled.  See :ref:`guide-routing` for more
                information.

            exchange (str, kombu.Exchange): Named custom exchange to send the
                task to.  Usually not used in combination with the ``queue``
                argument.

            routing_key (str): Custom routing key used to route the task to a
                worker server.  If in combination with a ``queue`` argument
                only used to specify custom routing keys to topic exchanges.

            priority (int): The task priority, a number between 0 and 9.
                Defaults to the :attr:`priority` attribute.

            serializer (str): Serialization method to use.
                Can be `pickle`, `json`, `yaml`, `msgpack` or any custom
                serialization method that's been registered
                with :mod:`kombu.serialization.registry`.
                Defaults to the :attr:`serializer` attribute.

            compression (str): Optional compression method
                to use.  Can be one of ``zlib``, ``bzip2``,
                or any custom compression methods registered with
                :func:`kombu.compression.register`.
                Defaults to the :setting:`task_compression` setting.

            link (Signature): A single, or a list of tasks signatures
                to apply if the task returns successfully.

            link_error (Signature): A single, or a list of task signatures
                to apply if an error occurs while executing the task.

            producer (kombu.Producer): custom producer to use when publishing
                the task.

            add_to_parent (bool): If set to True (default) and the task
                is applied while executing another task, then the result
                will be appended to the parent tasks ``request.children``
                attribute.  Trailing can also be disabled by default using the
                :attr:`trail` attribute

            ignore_result (bool): If set to `False` (default) the result
                of a task will be stored in the backend. If set to `True`
                the result will not be stored. This can also be set
                using the :attr:`ignore_result` in the `app.task` decorator.

            publisher (kombu.Producer): Deprecated alias to ``producer``.

            headers (Dict): Message headers to be included in the message.

        Returns:
            celery.result.AsyncResult: Promise of future evaluation.

        Raises:
            TypeError: If not enough arguments are passed, or too many
                arguments are passed.  Note that signature checks may
                be disabled by specifying ``@task(typing=False)``.
            kombu.exceptions.OperationalError: If a connection to the
               transport cannot be made, or if the connection is lost.

        Note:
            Also supports all keyword arguments supported by
            :meth:`kombu.Producer.publish`.
        r   r   r%   r'   N)accept)rc   rk   rl   )rc   producerrk   rl   
result_clsrh   	task_type)r   
__header__AttributeErrorr:   shadow_name_get_exec_optionsdict
setdefaultr   r%   r   r   task_always_eagerproducer_or_acquirer\   r'   r   r   dumpsloadsr   applyr   	send_taskr   AsyncResult)rI   rJ   rK   rc   r   rk   rl   rh   optionscheck_argumentspreoptsr8   eager_producerr'   bodycontent_typecontent_encodingdatas                     r4   r   zTask.apply_async  s/   V ; 	AA"&/  $*"@&,B@@@@ "   
  	GNt//fgNNFFFt//fgFFF((**.5B$w**'***7?D,>???= 	:z4=999mmoo8% 	((22 n$[[66
%%0 >%3%>

%(X%=
V|7D7J*8 84.  -2,(8(>     f               $%% O O!tz$ O8I466'+
O OFMO OO O O O O O O O O O O O O O O O O O !3=	4188jT=M  	  s1    
**A,E??FF!GG
G
c                     dS )a  Override for custom task name in worker logs/monitoring.

        Example:
            .. code-block:: python

                from celery.utils.imports import qualname

                def shadow_name(task, args, kwargs, options):
                    return qualname(args[0])

                @app.task(shadow_name=shadow_name, serializer='pickle')
                def apply_function_async(fun, *args, **kwargs):
                    return fun(*args, **kwargs)

        Arguments:
            args (Tuple): Task positional arguments.
            kwargs (Dict): Task keyword arguments.
            options (Dict): Task execution options.
        Nr   )rI   rJ   rK   r   s       r4   r   zTask.shadow_nameY  r   r6   c                    || j         n|}||j        n|}||j        n|}i |                                |}|j        pi }|                    d          }|||d<   |r||d<   nM|                    d          }	|                    d          }
|	dk    r|
r|
|d<   n|                    |            | j        |||fd| i|S )Nr%   r"   r$   r#   r.   r   )requestrJ   rK   r~   r   r\   rE   r   )rI   r   rJ   rK   r"   extra_optionsr   r   r%   r$   r#   s              r4   signature_from_requestzTask.signature_from_requestn  s   ")/$,,w#|w||#)>vEW1133E}E-3 $$Z00"*GJ 		.$GG$((44H'++M::K2~~+~#.  }---t~&'
 
(,
0=
 
 	
r6   c                 f   | j         }	|	j        dz   }
||| _        || j        n|}|	j        rt          |pt          dd                     |s	|| j        }|	j        } | j	        |	||f|||
d|}|c|
|k    r]|rt          |           | 
                    d                    | j        |	j        |j        |j                  |j        |j                  t          ||p|||          }|r|r||S 	 |                                 n## t"          $ r}t%          |d	          d}~ww xY w|r||S )
a  Retry the task, adding it to the back of the queue.

        Example:
            >>> from imaginary_twitter_lib import Twitter
            >>> from proj.celery import app

            >>> @app.task(bind=True)
            ... def tweet(self, auth, message):
            ...     twitter = Twitter(oauth=auth)
            ...     try:
            ...         twitter.post_status_update(message)
            ...     except twitter.FailWhale as exc:
            ...         # Retry in 5 minutes.
            ...         raise self.retry(countdown=60 * 5, exc=exc)

        Note:
            Although the task will never return above as `retry` raises an
            exception to notify the worker, we use `raise` in front of the
            retry to convey that the rest of the block won't be executed.

        Arguments:
            args (Tuple): Positional arguments to retry with.
            kwargs (Dict): Keyword arguments to retry with.
            exc (Exception): Custom exception to report when the max retry
                limit has been exceeded (default:
                :exc:`~@MaxRetriesExceededError`).

                If this argument is set and retry is called while
                an exception was raised (``sys.exc_info()`` is set)
                it will attempt to re-raise the current exception.

                If no exception was raised it will raise the ``exc``
                argument provided.
            countdown (float): Time in seconds to delay the retry for.
            eta (~datetime.datetime): Explicit time and date to run the
                retry at.
            max_retries (int): If set, overrides the default retry limit for
                this execution.  Changes to this parameter don't propagate to
                subsequent task retry attempts.  A value of :const:`None`,
                means "use the default", so if you want infinite retries you'd
                have to set the :attr:`max_retries` attribute of the task to
                :const:`None` first.
            time_limit (int): If set, overrides the default time limit.
            soft_time_limit (int): If set, overrides the default soft
                time limit.
            throw (bool): If this is :const:`False`, don't raise the
                :exc:`~@Retry` exception, that tells the worker to mark
                the task as being retried.  Note that this means the task
                will be marked as failed if the task raises an exception,
                or successful if it returns after the retry call.
            **options (Any): Extra options to pass on to :meth:`apply_async`.

        Raises:

            celery.exceptions.Retry:
                To tell the worker that the task has been re-sent for retry.
                This always happens, unless the `throw` keyword argument
                has been explicitly set to :const:`False`, and is considered
                normal operation.
        r   NzTask can be retried)	countdownr   rm   z$Can't retry {}[{}] args:{} kwargs:{})	task_argstask_kwargs)excwhenr   sigF)requeue)r   rm   override_max_retriesmax_retriesr   r   r   default_retry_delayr   r  r   r0   r   rt   rJ   rK   r   	Exceptionr   )rI   rJ   rK   r  throwr   r  r  r   r   rm   r   Srets                 r4   retryz
Task.retry  s   | ,/A%"(3D%*5*=d&&; " 	J sHe,A4&H&HIII 	1y(0I#'D'T6
S'
 
 
 
 "w'<'< ( #3'''..6==Iwz1618 V /    #"2X1MMM 	  	J	-MMOOOO 	- 	- 	-e,,,,	- 	I
s   5D
 

D*D%%D*c                    ddl m} |                                 }|pd}|pi }|pt                      }|pd}||j        j        }|j        | j                 }|| j        |d||	pdt                      t          |          t          |          |

                    dd          d
                    d          
                    d	          
                    d
          dd}dv r/t          d                   |d<   fd|d         D             |d<   d} ||j        |d||                                           } |||||          }|j        }t          |t                    r*|j        |j        }}t          |t                     r|j        }t          |t$                    r%|j        |j                            |dz             S |j        t,          j        n|j        j        }t3          ||||| j                  S )a  Execute this task locally, by blocking until the task returns.

        Arguments:
            args (Tuple): positional arguments passed on to the task.
            kwargs (Dict): keyword arguments passed on to the task.
            throw (bool): Re-raise task exceptions.
                Defaults to the :setting:`task_eager_propagates` setting.

        Returns:
            celery.result.EagerResult: pre-evaluated result.
        r   )build_tracerr   NTr   Fr$   r#   r%   )r   r$   r#   r%   )rt   r?   rm   r   r   r   r   ru   rv   rF   r   r   rr   c           	      X    i | ]&}|t                              |g                     'S r   )r   r\   ).0headerr   s     r4   
<dictcomp>zTask.apply.<locals>.<dictcomp>*  s>     ! ! !@F
7;;vr#:#:;;! ! !r6   rq   )eager	propagater8   r   )rm   )	tracebackr   )celery.app.tracer  r   r   r   task_eager_propagates_tasksr   r   r   r\   retval
isinstancer   	exceptionr  r   r  r   r  r   infor	   SUCCESSstater   )rI   rJ   rK   rk   rl   rc   rm   r  r   r   rF   r   r  r8   r?   r   tbtracerr  r  r#  s              `         r4   r   z
Task.apply  sI     	211111mmoozr2#TVV,Q=H2E z$)$ I A##D))":..$[[%@@ #KK
33&{{=99#KK
33	 
 
& '')3G<M4N)O)OG%&! ! ! !JQRcJd! ! !GH It4
 
 
 fWdFG44fm,, 	$)6+;BF&"899 $fe$$ 	9)?:##GaK#888"%("27FERdiPPPPr6   c                 \     |                                  j        |f| j        | j        d|S )zGet AsyncResult instance for the specified task.

        Arguments:
            task_id (str): Task id to get result for.
        )backend	task_name)r   r   r'  r   )rI   rc   rK   s      r4   r   zTask.AsyncResult>  sF     +t}}*7 JDL59YJ JBHJ J 	Jr6   c                 Z    |                     d| j                   t          | |g|R i |S )zCreate signature.

        Returns:
            :class:`~celery.signature`:  object for
                this task, wrapping arguments and execution options
                for a single task invocation.
        r8   )r   r8   r   )rI   rJ   starargs
starkwargss       r4   r   zTask.signatureG  s<     	eTX...t=h===*===r6   c                 .    |                      ||          S )zUCreate signature.

        Shortcut for ``.s(*a, **k) -> .signature(a, k)``.
        r   rH   s      r4   szTask.sS  s    
 ~~dF+++r6   c                 2    |                      ||d          S )zpCreate immutable signature.

        Shortcut for ``.si(*a, **k) -> .signature(a, k, immutable=True)``.
        T)	immutabler-  rH   s      r4   sizTask.siZ  s    
 ~~dFd~;;;r6   c                 Z    ddl m}  ||                                 ||| j                  S )z;Create a :class:`~celery.canvas.chunks` task for this task.r   )chunksr8   )celeryr3  r.  r8   )rI   itnr3  s       r4   r3  zTask.chunksa  s7    !!!!!!vdffhhA484444r6   c                 X    ddl m}  ||                                 || j                  S )z7Create a :class:`~celery.canvas.xmap` task from ``it``.r   )xmapr4  )r5  r9  r.  r8   )rI   r6  r9  s      r4   mapzTask.mapf  s5    tDFFHHbdh////r6   c                 X    ddl m}  ||                                 || j                  S )z;Create a :class:`~celery.canvas.xstarmap` task from ``it``.r   )xstarmapr4  )r5  r<  r.  r8   )rI   r6  r<  s      r4   starmapzTask.starmapk  s5    ######x"$(3333r6   c                     | j         }|| j        j        j        }| j        j                            |j                  5 } |j        |f|j        ||d|cddd           S # 1 swxY w Y   dS )a  Send monitoring event message.

        This can be used to add custom event types in :pypi:`Flower`
        and other monitors.

        Arguments:
            type_ (str):  Type of event, e.g. ``"task-failed"``.

        Keyword Arguments:
            retry (bool):  Retry sending the message
                if the connection is lost.  Default is taken from the
                :setting:`task_publish_retry` setting.
            retry_policy (Mapping): Retry settings.  Default is taken
                from the :setting:`task_publish_retry_policy` setting.
            **fields (Any): Map containing information about the event.
                Must be JSON serializable.
        N)r   )r   r  retry_policy)	r   r8   r   task_publish_retry_policyeventsdefault_dispatcherr   sendrt   )rI   type_r  r?  fieldsreqr   s          r4   
send_eventzTask.send_eventp  s    $ l8=BLX_///FF 	O!16OV5|O OGMO O	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	Os    A$$A(+A(c                    | j         j        }d|j        v rt          d          t	          |t
                    r t          |dd          st          d          t	          |t                    r)|| j        j	        d         
                    d          z  }t          | j         j                  pg D ]}|                    |           t          | j         j                  pg D ]}|                    |           t	          |t
                    r\d	|j        v rS|j	        d
         j                            d	g           }|                    t          |j        d	                              |                    | j         j                   | j                             dd          dz   }|                    || j         j        | j         j        | j         j        |           t	          |t
                    r/t          |j	                  pg D ]}|                    |           t1          | j         j        pg           D ]3}t5          || j                  }|                    |           ||z  }4|                     |          S )aK  Replace this task, with a new task inheriting the task id.

        Execution of the host task ends immediately and no subsequent statements
        will be run.

        .. versionadded:: 4.0

        Arguments:
            sig (Signature): signature to replace with.
            visitor (StampingVisitor): Visitor API object.

        Raises:
            ~@Ignore: This is always raised when called in asynchronous context.
            It is best to always use ``return self.replace(...)`` to convey
            to the reader that the task won't continue after being replaced.
        ri   z8A signature replacing a task must not be part of a chordtasksTz"Cannot replace with an empty chainzcelery.accumulater   )indexrk   ro   r   )ri   rf   rg   rd   ro   )ro   r4  )r   ri   r   r   r  r   r[   r   r8   rI  r.  r   ru   rk   rv   rl   r   extendfreezert   r\   setrg   rd   reversedrj   r   
on_replace)	rI   r  ri   callbackerrbackfinal_task_linksro   
chain_taskts	            r4   replacezTask.replace  s   " "ck!!&J   c6"" 	M73+F+F 	M&'KLLL c5!! 	B48>"5688q8AAAC"4<#9::@b 	 	HHHX!$,"788>B 	$ 	$GNN7#### c6"" 	Ev'<'<"y}4??KK##Js{6/B$C$CDDD 	

4<?### $ 0 01H! L Lq P\'0L("7 	 	
 	
 	
 c6"" 	L(339r L L
5JKKKK
 $,,233 	 	A"1$(333JNN1FNGGG:CCs###r6   c                 \   | j         j        st          d          |                    | j         j        | j         j        | j         j        | j         j                   |                                }| j        	                    | j         j        |           |s|
                                n|S )a{  Add signature to the chord the current task is a member of.

        .. versionadded:: 4.0

        Currently only supported by the Redis result backend.

        Arguments:
            sig (Signature): Signature to extend chord with.
            lazy (bool): If enabled the new task won't actually be called,
                and ``sig.delay()`` must be called manually.
        z'Current task is not member of any chord)rf   rg   ri   rd   )r   ri   
ValueErrorrN  r   rg   rd   rM  r'  add_to_chordr   )rI   r  lazyresults       r4   rY  zTask.add_to_chord  s     |! 	HFGGG\'0,$L(	 	 	
 	
 	
 !!$,"4f==="&/syy{{{C/r6   c                 Z    || j         j        } | j        j        |||fd| j         i| dS )zUpdate task state.

        Arguments:
            task_id (str): Id of the task to update.
                Defaults to the id of the current task.
            state (str): New state.
            meta (Dict): State meta-data.
        Nr   )r   rt   r'  store_result)rI   rc   r#  metarK   s        r4   update_statezTask.update_state  s[     ?loG!!T5	B 	B*.,	B:@	B 	B 	B 	B 	Br6   c                     dS )a  Handler called before the task starts.

        .. versionadded:: 5.2

        Arguments:
            task_id (str): Unique id of the task to execute.
            args (Tuple): Original arguments for the task to execute.
            kwargs (Dict): Original keyword arguments for the task to execute.

        Returns:
            None: The return value of this handler is ignored.
        Nr   )rI   rc   rJ   rK   s       r4   before_startzTask.before_start  r   r6   c                     dS )a  Success handler.

        Run by the worker if the task executes successfully.

        Arguments:
            retval (Any): The return value of the task.
            task_id (str): Unique id of the executed task.
            args (Tuple): Original arguments for the executed task.
            kwargs (Dict): Original keyword arguments for the executed task.

        Returns:
            None: The return value of this handler is ignored.
        Nr   )rI   r  rc   rJ   rK   s        r4   
on_successzTask.on_success  r   r6   c                     dS )a  Retry handler.

        This is run by the worker when the task is to be retried.

        Arguments:
            exc (Exception): The exception sent to :meth:`retry`.
            task_id (str): Unique id of the retried task.
            args (Tuple): Original arguments for the retried task.
            kwargs (Dict): Original keyword arguments for the retried task.
            einfo (~billiard.einfo.ExceptionInfo): Exception information.

        Returns:
            None: The return value of this handler is ignored.
        Nr   rI   r  rc   rJ   rK   einfos         r4   on_retryzTask.on_retry  r   r6   c                     dS )a  Error handler.

        This is run by the worker when the task fails.

        Arguments:
            exc (Exception): The exception raised by the task.
            task_id (str): Unique id of the failed task.
            args (Tuple): Original arguments for the task that failed.
            kwargs (Dict): Original keyword arguments for the task that failed.
            einfo (~billiard.einfo.ExceptionInfo): Exception information.

        Returns:
            None: The return value of this handler is ignored.
        Nr   re  s         r4   
on_failurezTask.on_failure!  r   r6   c                     dS )a  Handler called after the task returns.

        Arguments:
            status (str): Current task state.
            retval (Any): Task return value/exception.
            task_id (str): Unique id of the task.
            args (Tuple): Original arguments for the task.
            kwargs (Dict): Original keyword arguments for the task.
            einfo (~billiard.einfo.ExceptionInfo): Exception information.

        Returns:
            None: The return value of this handler is ignored.
        Nr   )rI   statusr  rc   rJ   rK   rf  s          r4   after_returnzTask.after_return1  r   r6   c                     | j         j        r&|                                                                S |                                 t          d          )a  Handler called when the task is replaced.

        Must return super().on_replace(sig) when overriding to ensure the task replacement
        is properly handled.

        .. versionadded:: 5.3

        Arguments:
            sig (Signature): signature to replace with.
        zReplaced by new task)r   r   r   r\   r   r   )rI   r  s     r4   rP  zTask.on_replace@  sE     <  	199;;??$$$IIKKK/000r6   c                 R    | j         r| j        j                            |           |S rD   )trailr   r   r;   )rI   r[  s     r4   	add_trailzTask.add_trailR  s*    : 	1L!((000r6   c                 N    | j                             t          |i |           d S rD   )r   r   r    rH   s      r4   r   zTask.push_requestW  s,     8 8 899999r6   c                 8    | j                                          d S rD   )r   rS   rY   s    r4   r   zTask.pop_requestZ  s         r6   c                 ,    t          | t                    S )z``repr(task)``.)rA   
R_INSTANCErY   s    r4   r`   zTask.__repr__]  s    z***r6   c                 d    | j         j        }|!| j        t                      | _        | j        S |S )zGet current request object.)r   top_default_requestr    )rI   rF  s     r4   _get_requestzTask._get_requesta  s7     $; $,(/		%((
r6   c                 F    | j         t          |           | _         | j         S rD   )r   extract_exec_optionsrY   s    r4   r   zTask._get_exec_optionsm  s$    %!5d!;!;D!!r6   c                 0    | j         }|| j        j        S |S rD   )_backendr8   r'  )rI   r'  s     r4   r'  zTask.backendr  s    -?8##r6   c                     || _         d S rD   )r|  )rI   r   s     r4   r'  zTask.backendy  s    r6   c                     | j         j        S rD   )	__class__r   rY   s    r4   r   zTask.__name__}  s    ~&&r6   )NNNNNNN)NNNN)NNNTNNN)
NNNNNNNNNNrD   )TN)F)NNN)Ur   r   r   r   	__trace__r:   r   r   r   Requestr<   r   r   r  r  r   r   ro  send_eventsr   r'   r*   r+   r'  r   r   r   r   throwsr&   r%   resultrepr_maxsizer   rw  r   r   r   r   r|  classmethodr   r   r   r   r8   r   r   r   r   r   r   r   r   r   r  subtask_from_requestr  r   r   r   subtaskr.  r1  r3  r:  r=  rG  rV  rY  r_  ra  rc  rg  ri  rl  rP  rp  r   r   r`   rx  r   r   r   setterr   r6   r4   r!   r!      s         IM5' 0H .G D D F K !
 J
 M
 E K $(  J J O G M I "& ! F G H  M  HMIK H
   [2   [   [ .4
(
(C- - [- ! ! [!  ; ; ;G G GI I I. . . JN7;Y Y Y Yv  * FJ%)
 
 
 
. 2<@48o o o ob '+$(0437DQ DQ DQ DQLJ J J	> 	> 	> 	> G, , ,< < <5 5 5
0 0 0
4 4 4
O O O O4B$ B$ B$H0 0 0 00B B B B            1 1 1$  
: : :! ! !+ + +	 	 	 h|$$G" " "
   X ^  ^ ' ' X' ' 'r6   r!   )r.   rb   )?r   r   billiard.einfor   r   kombur   kombu.exceptionsr   kombu.utils.uuidr   r5  r   r	   celery._stater
   celery.canvasr   r   r   celery.exceptionsr   r   r   r   r   celery.localr   celery.resultr   r   celery.utilsr   celery.utils.functionalr   r   celery.utils.importsr   celery.utils.nodenamesr   celery.utils.serializationr   r   r   r   registryr   utilsr   __all__rz  r=   r>   rt  r   TaskTyper5   rA   r    CallableTaskregisterr!   BaseTaskr   r6   r4   <module>r     s   C C 



 @ @ @ @ @ @ @ @       - - - - - - ! ! ! ! ! ! & & & & & & & & % % % % % % 2 2 2 2 2 2 2 2 2 2 b b b b b b b b b b b b b b ' ' ' ' ' ' 9 9 9 9 9 9 9 9 ! ! ! ! ! ! ; ; ; ; ; ; ; ; , , , , , , . . . . . . 9 9 9 9 9 9 ? ? ? ? ? ? ' ' ' ' ' '      
 #{]J
I/=,{K   600
       d d d d d d d dN 
[' [' [' [' [' [' ['  ['| r6   