
    Kix                        U d dl Z d dlZd dlmZmZ d dlmZmZmZ d dlm	Z	 d dl
mZmZmZmZmZmZmZmZmZmZmZmZmZ d dlZd dlmZ d dlmZ d dlmZ d d	l m!Z! d d
l"m#Z# d dl$m%Z% ddl&m'Z' ddl&m(Z( ddl&m)Z) ddl&m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z<m=Z=m>Z>m?Z?  ej                  eA      ZBej                  eDd<    ej                  eA      ZFej                  eDd<    G d de      ZH ed      ZI ed      ZJee3   ZKeLZMeLZNeOeLeLf   ZPeeQeNePf      ZReQeMeRf   ZSeeS   ZT G d de      ZU G d d e(      ZVy)!    N)AsyncExitStackasynccontextmanager)datetime	timedeltatimezone)TracebackType)AsyncGenerator	AwaitableCallableHashableIterableMapping	ParamSpecProtocolSequence	TypedDictTypeVarcastoverload)AsyncKeyValue)trace)Redis)PubSub)RedisCluster)Self   )DocketSnapshot)DocketSnapshotMixin)RunningExecution)
WorkerInfo)RedisConnection)ResultStorage)uuid7)	ExecutionTaskFunction)TASKS_ADDEDTASKS_CANCELLEDTASKS_REPLACEDTASKS_SCHEDULEDTASKS_STRICKEN)LiteralOperatorOperatorRestoreStrike
StrikeListloggertracerc                   ,    e Zd Zdee   dee   defdZy)_cancel_taskkeysargsreturnc                    K   y wN )selfr4   r5   s      Y/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/docket/docket.py__call__z_cancel_task.__call__=   s	        N)__name__
__module____qualname__liststrr<   r9       r;   r3   r3   <   s'    I%)#Y	rC   r3   PRc                   6    e Zd ZU eed<   eed<   eed<   eed<   y)RedisStreamPendingMessage
message_idconsumertime_since_deliveredtimes_deliveredN)r>   r?   r@   bytes__annotations__intr9   rC   r;   rG   rG   O   s    OrC   rG   c                      e Zd ZU dZeeef   ed<   eed<   e	ed<   e
dz  ed<   edz  ed<   eed<   d	d
 ed      d ed      ddfdededededededz  deddfdZedefd       Zedefd       ZdedefdZdefdZdee   dz  d edz  d!edz  ddfd"Zedeeez  df   fd#       Z edee!df   fd$       Z"d%ed&edefd'Z#dNd(ed)e$e   dz  ddfd*Z%d+eddfd,Z&de'eef   fd-Z(e)	 	 dOd(e*e+e,e-   f   d.e.dz  d/edz  de*e+e,e/   f   fd0       Z0e)	 	 dOd(ed.e.dz  d/edz  de*d1e,e/   f   fd2       Z0	 	 dOd(e*e+e,e-   f   ez  d.e.dz  d/edz  de*d1e,e/   f   fd3Z0e)d(e*e+e,e-   f   d.e.d/ede*e+e,e/   f   fd4       Z1e)d(ed.e.d/ede*d1e,e/   f   fd5       Z1d(e*e+e,e-   f   ez  d.e.d/ede*d1e,e/   f   fd6Z1d7e/ddfd8Z2d/eddfd9Z3d/ede/dz  fd:Z4edefd;       Z5edefd<       Z6d=edefd>Z7d=edefd?Z8d=edefd@Z9d=edefdAZ:d=edefdBZ;edefdC       Z<dPdDZ=dEeez  d/eddfdFZ>	 	 	 	 dQd(e*e+e,e-   f   ez  dz  dGedz  dHe?e@z  dIeAdz  ddf
dJZB	 	 	 	 dQd(e*e+e,e-   f   ez  dz  dGedz  dHe?e@z  dIeAdz  ddf
dKZCdPdLZDdefdMZEy)RDocketa  A Docket represents a collection of tasks that may be scheduled for later
    execution.  With a Docket, you can add, replace, and cancel tasks.
    Example:

    ```python
    @task
    async def my_task(greeting: str, recipient: str) -> None:
        print(f"{greeting}, {recipient}!")

    async with Docket() as docket:
        docket.add(my_task)("Hello", recipient="world")
    ```
    tasksstrike_list_redisN_result_storage_cancel_task_script_stackdocketzredis://localhost:6379/0   )seconds      )minutesFnameurlheartbeat_intervalmissed_heartbeatsexecution_ttlresult_storageenable_internal_instrumentationr6   c                     || _         || _        || _        || _        || _        || _        d| _        || _        t        |      | _	        ddl
m} |D 	ci c]  }	|	j                  |	 c}	| _
        yc c}	w )a  
        Args:
            name: The name of the docket.
            url: The URL of the Redis server or in-memory backend.  For example:
                - "redis://localhost:6379/0"
                - "redis://user:password@localhost:6379/0"
                - "redis://user:password@localhost:6379/0?ssl=true"
                - "rediss://localhost:6379/0"
                - "unix:///path/to/redis.sock"
                - "memory://" (in-memory backend for testing)
            heartbeat_interval: How often workers send heartbeat messages to the docket.
            missed_heartbeats: How many heartbeats a worker can miss before it is
                considered dead.
            execution_ttl: How long to keep completed or failed execution state records
                in Redis before they expire. Defaults to 15 minutes.
            enable_internal_instrumentation: Whether to enable OpenTelemetry spans
                for internal Redis polling operations like strike stream monitoring.
                Defaults to False.
        Nr   )standard_tasks)r]   r^   r_   r`   ra   rc   rU   _user_result_storager!   rS   rQ   re   r>   )
r:   r]   r^   r_   r`   ra   rb   rc   re   fns
             r;   __init__zDocket.__init__m   sn    : 	"4!2*/N,#' $2!%c*)IW.X2r{{B.X
