
    h                     .    d dl Z d dlmZ  G d de      Zy)    N)StatelessServerc                   0     e Zd ZdZd fd	Zd Zd Z xZS )Workerz
    ASGI protocol server that surfaces events sent to specific channels
    on the channel layer into a single application instance.
    c                 p    t         |   ||       || _        || _        | j                  t	        d      y )NzChannel layer is not valid)super__init__channelschannel_layer
ValueError)selfapplicationr	   r
   max_applications	__class__s        K/var/www/Befach/backend/env/lib/python3.12/site-packages/channels/worker.pyr   zWorker.__init__   s?    &67 *%9:: &    c                   K   g }| j                   D ]5  }|j                  t        j                  | j	                  |                   7 t        j
                  |       d{    |D cg c]  }|j                          c} y7 #c c}w w)zP
        Listens on all the provided channels and handles the messages.
        N)r	   appendasyncioensure_futurelistenerwaitresult)r   	listenerschannelr   s       r   handlezWorker.handle   sn     
 	}}GW224==3IJK % ll9%%%+45x	5 	&5s$   AB!B"B*BBBc                    K   	 | j                   j                  |       d{   }|j                  dd      st        d      d|d}| j	                  ||      }|j                  |       d{    q7 R7 w)z)
        Single-channel listener
        Ntypez%Worker received message with no type.r   )r   r   )r
   receivegetr   "get_or_create_application_instanceput)r   r   messagescopeinstance_queues        r   r   zWorker.listener    s|       ..66w??G;;vt, !HII&7;E!DDWeTN $$W--- ? .s"    A9A5AA9/A70A97A9)i  )__name__
__module____qualname____doc__r   r   r   __classcell__)r   s   @r   r   r      s    
;6.r   r   )r   asgiref.serverr   r    r   r   <module>r,      s     *&._ &.r   