File tree Expand file tree Collapse file tree 1 file changed +10
-13
lines changed
packages/service-library/src/servicelib Expand file tree Collapse file tree 1 file changed +10
-13
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,15 @@ async def _cancel_or_warn(task: Task) -> None:
6262 _logger .warning ("Could not cancel task_name=%s pending=%s" , task_name , pending )
6363
6464
65+ async def _auto_extend_lock (lock : Lock ) -> None :
66+ try :
67+ with log_context (_logger , logging .DEBUG , f"Autoextend lock { lock .name } " ):
68+ # TODO: if we cannot re-acquire that means the lock is lost, and we are not anymore safe and should raise all the way to the caller
69+ await lock .reacquire ()
70+ except redis .exceptions .LockNotOwnedError as exc :
71+ raise LockLostError (lock = lock ) from exc
72+
73+
6574@dataclass
6675class RedisClientSDK :
6776 redis_dsn : str
@@ -182,21 +191,9 @@ async def lock_context(
182191 if not await ttl_lock .acquire (token = lock_value ):
183192 raise CouldNotAcquireLockError (lock = ttl_lock )
184193
185- async def _extend_lock (lock : Lock ) -> None :
186- try :
187- with (
188- log_context (
189- _logger , logging .DEBUG , f"Extending lock { lock_unique_id } "
190- ),
191- ):
192- # TODO: if we cannot re-acquire that means the lock is lost, and we are not anymore safe and should raise all the way to the caller
193- await lock .reacquire ()
194- except redis .exceptions .LockNotOwnedError as exc :
195- raise LockLostError (lock = lock ) from exc
196-
197194 try :
198195 async with periodic_task (
199- _extend_lock ,
196+ _auto_extend_lock ,
200197 interval = total_lock_duration / 2 ,
201198 task_name = lock_unique_id ,
202199 lock = ttl_lock ,
You can’t perform that action at this time.
0 commit comments