.Xs   A0c                      y)Nzdocket-workersr9   r:   s    r;   worker_group_namezDocket.worker_group_name   s    rC   c                 L    | j                   j                  | j                        S )zReturn the key prefix for this docket.

        All Redis keys for this docket are prefixed with this value.

        For Redis Cluster mode, returns a hash-tagged prefix like "{myapp}"
        to ensure all keys hash to the same slot.
        )rS   prefixr]   rj   s    r;   rm   zDocket.prefix   s     {{!!$)),,rC   suffixc                 $    | j                    d| S )zReturn a Redis key with the docket prefix.

        Args:
            suffix: The key suffix (e.g., "queue", "stream", "runs:task-123")

        Returns:
            Full Redis key like "docket:queue" or "docket:stream"
        :)rm   )r:   rn   s     r;   keyz
Docket.key   s     ++ax((rC   c                 ^   K   t                _         j                  j                          d {    t         j                   j
                   j                         _         j                  j                   j                         d {     j                  j                   j                         d {     j                  R j                   _        d  _        t         j                  d      r" j                  j                          d {     S t         j                   j                          _         j                  j                   j                         d {     j                  j#                   fd        j                   _         S 7 q7 7 7 7 ?w)N)r^   r]   rc   setupc                      t         dd       S )NrT   )setattrrj   s   r;   <lambda>z#Docket.__aenter__.<locals>.<lambda>   s    7H$)O rC   )r   rV   
__aenter__r/   r^   r]   rc   rR   enter_async_contextrS   rf   rb   rT   hasattrrs   r"   results_collectioncallbackrj   s   `r;   rw   zDocket.__aenter__   sZ    $&kk$$&&&%,0,P,P
 kk--dkk::: kk--d.>.>??? $$0151J1JD#'D t**G4))//111 	 $1d>U>U#VD ++11$2F2FGGGKK  !OP"&"6"6D5 	' 	; 	@ 2 HsZ   -F-F!AF-F$,F-;F'<AF-F)AF-+F+,6F-$F-'F-)F-+F-exc_type	exc_value	tracebackc                 n   K   	 | j                   j                  |||       d {    | ` y 7 # | ` w xY wwr8   )rV   	__aexit__)r:   r|   r}   r~   s       r;   r   zDocket.__aexit__   s8     	++'')YGGG Hs    5 . ,. 5. 25c                   K   | j                   j                         4 d {   }| d d d       d {    y 7 7 # 1 d {  7  sw Y   y xY wwr8   )rS   client)r:   rs     r;   rediszDocket.redis   sL     ;;%%' 	 	1G	 	 	 	 	 	 	>   A<AA A>AA AA	AAc                   K   | j                   j                         4 d {   }| d d d       d {    y 7 7 # 1 d {  7  sw Y   y xY wwr8   )rS   pubsub)r:   r   s     r;   _pubsubzDocket._pubsub   sL     ;;%%' 	 	6L	 	 	 	 	 	 	r   channelmessagec                 V   K   | j                   j                  ||       d{   S 7 w)a7  Publish a message to a pub/sub channel.

        This handles both standalone and cluster modes transparently.

        Args:
            channel: The pub/sub channel to publish to
            message: The message to publish

        Returns:
            Number of subscribers that received the message
        N)rS   publish)r:   r   r   s      r;   _publishzDocket._publish   s%      [[(('::::s    )')functionnamesc                 j    ddl m}  ||       |s|j                  g}|D ]  }|| j                  |<    y)zRegister a task with the Docket.

        Args:
            function: The task to register.
            names: Names to register the task under. Defaults to [function.__name__].
        r   )validate_dependenciesN)dependenciesr   r>   rQ   )r:   r   r   r   r]   s        r;   registerzDocket.register   s=     	8h'&&'E 	(D'DJJt	(rC   collection_pathc                     |j                  d      \  }}}t        j                  |      }t        ||      }|D ]  }| j	                  |        y)z
        Register a collection of tasks.

        Args:
            collection_path: A path in the format "module:collection".
        rp   N)
