
    &`i~                         d dl Z d dlZd dlmZmZ d dlmZ erd dlmZ dZ	dZ
dZ G d d	          Zd
eddfdZd
edee         fdZded
efdZded
efdZdS )    N)TYPE_CHECKINGList)DataContext)StreamingExecutorexecution_callbacksRAY_DATA_EXECUTION_CALLBACKS_env_callbacks_initializedc                   :    e Zd ZdZd
dZd
dZd
dZdddefdZd	S )ExecutionCallbackz(Callback interface for execution events.executorr   c                     dS )z+Called before the Dataset execution starts.N selfr   s     /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/data/_internal/execution/execution_callback.pybefore_execution_startsz)ExecutionCallback.before_execution_starts           c                     dS )z2Called at each step of the Dataset execution loop.Nr   r   s     r   on_execution_stepz#ExecutionCallback.on_execution_step   r   r   c                     dS )z,Called after the Dataset execution succeeds.Nr   r   s     r   after_execution_succeedsz*ExecutionCallback.after_execution_succeeds   r   r   errorc                     dS )z)Called after the Dataset execution fails.Nr   )r   r   r   s      r   after_execution_failsz'ExecutionCallback.after_execution_fails   r   r   N)r   r   )	__name__
__module____qualname____doc__r   r   r   	Exceptionr   r   r   r   r   r      sy        22         .A )      r   r   contextreturnc                    t           j                            t          d          }|sdS |                    d          D ]}|                                }|s	 |                    dd          \  }}t          j        |          }t          ||          } |            }t          ||            r# t          t          t          f$ r}t          d| d|           d}~ww xY wdS )zKInitialize callbacks from environment variable and add them to the context. N,.   z Failed to import callback from 'z': )osenvirongetEXECUTION_CALLBACKS_ENV_VARsplitstriprsplit	importlibimport_modulegetattradd_execution_callbackImportErrorAttributeError
ValueError)	r!   callbacks_strcallback_pathmodule_path
class_namemodulecallback_clscallbackes	            r   _initialize_env_callbacksr>   #   s   JNN#>CCM &,,S11 W W%++-- 		W&3&:&:3&B&B#K,[99F"6:66L#|~~H"8W5555^Z8 	W 	W 	WUUURSUUVVV	WW Ws   AB11C"CC"c                     |                      t          d          s*t          |            |                     t          d           ddlm} |                      t           |            g          S )z0Get all ExecutionCallbacks from the DataContext.FTr   )IssueDetectionExecutionCallback)
get_configENV_CALLBACKS_INITIALIZED_KEYr>   
set_config=ray.data._internal.execution.callbacks.insert_issue_detectorsr@   EXECUTION_CALLBACKS_CONFIG_KEY)r!   r@   s     r   get_execution_callbacksrF   8   s     ;UCC @!'***8$???      &)H)H)J)J(K  r   r<   c                     |                     t          g           }|                    |            |                    t          |           dS )z,Add an ExecutionCallback to the DataContext.N)rA   rE   appendrC   r<   r!   r   s      r   r2   r2   H   K    !,,-KRPPx(((57JKKKKKr   c                     |                     t          g           }|                    |            |                    t          |           dS )z1Remove an ExecutionCallback from the DataContext.N)rA   rE   removerC   rI   s      r   remove_execution_callbackrM   O   rJ   r   )r/   r(   typingr   r   ray.data.contextr   /ray.data._internal.execution.streaming_executorr   rE   r+   rB   r   r>   rF   r2   rM   r   r   r   <module>rQ      sG       				 & & & & & & & & ( ( ( ( ( ( RQQQQQQ!6 <  <        (W{ Wt W W W W*[ T:K5L     L%6 L L L L LL(9 LK L L L L L Lr   