
    Ji3
                        U d dl mZ d dlZd dlZd dlmZmZ d dlmZm	Z	 d dl
mZmZ d dlmZmZmZ d dlmZ d dlmZ d d	lmZ  G d
 d      Z e       Zded<    G d d      Zy)    )annotationsN)AsyncGeneratorCallable)PR)Event	StopEvent)PluginSnapshottableRuntimeWorkflowRuntime)StepWorkerFunction)WorkflowTick)Workflowc                  ,    e Zd Z	 	 	 	 	 	 	 	 ddZddZy)BasicRuntimec                     y N )selfworkflowworkflow_functionstepss       i/var/www/html/BankruptcyAI-uat/bankruptcy-ai/venv/lib/python3.12/site-packages/workflows/plugins/basic.pyregisterzBasicRuntime.register   s     	    c                    t        |      }|S r   )AsyncioWorkflowRuntime)r   run_idsnapshottables      r   new_runtimezBasicRuntime.new_runtime   s    .DV.Lr   N)r   r   r   Callable[P, R]r   z dict[str, StepWorkerFunction[R]]returnNone)r   strr"   r   )__name__
__module____qualname__r   r    r   r   r   r   r      s2     * 0	
 
r   r   r
   basic_runtimec                      e Zd ZdZ	 	 	 	 ddZddZddZddZddZddZ	ddZ
	 	 	 	 	 	 dd	Z	 	 	 	 dd
ZddZddZddZy)r   z
    A plugin interface to switch out a broker runtime (external library or service that manages durable/distributed step execution)
    c                    || _         t        j                         | _        t        j                         | _        g | _        y r   )r   asyncioQueuereceive_queuepublish_queueticks)r   r   s     r   __init__zAsyncioWorkflowRuntime.__init__(   s.     :A--/3:==?)+
r   c                :    | j                   j                  |       y r   )r/   appendr   ticks     r   on_tickzAsyncioWorkflowRuntime.on_tick1   s    

$r   c                    | j                   S r   )r/   r   s    r   replayzAsyncioWorkflowRuntime.replay4   s    zzr   c                R   K   | j                   j                          d {   S 7 wr   )r-   getr7   s    r   wait_receivez#AsyncioWorkflowRuntime.wait_receive7   s!     ''++----s   '%'c                B   K   | j                   j                  |       y wr   )r.   
put_nowait)r   events     r   write_to_event_streamz,AsyncioWorkflowRuntime.write_to_event_stream:   s     %%e,   c                  K   	 | j                   j                          d {   }| t        |t              ry 97 wr   )r.   r:   
isinstancer	   )r   items     r   stream_published_eventsz.AsyncioWorkflowRuntime.stream_published_events=   s:     ++//11DJ$	*	 1s   ?=?c                B   K   | j                   j                  |       y wr   )r-   r=   r3   s     r   
send_eventz!AsyncioWorkflowRuntime.send_eventD   s     %%d+r@   c                   K   |S wr   r   )r   	step_namestep_workers      r   register_step_workerz+AsyncioWorkflowRuntime.register_step_workerG   s         c                   K   |S wr   r   )r   r   s     r   register_workflow_functionz1AsyncioWorkflowRuntime.register_workflow_functionL   s      ! rK   c                2   K   t        j                         S wr   )time	monotonicr7   s    r   get_nowzAsyncioWorkflowRuntime.get_nowQ   s     ~~s   c                J   K   t        j                  |       d {    y 7 wr   )r+   sleep)r   secondss     r   rS   zAsyncioWorkflowRuntime.sleepT   s     mmG$$$s   #!#c                   K   y wr   r   r7   s    r   closezAsyncioWorkflowRuntime.closeW   s	     s   N)r   r$   r"   r#   )r4   r   r"   r#   )r"   zlist[WorkflowTick])r"   r   )r>   r   r"   r#   )r"   zAsyncGenerator[Event, None])rH   r$   rI   StepWorkerFunction[R]r"   rW   )r   r!   r"   r!   )r"   float)rT   rX   r"   r#   )r"   r#   )r%   r&   r'   __doc__r0   r5   r8   r;   r?   rD   rF   rJ   rM   rQ   rS   rV   r   r   r   r   r   #   s}    ,, 
, .-,+@	
!!/!	!
 %r   r   )
__future__r   r+   rO   typingr   r   workflows.decoratorsr   r   workflows.eventsr   r	   workflows.runtime.types.pluginr
   r   r   %workflows.runtime.types.step_functionr   workflows.runtime.types.ticksr   workflows.workflowr   r   r(   __annotations__r   r   r   r   <module>rc      sJ    #   + % - X X D 6 '  %v &5 5r   