rpartition	importlibimport_modulegetattrr   )r:   r   module_name_member_namemodule
collectionr   s           r;   register_collectionzDocket.register_collection  sR     '6&@&@&E#Q((5V[1
" 	$HMM(#	$rC   c                     d| j                   iS )Nzdocket.name)r]   rj   s    r;   labelszDocket.labels  s    499
 	
rC   whenrq   c                      y)zAdd a task to the Docket.

        Args:
            function: The task function to add.
            when: The time to schedule the task.
            key: The key to schedule the task under.
        Nr9   r:   r   r   rq   s       r;   addz
Docket.add      rC   .c                      y)zAdd a task to the Docket.

        Args:
            function: The name of a task to add.
            when: The time to schedule the task.
            key: The key to schedule the task under.
        Nr9   r   s       r;   r   z
Docket.add%  r   rC   c                 N    dt        t              r j                     n j                         #t	        j
                  t        j                        t        t                     dt        j                  dt        j                  dt        f fd}|S )zAdd a task to the Docket.

        Args:
            function: The task to add.
            when: The time to schedule the task.
            key: The key to schedule the task under.
        Nr5   kwargsr6   c            
        K   t        | |d      }t        j                  di j                         |j	                         d|j
                  i      5  j                  j                  |      rpt        j                  d|j
                  |j                         t        j                  di j                         |j                         ddi       |cd d d        S |j                  d	
       d {    d d d        t        j                  di j                         |j                                t!        j                  di j                         |j                                |S 7 z# 1 sw Y   yxY ww)Nr   attemptfunction_namez
docket.addcode.function.name
attributes'%r is stricken, skipping schedule of %rdocket.whererW   Freplace)r$   r1   start_as_current_spanr   specific_labelsr   rR   is_strickenr0   warningrq   r*   r   general_labelsscheduler&   r)   r5   r   	executionr   r   rq   r:   r   s      r;   	schedulerzDocket.add.<locals>.schedulerN  s    !+	I --kkm//1 ))*A*A .  8 ##//	:NNA!//!
 #&&"kkm'668 +H %/8 84  (((777588 OOAN$++-N93K3K3MNO#Rdkkm#Ry7O7O7Q#RS 858 8s>   AFBE:
F(E:=E8>E:A6F8E::F?F)
isinstancerB   rQ   r   r   nowr   utcr#   rD   r5   r   r$   r:   r   r   rq   r   r   s   ```` @r;   r   z
Docket.add4  s     %)h$$Mzz(+HMM(#<<<-D;eg,C+	166 +	QXX +	) +	 +	Z rC   c                      y)zReplace a previously scheduled task on the Docket.

        Args:
            function: The task function to replace.
            when: The time to schedule the task.
            key: The key to schedule the task under.
        Nr9   r   s       r;   r   zDocket.replace}  r   rC   c                      y)zReplace a previously scheduled task on the Docket.

        Args:
            function: The name of a task to replace.
            when: The time to schedule the task.
            key: The key to schedule the task under.
        Nr9   r   s       r;   r   zDocket.replace  r   rC   c                      dt        t              r j                     n j                         dt        j
                  dt        j                  dt        f fd}|S )zReplace a previously scheduled task on the Docket.

        Args:
            function: The task to replace.
            when: The time to schedule the task.
            key: The key to schedule the task under.
        Nr5   r   r6   c            
      |  K   t        | |d      }t        j                  di j                         |j	                         d|j
                  i      5  j                  j                  |      rpt        j                  d|j
                  |j                         t        j                  di j                         |j                         ddi       |cd d d        S |j                  d	
       d {    d d d        t        j                  di j                         |j                                t!        j                  di j                         |j                                t#        j                  di j                         |j                                |S 7 # 1 sw Y   xY ww)Nr   r   zdocket.replacer   r   r   r   rW   Tr   )r$   r1   r   r   r   r   rR   r   r0   r   rq   r*   r   r   r   r(   r'   r)   r   s      r;   r   z!Docket.replace.<locals>.scheduler  s    !+	I -- kkm//1 ))*A*A .  7 ##//	:NNA!//!
 #&&"kkm'668 +H %/7 74  (((666578 q"QT[[]"Qi6N6N6P"QR#Rdkkm#Ry7O7O7Q#RS#Rdkkm#Ry7O7O7Q#RS 757 7s>   AF<BF0
F<(F0=F.>F0B,F<.F00F95F<)r   rB   rQ   r   rD   r5   r   r$   r   s   ```` @r;   r   zDocket.replace  sc     %)h$$Mzz(+HMM(#,	166 ,	QXX ,	) ,	 ,	\ rC   r   c                 x  K   t         j                  di | j                         |j                         d|j                  i      5  | j
                  j                  |      rot        j                  d|j                  |j                         t        j                  di | j                         |j                         ddi       	 d d d        y |j                  d	       d {    d d d        t        j                  di | j                         |j                                y 7 C# 1 sw Y   BxY ww)
Nzdocket.scheduler   r   r   r   r   rW   Fr   )r1   r   r   r   r   rR   r   r0   r   rq   r*   r   r   r   r)   )r:   r   s     r;   r   zDocket.schedule  s8    ))++-++- %i&=&= * 
 	4 ++I6=++MM
 ""++-#224 ' /	4 	44 $$U$3335	48 	AN$++-N93K3K3MNO 45	4 	4s=   AD:BD.
	D:D.(D,)D.-?D:,D..D73D:c                   K   t         j                  di | j                         d|i      5  | j                         4 d{   }| j	                  ||       d{    ddd      d{    | j                  | j                  |      |       d{    ddd       t        j                  d| j                                y7 7 l7 ^# 1 d{  7  sw Y   nxY w7 L# 1 sw Y   KxY ww)a  Cancel a previously scheduled task on the Docket.

        If the task is scheduled (in the queue or stream), it will be removed.
        If the task is currently running, a cancellation signal will be sent
        to the worker, which will attempt to cancel the asyncio task. This is
        best-effort: if the task completes before the signal is processed,
        the cancellation will have no effect.

        Args:
            key: The key of the task to cancel.
        zdocket.cancelz
docket.keyr   Nr   )	r1   r   r   r   _cancelr   cancel_channelr'   r   )r:   rq   r   s      r;   cancelzDocket.cancel  s      ));$++-;s; * 
 	? zz| / /ull5#.../ / -- 3 3C 8#>>>	? 	At{{}-/./ / / / ?	? 	?s   ,C1C%CC%CC
C"C%-C.(C%C#C%-C1C%
CC%C 	CC 	C%%C.*C1c           
        K   ddl }| j                         4 d{   } |j                  | j                  |             d{   }|s	 ddd      d{    y|j	                  d      }|j	                  d      }|j	                  d      }|r|r|s	 ddd      d{    y|j                         }| j                  j	                  |      }	|	sdd}
