o
    wOiO
                     @   s   d dl Z d dlmZmZmZ d dlmZ d dlmZm	Z	m
Z
 e
eeeedf ZG dd deeZeG dd dZeG d	d
 d
ZdS )    N)asdict	dataclassfield)Enum)DictOptionalUnionc                   @   s   e Zd ZdZdZdZdS )EventSourcez3
    Known identifiers of the event producers.
    AGENTWORKERN)__name__
__module____qualname____doc__r
   r    r   r   K/home/ubuntu/.local/lib/python3.10/site-packages/torchelastic/events/api.pyr	      s    r	   c                   @   s|   e Zd ZU dZeed< eed< dZeed< e	e
dZeeef ed< dd	 Zed
eed f dd fddZdefddZdS )Eventa{  
    The class represents the generic event that occurs during the torchelastic
    job execution. The event can be any kind of meaningful action.

    Args:
        name: event name.
        source: the event producer, e.g. agent or worker
        timestamp: timestamp in milliseconds when event occured.
        metadata: additional data that is associated with the event.
    namesourcer   	timestamp)default_factorymetadatac                 C      |   S N	serializeselfr   r   r   __str__-      zEvent.__str__datareturnc                 C   s@   t | tr| S t | trt| }t|d  |d< tdi |S )Nr   r   )
isinstancer   strjsonloadsr	   r    	data_dictr   r   r   deserialize0   s   


zEvent.deserializec                 C      t t| S r   r$   dumpsr   r   r   r   r   r   9      zEvent.serializeN)r   r   r   r   r#   __annotations__r	   r   intr   dictr   r   EventMetadataValuer   staticmethodr   r(   r   r   r   r   r   r      s   
 r   c                   @   s   e Zd ZU dZeed< eed< eed< eed< eed< dZee ed< dZee ed	< dZ	ee ed
< dd Z
edeed f dd fddZdefddZdS )TsmEventa  
    The class represents the event produced by tsm api calls.

    Arguments:
        session: Session id that was used to execute request.
        scheduler: Scheduler that is used to execute request
        api: Api name
        unix_user: Unix user that executes request
        source_hostname: Hostname of server that executes request
        app_id: Unique id that is set by the underlying scheduler
        runcfg: Run config that was used to schedule app.
    session	schedulerapi	unix_usersource_hostnameNapp_idruncfgraw_exceptionc                 C   r   r   r   r   r   r   r   r   U   r   zTsmEvent.__str__r    r!   c                 C   s0   t | tr| S t | trt| }tdi |S )Nr   )r"   r2   r#   r$   r%   r&   r   r   r   r(   X   s
   


zTsmEvent.deserializec                 C   r)   r   r*   r   r   r   r   r   a   r,   zTsmEvent.serialize)r   r   r   r   r#   r-   r8   r   r9   r:   r   r1   r   r(   r   r   r   r   r   r2   =   s   
 r2   )r$   dataclassesr   r   r   enumr   typingr   r   r   r#   r.   floatboolr0   r	   r   r2   r   r   r   r   <module>   s   	!