ó
    Ú°›jO  ã                   ób  • S r SSKrSSKrSSKrSSKrSSKJrJrJrJ	r	  SSK
Jr  \" 5       r\R                  " 5       r\R                  R!                  S\" \R$                  " 5       5      5      rSr\R                  R!                  SS5      SL r " S	 S
5      r " S S\	\   5      r " S S5      rg)z]
Handles getting stuff from environment variables and updating the global state like job id.
é    N)ÚAnyÚDictÚOptionalÚSeté   )ÚRunPodLoggerÚRUNPOD_POD_IDi   ÚRUNPOD_WEBHOOK_GET_JOBc            	       ó~   • \ rS rSrSr  SS\S\\\\4      S\\   SS4S jjr	S	\
S\4S
 jrS\4S jrS\4S jrSrg)ÚJobé   zª
Represents a job object.

Args:
    job_id: The id of the job, a unique string.
    job_input: The input to the job.
    webhook: The webhook to send the job output to.
NÚidÚinputÚwebhookÚreturnc                 ór   • Xl         X l        X0l        UR                  5        H  u  pV[	        XU5        M     g ©N)r   r   r   ÚitemsÚsetattr)Úselfr   r   r   ÚkwargsÚkeyÚvalues          Úc/home/mande/repo/quber/.venv/lib/python3.13/site-packages/runpod/serverless/modules/worker_state.pyÚ__init__ÚJob.__init__&   s/   € ð ŒØŒ
ØŒà Ÿ,™,ž.‰JˆCÜ�D˜uÖ%ò )ó    Úotherc                 ó`   • [        U[        5      (       a  U R                  UR                  :H  $ g)NF)Ú
isinstancer   r   )r   r   s     r   Ú__eq__Ú
Job.__eq__4   s%   € Ü�eœS×!Ñ!Ø—7‘7˜eŸh™hÑ&Ð&Ør   c                 ó,   • [        U R                  5      $ r   )Úhashr   ©r   s    r   Ú__hash__ÚJob.__hash__9   s   € Ü�D—G‘G‹}Ðr   c                 ó   • U R                   $ r   ©r   r%   s    r   Ú__str__ÚJob.__str__<   s   € Ø�w‰wˆr   )r   r   r   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ústrr   r   r   r   ÚobjectÚboolr!   Úintr&   r*   Ú__static_attributes__© r   r   r   r      sv   † ñð +/Ø!%ñ	&àð&ð ˜˜S #˜X™Ñ'ð&ð ˜#‘ð	&ð 
õ&ð˜Fð  tô ð
˜#ô ð˜÷ r   r   c                   óÄ   ^ • \ rS rSrSrSrS rS rS\4S jr	SS jr
SS	 jrSU 4S
 jjrS\4U 4S jjrS\4U 4S jjrS\S\\   4S jrS\\   4S jrS\4S jrSrU =r$ )ÚJobsProgresséC   zETrack the state of current jobs in progress (in-memory, per process).Nc                 óð   • [         R                  cV  [        R                  U 5      [         l        [        R	                  [         R                  5        S [         R                  l        [         R                  $ r   )r8   Ú	_instanceÚsetÚ__new__r   Ú_mirror)Úclss    r   r=   ÚJobsProgress.__new__H   sM   € Ü×!Ñ!Ñ)Ü%(§[¡[°Ó%5ŒLÔ"Ü�L‰Lœ×/Ñ/Ô0ð .2ŒL×"Ñ"Ô*Ü×%Ñ%Ð%r   c                 ó   • g r   r6   r%   s    r   r   ÚJobsProgress.__init__Q   s   € àr   r   c                 óV   • SU R                   R                   SU R                  5        3$ )NÚ<z>: )Ú	__class__r,   Úget_job_listr%   s    r   Ú__repr__ÚJobsProgress.__repr__U   s*   € Ø�4—>‘>×*Ñ*Ð+¨3¨t×/@Ñ/@Ó/BÐ.CÐDÐDr   c                 ó0   • Xl         U R                  5         g)z‡Attach a PingJobMirror that mirrors the in-progress job ids to the
ping process. Every add/remove/clear then pushes the snapshot to it.N)r>   Ú_notify_mirror)r   Úmirrors     r   Ú
set_mirrorÚJobsProgress.set_mirrorX   s   € ð ŒØ×ÑÕr   c                 ór   • U R                   b*  U R                   R                  U R                  5       5        gg)z@Push the current job-id snapshot to the attached mirror, if any.N)r>   r<   rF   r%   s    r   rJ   ÚJobsProgress._notify_mirror^   s,   € à�<‰<Ñ#Ø�L‰L×Ñ˜T×.Ñ.Ó0Õ1ð $r   c                 óB   >• [         TU ]  5         U R                  5         g r   )ÚsuperÚclearrJ   )r   rE   s    €r   rR   ÚJobsProgress.clearc   s   ø€ Ü‰‰ŒØ×ÑÕr   Úelementc                 ó  >• [        U[        5      (       a	  [        US9n[        U[        5      (       a  [        S0 UD6n[        U[        5      (       d  [	        S5      e[
        TU ]  U5      nU R                  5         U$ )z£
Adds a Job object to the set.

If the added element is a string, then `Job(id=element)` is added.
If the added element is a dict, then `Job(**element)` is added.
r)   z.Only Job objects can be added to JobsProgress.r6   )r    r1   r   ÚdictÚ	TypeErrorrQ   ÚaddrJ   ©r   rT   ÚresultrE   s      €r   rX   ÚJobsProgress.addg   sk   ø€ ô �gœs×#Ñ#Ü˜W‘oˆGä�gœt×$Ñ$Ü‘n˜G‘nˆGä˜'¤3×'Ñ'ÜÐLÓMÐMä‘‘˜WÓ%ˆØ×ÑÔØˆr   c                 ó  >• [        U[        5      (       a	  [        US9n[        U[        5      (       a  [        S0 UD6n[        U[        5      (       d  [	        S5      e[
        TU ]  U5      nU R                  5         U$ )z 
Removes a Job object from the set.

If the element is a string, then `Job(id=element)` is removed.
If the element is a dict, then `Job(**element)` is removed.
r)   z2Only Job objects can be removed from JobsProgress.r6   )r    r1   r   rV   rW   rQ   ÚdiscardrJ   rY   s      €r   ÚremoveÚJobsProgress.remove{   sk   ø€ ô �gœs×#Ñ#Ü˜W‘oˆGä�gœt×$Ñ$Ü‘n˜G‘nˆGä˜'¤3×'Ñ'ÜÐPÓQÐQä‘‘ Ó)ˆØ×ÑÔØˆr   c                 ó¤   • [        U[        5      (       a	  [        US9n[        U[        5      (       d  [        S5      eU  H  nX!:X  d  M
  Us  $    g )Nr)   z4Only Job objects can be retrieved from JobsProgress.)r    r1   r   rW   )r   rT   Újobs      r   ÚgetÚJobsProgress.get�   sJ   € Ü�gœs×#Ñ#Ü˜W‘oˆGä˜'¤3×'Ñ'ÜÐRÓSÐSãˆCØ�~Ø’
ñ ð r   c                 óT   • [        U 5      (       d  gSR                  S U  5       5      $ )zL
Returns the list of job IDs as a comma-separated string, or None if empty.
NÚ,c              3   ó8   #   • U  H  n[        U5      v •  M     g 7fr   )r1   )Ú.0ra   s     r   Ú	<genexpr>Ú,JobsProgress.get_job_list.<locals>.<genexpr>¢   s   é € Ð1ªD Sœ˜CŸ˜ªDùs   ‚)ÚlenÚjoinr%   s    r   rF   ÚJobsProgress.get_job_list›   s%   € ô �4�y‰yØà�x‰xÑ1©DÓ1Ó1Ð1r   c                 ó   • [        U 5      $ )z
Returns the number of jobs.
)rj   r%   s    r   Úget_job_countÚJobsProgress.get_job_count¤   s   € ô �4‹yÐr   )r>   )r   N)r,   r-   r.   r/   r0   r;   r=   r   r1   rG   rL   rJ   rR   r   rX   r^   r   r   rb   rF   r4   rn   r5   Ú__classcell__)rE   s   @r   r8   r8   C   s‚   ø† ÙOà€Iò&òðE˜#ô Eôô2÷
ð˜3÷ ð(˜c÷ ð(
˜3ð 
 8¨C¡=ô 
ð2˜h s™mô 2ð˜s÷ ò r   r8   c                   óZ   • \ rS rSrSr\S4S\4S jjrS\\	   SS4S jr
S\\	   4S	 jrS
rg)ÚPingJobMirroré®   aâ  
One-way snapshot of in-progress job ids from the worker (main) process to
the separate ping process.

Backed by a fixed-size shared-memory buffer created in the main process and
passed to the ping process via ``Process(args=...)``. It lives only in this
worker's own process tree, so it cannot be shared across workers and never
touches the filesystem. All operations are best-effort and never raise into
the caller (a failure here must not break job processing or kill the ping).
NÚcapacityc                 ó\   • U=(       d    [         nXl        UR                  SU5      U l        g )NÚc)ÚmultiprocessingÚ	_capacityÚArrayÚ_buffer)r   rt   Úctxs      r   r   ÚPingJobMirror.__init__º   s#   € Ø×$”_ˆØ!ŒØ—y‘y  hÓ/ˆ�r   Újob_idsr   c                 óÐ  •  U=(       d    SR                  S5      nU R                  S-
  n[        U5      U:”  a:  USU nUR                  S5      nUS:w  a  USU n[        R                  SU S35        U R                  R                  5          X R                  l        SSS5        g! , (       d  f       g= f! [         a"  n[        R                  S	U 35         SnAgSnAff = f)
z=Write the current job-id snapshot. Best-effort; never raises.Ú úutf-8r   Nó   ,éÿÿÿÿz(PingJobMirror: job-id snapshot exceeded z bytes; truncatedzPingJobMirror.set failed: )Úencoderx   rj   ÚrfindÚlogÚwarnrz   Úget_lockr   Ú	ExceptionÚerror)r   r}   ÚdataÚlimitÚcutÚerrs         r   r<   ÚPingJobMirror.set¿   sÇ   € ð	:Ø—M˜r×)Ñ)¨'Ó2ˆDØ—N‘N QÑ&ˆEÜ�4‹y˜5Ó Ø˜F˜U�|�Ø—j‘j Ó&�Ø˜"“9Ø  ˜:�DÜ—‘Ø>¸u¸gÐEVÐWôð —‘×&Ñ&Õ(Ø%)—‘Ô"÷ )×(Ö(ûäó 	:Ü�I‰IÐ2°3°%Ð8×9Ñ9ûð	:ús6   ‚BB9 ÂB(ÂB9 Â(
B6Â2B9 Â6B9 Â9
C%ÃC Ã C%c                 ó.  •  U R                   R                  5          U R                   R                  nSSS5        WR                  S5      nU=(       d    S$ ! , (       d  f       N*= f! [         a"  n[
        R                  SU 35         SnAgSnAff = f)z<Read the current job-id snapshot. Best-effort; never raises.Nr€   zPingJobMirror.get failed: )rz   r‡   r   Údecoderˆ   r…   Údebug)r   rŠ   Útextr�   s       r   rb   ÚPingJobMirror.getÑ   st   € ð	Ø—‘×&Ñ&Õ(Ø—|‘|×)Ñ)�÷ )à—;‘;˜wÓ'ˆDØ—<˜4Ð÷ )Õ(ûô ó 	Ü�I‰IÐ2°3°%Ð8Ô9Üûð	ús-   ‚A( œA³#A( Á
A%Á!A( Á(
BÁ2BÂB)rz   rx   )r,   r-   r.   r/   r0   ÚPING_MIRROR_CAPACITYr4   r   r   r1   r<   rb   r5   r6   r   r   rr   rr   ®   sA   † ñ	ð (<Àñ 0 õ 0ð
:˜8 C™=ð :¨Tô :ð$	�X˜c‘]÷ 	r   rr   )r0   rw   ÚosÚtimeÚuuidÚtypingr   r   r   r   Ú	rp_loggerr   r…   Úperf_counterÚREF_COUNT_ZEROÚenvironrb   r1   Úuuid4Ú	WORKER_IDr”   ÚIS_LOCAL_TESTr   r8   rr   r6   r   r   Ú<module>r       s¡   ðñó Û 	Û Û ß +Ó +å #ñ ƒn€à×"Ò"Ó$€à�J‰J�N‰N˜?©C°·
²
³Ó,=Ó>€	àÐ ð —
‘
—‘Ð7¸Ó>À$ÐF€÷!ñ !ôNe�3�s‘8ô e÷V,ò ,r   