||
_        |
}	|j                  |      }|j                  |      }|j	                  d      }|s	 ddd      d{    yt        j                  t        |j                               t        j                        }dd	lm}  || |	||||d
      }|j!                          d{    |cddd      d{    S 7 7 d7 T7 7 7 %7 # 1 d{  7  sw Y   yxY ww)a  Get a task Execution from the Docket by its key.

        Args:
            key: The task key.

        Returns:
            The Execution if found, None if the key doesn't exist.

        Example:
            # Claim check pattern: schedule a task, save the key,
            # then retrieve the execution later to check status or get results
            execution = await docket.add(my_task, key="important-task")(args)
            task_key = execution.key

            # Later, retrieve the execution by key
            execution = await docket.get_execution(task_key)
            if execution:
                await execution.get_result()
        r   Ns   functions   argss   kwargsc                     K   y wr8   r9   r9   rC   r;   placeholderz)Docket.get_execution.<locals>.placeholder@  s	     r=   s   when)tz)r$   r   )rW   r   r5   r   rq   r   r   r6   N)cloudpickler   hgetallruns_keygetdecoderQ   r>   loadsr   fromtimestampfloatr   r   docket.executionr$   sync)r:   rq   r   r   datar   	args_datakwargs_datafunction_name_strr   r   r5   r   when_strr   r$   r   s                    r;   get_executionzDocket.get_execution  s    ( 	::< 4	 4	5&t}}S'9::D	4	 4	 4	 !HH[1M)I((9-K 	4	 4	 4	 !. 4 4 6zz~~&78H (9$& $$Y/D &&{3F xx(HC4	 4	 4	D ))%0A*Bx||TD 3!!I .."""i4	 4	 4	:4	 4	 4	d #e4	 4	 4	 4	s   GF%G%F7F(F7GF+G:F7G"F.#G(A0F7G#F1$G)A$F7F3F7GF5 G(F7+G.G1G3F75G7G	=G >G	Gc                 $    | j                  d      S )Nqueuerq   rj   s    r;   	queue_keyzDocket.queue_keyb  s    xx  rC   c                 $    | j                  d      S )Nstreamr   rj   s    r;   
