Coverage for /usr/local/lib/python3.12/site-packages/prefect/locking/protocol.py: 59%
17 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 10:48 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 10:48 +0000
1from typing import Optional, Protocol, runtime_checkable 1a
4@runtime_checkable 1a
5class LockManager(Protocol): 1a
6 def acquire_lock( 1a
7 self,
8 key: str,
9 holder: str,
10 acquire_timeout: Optional[float] = None,
11 hold_timeout: Optional[float] = None,
12 ) -> bool:
13 """
14 Acquire a lock for a transaction record with the given key. Will block other
15 actors from updating this transaction record until the lock is
16 released.
18 Args:
19 key: Unique identifier for the transaction record.
20 holder: Unique identifier for the holder of the lock.
21 acquire_timeout: Max number of seconds to wait for the record to become
22 available if it is locked while attempting to acquire a lock. Pass 0
23 to attempt to acquire a lock without waiting. Blocks indefinitely by
24 default.
25 hold_timeout: Max number of seconds to hold the lock for. Holds the lock
26 indefinitely by default.
28 Returns:
29 bool: True if the lock was successfully acquired; False otherwise.
30 """
31 ...
33 async def aacquire_lock( 1a
34 self,
35 key: str,
36 holder: str,
37 acquire_timeout: Optional[float] = None,
38 hold_timeout: Optional[float] = None,
39 ) -> bool:
40 """
41 Acquire a lock for a transaction record with the given key. Will block other
42 actors from updating this transaction record until the lock is
43 released.
45 Args:
46 key: Unique identifier for the transaction record.
47 holder: Unique identifier for the holder of the lock.
48 acquire_timeout: Max number of seconds to wait for the record to become
49 available if it is locked while attempting to acquire a lock. Pass 0
50 to attempt to acquire a lock without waiting. Blocks indefinitely by
51 default.
52 hold_timeout: Max number of seconds to hold the lock for. Holds the lock
53 indefinitely by default.
55 Returns:
56 bool: True if the lock was successfully acquired; False otherwise.
57 """
58 ...
60 def release_lock(self, key: str, holder: str) -> None: 1a
61 """
62 Releases the lock on the corresponding transaction record.
64 Args:
65 key: Unique identifier for the transaction record.
66 holder: Unique identifier for the holder of the lock. Must match the
67 holder provided when acquiring the lock.
68 """
69 ...
71 def is_locked(self, key: str) -> bool: 1a
72 """
73 Simple check to see if the corresponding record is currently locked.
75 Args:
76 key: Unique identifier for the transaction record.
78 Returns:
79 True is the record is locked; False otherwise.
80 """
81 ...
83 def is_lock_holder(self, key: str, holder: str) -> bool: 1a
84 """
85 Check if the current holder is the lock holder for the transaction record.
87 Args:
88 key: Unique identifier for the transaction record.
89 holder: Unique identifier for the holder of the lock.
91 Returns:
92 bool: True if the current holder is the lock holder; False otherwise.
93 """
94 ...
96 def wait_for_lock(self, key: str, timeout: Optional[float] = None) -> bool: 1a
97 """
98 Wait for the corresponding transaction record to become free.
100 Args:
101 key: Unique identifier for the transaction record.
102 timeout: Maximum time to wait. None means to wait indefinitely.
104 Returns:
105 bool: True if the lock becomes free within the timeout; False
106 otherwise.
107 """
108 ...
110 async def await_for_lock(self, key: str, timeout: Optional[float] = None) -> bool: 1a
111 """
112 Wait for the corresponding transaction record to become free.
114 Args:
115 key: Unique identifier for the transaction record.
116 timeout: Maximum time to wait. None means to wait indefinitely.
118 Returns:
119 bool: True if the lock becomes free within the timeout; False
120 otherwise.
121 """
122 ...