
    Ki                        d Z ddlmZ ddlZddlmZmZmZ ddlmZm	Z	 ddl
mZmZmZmZmZmZ erdd	lmZ dd
lmZmZ  ej,                  d      Z G d ded         Zy)zPerpetual task dependency.    )annotationsN)datetime	timedeltatimezone)TYPE_CHECKINGAny   )CompletionHandlerTaskOutcomecurrent_docketcurrent_executioncurrent_workerformat_duration   )	Execution)TASKS_PERPETUATEDTASKS_SUPERSEDEDzdocket.dependenciesc                      e Zd ZU dZded<   ded<   ded<   ded	<   ded
<   ded<    ed      df	 	 	 	 	 ddZddZedd       Z	ddZ
ddZddZddZddZy) 	Perpetualay  Declare a task that should be run perpetually.  Perpetual tasks are automatically
    rescheduled for the future after they finish (whether they succeed or fail).  A
    perpetual task can be scheduled at worker startup with the `automatic=True`.

    Example:

    ```python
    @task
    async def my_task(perpetual: Perpetual = Perpetual()) -> None:
        ...
    ```
    r   everybool	automaticztuple[Any, ...]argszdict[str, Any]kwargs	cancelleddatetime | None
_next_whenr   Fc                <    || _         || _        d| _        d| _        y)a  
        Args:
            every: The target interval between task executions.
            automatic: If set, this task will be automatically scheduled during worker
                startup and continually through the worker's lifespan.  This ensures
                that the task will always be scheduled despite crashes and other
                adverse conditions.  Automatic tasks must not require any arguments.
        FN)r   r   r   r   )selfr   r   s      j/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/docket/dependencies/_perpetual.py__init__zPerpetual.__init__1   s      
"    c                   K   t        j                         }t        | j                  | j                        }|j
                  |_        |j                  |_        |S w)N)r   r   )r   getr   r   r   r   r   )r   	execution	perpetuals      r    
__aenter__zPerpetual.__aenter__C   sG     %))+	DJJ$..I	"	$++	s   AAc                     y)zBReturn None to schedule for immediate execution at worker startup.N r   s    r    initial_whenzPerpetual.initial_whenJ   s     r"   c                    d| _         y )NT)r   r*   s    r    cancelzPerpetual.cancelO   s	    r"   c                     || _         || _        y )N)r   r   )r   r   r   s      r    
perpetuatezPerpetual.perpetuateR   s    	r"   c                Z    t        j                  t        j                        |z   | _        y)z2Schedule the next execution after the given delay.N)r   nowr   utcr   )r   delays     r    afterzPerpetual.afterV   s    ",,x||4u<r"   c                    || _         y)z.Schedule the next execution at the given time.N)r   )r   whens     r    atzPerpetual.atZ   s	    r"   c                  K   | j                   rbt        j                         }|j                         4 d{   }|j	                  ||j
                         d{    ddd      d{    y|j                          d{   rt        j                         }t        j                  di |j                         |j                         ddi       t        j                  dt        |j                  j!                               |j#                                yt        j                         }t        j                         }| j$                  r| j$                  }nIt'        j(                  t*        j,                        }t/        ||| j0                  z   |j                  z
        } |j3                  |j4                  ||j
                        | j6                  i | j8                   d{    t;        j                  di |j                         |j                                |j<                  rRt        j?                  dt        |j                  j!                               |j#                         |j<                  	       t        j                  d
t        |j                  j!                               |j#                                y7 7 t7 g# 1 d{  7  sw Y   yxY w7 f7 w)z3Handle completion by scheduling the next execution.NFr	   zdocket.whereon_completeu   ↬ [%s] %s (superseded)Tu   ↩ [%s] %s)exc_infou   ↫ [%s] %s) r   r   r$   redis_cancelkeyis_supersededr   r   addlabelsgeneral_labelsloggerinfor   durationtotal_seconds	call_reprr   r   r1   r   r2   maxr   replacefunctionr   r   r   	exceptionerror)r   r%   outcomedocketr;   workerr6   r1   s           r    r9   zPerpetual.on_complete^   sf    >>#'')F||~ ; ;nnUIMM:::; ;((***#'')F  mmo..0 #M KK* 0 0 > > @A##%
 ##%##%????D,,x||,CsC$**,w/?/??@DEfnnY//y}}EYY
kk
 	
 	

 	a!RFMMO!Ry7O7O7Q!RSLL 0 0 > > @A##% **	   	G,,::<=!	
 g;:; ; ; ;*4	
sv   5K0KK0 KKK K0+K,K0K*E'K0,K--C K0KK0K'KK'#K0-K0N)r   r   r   r   returnNone)rO   r   )rO   r   )rO   rP   )r   r   r   r   rO   rP   )r3   r   rO   rP   )r6   r   rO   rP   )r%   r   rL   r   rO   r   )__name__
__module____qualname____doc____annotations__r   r!   r'   propertyr+   r-   r/   r4   r7   r9   r)   r"   r    r   r      s     O
O %Q<  
	$  =7r"   r   )rT   
__future__r   loggingr   r   r   typingr   r   _baser
   r   r   r   r   r   r%   r   instrumentationr   r   	getLoggerrB   r   r)   r"   r    <module>r]      sS      "  2 2 %  % A			0	1{!+. {r"   