stream_keyzDocket.stream_keyf  s    xx!!rC   task_keyc                 *    | j                  d|       S )Nzknown:r   r:   r   s     r;   known_task_keyzDocket.known_task_keyj  s    xx&
+,,rC   c                 $    | j                  |      S r8   r   r   s     r;   parked_task_keyzDocket.parked_task_keym  s    xx!!rC   c                 *    | j                  d|       S )Nz
stream-id:r   r   s     r;   stream_id_keyzDocket.stream_id_keyp  s    xx*XJ/00rC   c                 *    | j                  d|       S )z<Return the Redis key for storing execution state for a task.zruns:r   r   s     r;   r   zDocket.runs_keys  s    xx%z*++rC   c                 *    | j                  d|       S )zEReturn the Redis pub/sub channel for cancellation signals for a task.zcancel:r   r   s     r;   r   zDocket.cancel_channelw  s    xx'(,--rC   c                 $    | j                  d      S )z.Return the collection name for result storage.resultsr   rj   s    r;   rz   zDocket.results_collection{  s     xx	""rC   c                 h  K   	 | j                         4 d{   }|j                  | j                  | j                  dd       d{    ddd      d{    y7 F7 7 	# 1 d{  7  sw Y   yxY w# t         j                  j
                  $ r}dt        |      vr Y d}~yd}~ww xY ww)a
  Create stream and consumer group if they don't exist (idempotent).

        This is safe to call from multiple workers racing to initialize - the
        BUSYGROUP error is silently ignored since it just means another worker
        created the group first.
        Nz0-0T)	groupnamer]   idmkstream	BUSYGROUP)r   xgroup_createrk   r   
