
    i|*                        d dl mZ d dlZd dlZd dlZd dlZd dlZd dlm	Z	m
Z
mZmZmZmZ ej         G d d                      Z G d dej                  Z G d d	ej        ej                           ZdS )
    )annotationsN)
client_liberrorsexecution_libmiddleware_lib
server_libtypesc                  $    e Zd ZU ded<   ded<   dS )_Configzserver_lib.FunctionConfigmainz server_lib.FunctionConfig | None
on_failureN)__name__
__module____qualname____annotations__     W/root/projects/qq-shell/venv/lib/python3.11/site-packages/inngest/_internal/function.pyr   r      s.          $### 100000r   r   c                      e Zd ZU  ej        d          Zded<   ded<   ded<   d	ed
<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   d%d#Zd$S )&FunctionOptsT)arbitrary_types_allowedzserver_lib.Batch | Nonebatch_eventszlist[server_lib.Cancel] | Nonecancelz#list[server_lib.Concurrency] | Noneconcurrencyzserver_lib.Debounce | Nonedebouncestrfully_qualified_id
str | Noneidempotencylocal_idnamezeexecution_lib.FunctionHandlerAsync[typing.Any] | execution_lib.FunctionHandlerSync[typing.Any] | Noner   zserver_lib.Priority | Nonepriorityzserver_lib.RateLimit | None
rate_limitz
int | Noneretrieszserver_lib.Throttle | Nonethrottlezserver_lib.Timeouts | Nonetimeoutszserver_lib.Singleton | None	singletonerrpydantic.ValidationErrorreturnBaseExceptionc                @    t           j                            |          S N)r   FunctionConfigInvalidErrorfrom_validation_error)selfr(   s     r   convert_validation_errorz%FunctionOpts.convert_validation_error:   s     0FFsKKKr   N)r(   r)   r*   r+   )r   r   r   pydantic
ConfigDictmodel_configr   r1   r   r   r   r   r      s        &8&tDDDL))))****4444((((  MMMIII   
 )(((++++((((((((****L L L L L Lr   r   c                     e Zd ZU ded<   dZded<   ded<   ded	<   ed,d            Zed-d            Zed.d            Zed,d            Z	ed,d            Z
ed/d            Zej        dfd0dZd1d%Zd2d'Zd3d*Zd,d+ZdS )4FunctionXexecution_lib.FunctionHandlerAsync[types.T] | execution_lib.FunctionHandlerSync[types.T]_handlerNr   _on_failure_fn_idr   _optsz6list[server_lib.TriggerCron | server_lib.TriggerEvent]	_triggersr*   r   c                    | j         j        S r-   r:   r   r0   s    r   idzFunction.idJ   s    z,,r   boolc                4    t          j        | j                  S )z"Whether the main handler is async.)inspectiscoroutinefunctionr8   r>   s    r   is_handler_asynczFunction.is_handler_asyncN   s     *4=999r   bool | Nonec                Z    | j         j        dS t          j        | j         j                  S )zu
        Whether the on_failure handler is async. Returns None if there isn't an
        on_failure handler.
        N)r:   r   rB   rC   r>   s    r   is_on_failure_handler_asyncz$Function.is_on_failure_handler_asyncS   s*     : (4*4:+@AAAr   c                    | j         j        S r-   )r:   r    r>   s    r   r    zFunction.local_id]   s    z""r   c                    | j         j        S r-   )r:   r!   r>   s    r   r!   zFunction.namea   s    zr   c                    | j         S r-   )r9   r>   s    r   on_failure_fn_idzFunction.on_failure_fn_ide   s    %%r   optstriggeriserver_lib.TriggerCron | server_lib.TriggerEvent | list[server_lib.TriggerCron | server_lib.TriggerEvent]handleroutput_typeobject
middleware3list[middleware_lib.UninitializedMiddleware] | NoneNonec                h   || _         |pg | _        || _        || _        t	          |t
                    r|n|g| _        |j        m| j        r&| j	        du rt          j        d|j         d          | j        du r&| j	        du rt          j        d|j         d          |j         d| _        d S d S )NFzGan async function cannot have a non-async on_failure handler (function )TzGa non-async function cannot have an async on_failure handler (function z-failure)r8   _middlewarer:   _output_type
isinstancelistr;   r   rD   rG   r   Errorr    r   r9   )r0   rL   rM   rO   rP   rR   s         r   __init__zFunction.__init__i   s      %+
'$.w$=$=LG9?&%4==ln^b^knnn   %..4<<ln^b^knnn   )-(?%I%I%ID"""! '&r   clientclient_lib.Inngestctxexecution_lib.Contextfn_id middleware_lib.MiddlewareManagerexecution_lib.CallResultc                |  K   | j         D ]}|                    |           | j        |k    r| j        }| j        }nw| j        |k    rF| j        j        &t          j	        t          j        d                    S | j        j        }t          }n&t          j	        t          j        d                    S t          j        |          st          j        d          t          j        |j                  5  |j        j                            |||| |           d {V }d d d            n# 1 swxY w Y   |                    |           d {V }	t)          |	t*                    rt          j	        |	          S |                                 d {V }	t)          |	t*                    rt          j	        |	          S |S )Non_failure not definedfunction ID mismatchzhandler is not async)rW   addr?   r8   rX   rK   r:   r   r   
CallResultr   FunctionNotFoundErrorrQ   is_function_handler_asyncUnreachableErrorset_step_contextstep
_executionruntransform_outputrY   	Exceptionbefore_response
r0   r]   r_   ra   rR   mrO   rP   call_resr(   s
             r   callzFunction.call   s/      ! 	 	ANN17emG+KK"e++z$,$/01IJJ   j+G
 !KK +,-CDD   6w?? 	B)*@AAA+CH55 	 	 X044       H	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 //99999999c9%% 	1 +C000..00000000c9%% 	1 +C000s   4*D**D.1D.execution_lib.ContextSyncc                T   | j         D ]}|                    |           | j        |k    r| j        }| j        }nw| j        |k    rF| j        j        &t          j	        t          j        d                    S | j        j        }t          }n&t          j	        t          j        d                    S t          j        |          st          j        d          t          j        |j                  5  |j        j                            |||| |          }d d d            n# 1 swxY w Y   |                    |          }	t)          |	t*                    rt          j	        |	          S |                                }	t)          |	t*                    rt          j	        |	          S |S )Nre   rf   zhandler is not sync)rW   rg   r?   r8   rX   rK   r:   r   r   rh   r   ri   rQ   is_function_handler_syncrk   rl   rm   rn   ro   transform_output_syncrY   rq   before_response_syncrs   s
             r   	call_synczFunction.call_sync   s    ! 	 	ANN17emG+KK"e++z$,$/01IJJ   j+G
 !KK +,-CDD   5g>> 	A)*?@@@+CH55 		 		 x*.. H		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 ..x88c9%% 	1 +C000--//c9%% 	1 +C000s   2$D""D&)D&app_urlr   c                   | j         j        }| j         j        }| j         j         t	          j        | j         j                  }nd }|dz   t          j                            |t          j	        d          z   }d}|
                    d          rd}t	          j        | j         j        | j         j        | j         j        | j         j        || j         j        || j         j        | j         j        t          j	        t	          j        t          j	        t          j	        |t	          j        ||                    i| j         j        | j         j        | j        | j         j        	          }d }| j        |dz   t          j                            | j        t          j	        d          z   }t	          j        d g g d | j        d | d