exceptionsResponseErrorrB   )r:   r   es      r;   _ensure_stream_and_groupzDocket._ensure_stream_and_group  s     
	zz|  qoo"44!	 &         -- 	#a&( )	s   B2A: AA: -A%	A!
A%A: A#A: B2A: !A%#A: %A7+A.,A73A: 6B27A: :B/B*%B2*B//B2r   c           	        K   | j                   %t        t         |j                  d            | _         | j                   }t	        j
                  t        j                        j                         }| j                  |      } || j                  | j                  |      | j                  |      | j                  | j                  |      |g||g       d{    | j                  r?t!        | j                  j#                               } |j$                  ||       d{    y |j&                  |       d{    y7 j7 "7 	w)zCancel a task atomically.

        Handles cancellation regardless of task location:
        - From the stream (using stored message ID)
        - From the queue (scheduled tasks)
        - Cleans up all associated metadata keys
        NaJ  
                    local stream_key = KEYS[1]
                    -- TODO: Remove in next breaking release (v0.14.0) - legacy key locations
                    local known_key = KEYS[2]
                    local parked_key = KEYS[3]
                    local queue_key = KEYS[4]
                    local stream_id_key = KEYS[5]
                    local runs_key = KEYS[6]
                    local task_key = ARGV[1]
                    local completed_at = ARGV[2]

                    -- Get stream ID (check new location first, then legacy)
                    local message_id = redis.call('HGET', runs_key, 'stream_id')

                    -- TODO: Remove in next breaking release (v0.14.0) - check legacy location
                    if not message_id then
                        message_id = redis.call('GET', stream_id_key)
                    end

                    -- Delete from stream if message ID exists
                    if message_id then
                        redis.call('XDEL', stream_key, message_id)
                    end

                    -- Clean up legacy keys and parked data
                    redis.call('DEL', known_key, parked_key, stream_id_key)
                    redis.call('ZREM', queue_key, task_key)

                    -- Clear scheduling markers so add() can reschedule this key
                    redis.call('HDEL', runs_key, 'known', 'stream_id')

                    -- Only set CANCELLED if not already in a terminal state
                    local current_state = redis.call('HGET', runs_key, 'state')
                    if current_state ~= 'completed' and current_state ~= 'failed' and current_state ~= 'cancelled' then
                        redis.call('HSET', runs_key, 'state', 'cancelled', 'completed_at', completed_at)
                    end

                    return 'OK'
                    )r4   r5   )rU   r   r3   register_scriptr   r   r   r   	isoformatr   r   r   r   r   r   ra   rN   total_secondsexpiredelete)r:   r   rq   cancel_taskcompleted_attask_runs_keyttl_secondss          r;   r   zDocket._cancel  s1     ##+'+%%%&*-(D$\ ..  ||HLL1;;=c* ##C($$S)""3' |$

 
	
 
	
 d00>>@AK%,,}k::: %,,}---%
	
 ; .s7   CE	EA	E	"E#E	=E>E	E	E		parameteroperatorvaluec                 N  K   t        |      r|j                  n|}t        ||t        |      |      }t        j                  di | j                         |j                               5  | j                  j                  |       d{    ddd       y7 # 1 sw Y   yxY ww)a7  Strike a task from the Docket.

        Args:
            function: The task to strike (function or name), or None for all tasks.
            parameter: The parameter to strike on, or None for entire task.
            operator: The comparison operator to use.
            value: The value to strike on.
        zdocket.striker   N)	callabler>   r.   r,   r1   r   r   rR   send_instructionr:   r   r  r  r	  r   instructions          r;   strikezDocket.strike  s      .6h-?))X]Ix7I5Q))@$++-@;+=+=+?@ * 
 	A ""33K@@@		A 	A A		A 	A0   A(B%*B	B
B	B%BB"B%c                 N  K   t        |      r|j                  n|}t        ||t        |      |      }t        j                  di | j                         |j                               5  | j                  j                  |       d{    ddd       y7 # 1 sw Y   yxY ww)aM  Restore a previously stricken task to the Docket.

        Args:
            function: The task to restore (function or name), or None for all tasks.
            parameter: The parameter to restore on, or None for entire task.
            operator: The comparison operator to use.
            value: The value to restore on.
        zdocket.restorer   N)	r  r>   r-   r,   r1   r   r   rR   r  r  s          r;   restorezDocket.restore  s      .6h-?))XmY8JER))@$++-@;+=+=+?@ * 
 	A ""33K@@@		A 	A A		A 	Ar  c                 T   K   | j                   j                          d{    y7 w)aW  Wait for all existing strikes to be loaded from the stream.

        This method blocks until the strike monitor has completed its initial
        non-blocking read of all existing strike messages. Call this before
        making decisions that depend on the current strike state, such as
        scheduling automatic perpetual tasks.
        N)rR   wait_for_strikes_loadedrj   s    r;   r  zDocket.wait_for_strikes_loaded  s       66888s   (&(c           	      D  K   t         j                  d| j                               5  | j                         4 d{   } |j                         4 d{   }|j                  | j                         |j                  | j                         |j                  | j                  dd       |j                          d{   \  }}}ddd      d{    g }dkD  rW |j                  | j                  dd       d{   }|D ],  \  }}	d|	v s|j                  |	d   j                                .  |j                         4 d{   }|dkD  r|j                  | j                  dd	
       |j                  | j                         D ]  }
|
j                         }|j                  | j!                  |             |j                  | j#                  |             |j                  | j%                  |             | j'                  |      }| j(                  r6t+        | j(                  j-                               }|j/                  ||       |j                  |        |D ]f  }| j'                  |      }| j(                  r6t+        | j(                  j-                               }|j/                  ||       V|j                  |       h |j                          d{    |z   }|cddd      d{    cddd      d{    cddd       S 7 7 7 e7 T# 1 d{  7  sw Y   exY w7 @7 7 ^7 I7 :# 1 d{  7  sw Y   nxY wddd      d{  7   n# 1 d{  7  sw Y   nxY wddd       y# 1 sw Y   yxY ww)aA  Clear all queued and scheduled tasks from the docket.

        This removes all tasks from the stream (immediate tasks) and queue
        (scheduled tasks), along with their associated parked data. Running
        tasks are not affected.

        Returns:
            The total number of tasks that were cleared.
        zdocket.clearr   Nr   -+s   keyF)maxlenapproximate)r1   r   r   r   pipelinexlenr   zcardr   zrangeexecutexrangeappendr   xtrimr  r   r   r   r   ra   rN   r   r  )r:   r   r  stream_countqueue_countscheduled_keysstream_keysmessagesrH   fields	key_bytesr   r  r  total_cleareds                  r;   clearzDocket.clear  sB     )){{} * 
 <	) zz| 8) 8)u)5>>+ 	Y 	YxMM$//2NN4>>2OODNNAr:
 GOFVFVFX@X=L+~	Y 	Y *,!#%1U\\$//3%LLH.6 H*