d d t          j	        t	          j        t          j	        t          j	        t	          j        d          t	          j        d|                    id d t	          j        t          j        j        j        d| j         d          gd 	          }t?          ||          S )N)attempts?)fnIdstepIdhttpzwss://ws)typeurl)r?   r!   r$   runtime)r   r   r   r   r?   r   r!   r"   r#   stepsr%   r&   triggersr'   z
 (failure)r   zevent.data.function_id == '')event
expression)r   r   ) r:   r   r!   r$   r   Retriesurllibparse	urlencodeROOT_STEP_ID
startswithFunctionConfigr   r   r   r   r   r"   r#   StepRuntimer%   r&   r;   r'   rK   TriggerEventInternalEventsFUNCTION_FAILEDvaluer?   r   )	r0   r}   ra   r!   r$   r   runtime_typer   r   s	            r   
get_configzFunction.get_config   s   
-z:) ($*2DEEEGGG l$$!(5   	 6<>>(## 	 L(0:$
.Z(
.Z(z,'!.#0#&.)  	* * *
 Z(Z(^j*1
 
 
6 
 ,,(( $ 5","9    $2!( (((+Z_%2'4 * 2A > > > * 2!' #! ! !	. . .
 +(7GM#K#K#K#K   ;  J@ DZ8888r   c                    | j         j        S r-   r=   r>   s    r   get_idzFunction.get_idV  s    z,,r   )r*   r   )r*   r@   )r*   rE   )r*   r   )rL   r   rM   rN   rO   r7   rP   rQ   rR   rS   r*   rT   )
r]   r^   r_   r`   ra   r   rR   rb   r*   rc   )
r]   r^   r_   rw   ra   r   rR   rb   r*   rc   )r}   r   r*   r   )r   r   r   r   r9   propertyr?   rD   rG   r    r!   rK   r	   EmptySentinelr\   rv   r|   r   r   r   r   r   r6   r6   A   s            %)((((EEEE- - - X- : : : X: B B B XB # # # X#    X & & & X& $1JN!J !J !J !J !JF1 1 1 1f3 3 3 3j`9 `9 `9 `9D- - - - - -r   r6   )
__future__r   dataclassesrB   typingurllib.parser   r2   inngest._internalr   r   r   r   r   r	   	dataclassr   	BaseModelr   GenericTr6   r   r   r   <module>r      sN   " " " " " "                           1 1 1 1 1 1 1 1!L !L !L !L !L5? !L !L !LHV- V- V- V- V-v~eg& V- V- V- V- V-r   