F!V+'..vf~/D/D/FGH
 *5>>+ ") ")x $a' tqeTOODNN3 &4 ;	#,#3#3#5 (<(<X(FG (;(;H(EF (:(:8(DE )-h(?--*-d.@.@.N.N.P*QK$OOM;G$OOM:; %0 ;(,h(?--*-d.@.@.N.N.P*QK$OOM;G$OOM:; #**,,,$0;$>M(E") ") ")-8) 8) 8)	<	) <	)8)	Y AY	Y 	Y 	Y 	Y  M")> -?")-8),") ") ")-8) 8) 8) 8) 8)	<	) <	) <	)sB  &N NL!NM6L$
M6A'L-L'
L-M6L*,M6MM69M6M
M6FM*M	
+
M5M6M
M6NMN
N !N$M6'L-*M6-M 3L64M ;	M6M6	MM6NM!MM!M6$N/M20N6N	<M?=N	N	N NN r8   )NNr   )NNz==N)Fr>   r?   r@   __doc__dictrB   r%   rM   r/   r!   r"   r3   r   r   rN   r   boolrh   propertyrk   rm   rq   r   rw   typeBaseExceptionr   r   r   r	   r   r   r   r   r   r   rA   r   r   r   r   r   r   rD   r
   rE   r   r$   r   r   r   r   r   r   r   r   r   r   r   r   rz   r   r   r,   r+   r   r  r  r  r+  r9   rC   r;   rP   rP   V   s+    \!"""T))%,, -(1!(<!"#,R#8/305)Y)Y )Y &	)Y
 )Y !)Y &,)Y *.)Y 
)YV  3     - - -	)# 	)# 	)$ <	}%,	 !4'	 !4'		
 
	 ^EL,@$,FG   ~fdl;  ;c ;C ;C ;( (d3i$6F (RV ("$3 $4 $
S) 

  !%	1il?+ o 4Z	
 
!Yy))	*   !%	 o 4Z	
 
#y++	, " !%	G1il?+c1G oG 4Z	G
 
#y++	,GR 1il?+  	
 
!Yy))	*    	
 
#y++	, B1il?+c1B B 	B
 
#y++	,BHP	 Pd P>. . .0Js Jy4/? JX !3 ! ! "C " "-s -s -" " "1c 1c 1, , ,.s .s . #C # #&P.5<#7 P.c P.d P.h <@ $/3!%A1il?+c1D8A :A _,	A
 $A 
A4 <@ $/3!%A1il?+c1D8A :A _,	A
 $A 
A09F)S F)rC   rP   )Wr   logging
contextlibr   r   r   r   r   typesr   typingr	   r
   r   r   r   r   r   r   r   r   r   r   r   redis.exceptionsr   !key_value.aio.protocols.key_valuer   opentelemetryr   redis.asyncior   redis.asyncio.clientr   redis.asyncio.clusterr   typing_extensionsr   _docket_snapshotr   r   r   r    rS   r!   _result_storer"   _uuid7r#   r   r$   r%   instrumentationr&   r'   r(   r)   r*   
strikelistr+   r,   r-   r.   r/   	getLoggerr>   r0   LoggerrM   
get_tracerr1   Tracerr3   rD   rE   TaskCollectionrL   RedisStreamIDRedisMessageIDr-  RedisMessagetupleRedisMessagesRedisStreamRedisReadGroupResponserG   rP   r9   rC   r;   <module>rN     s3     : 2 2       ;   ' . " > 1 B 6 # (    +**84 4'u''1 18  cNCL,'E5L!~|;<=M=01!+. 	 O)  O)rC   