aioredlock
aioredlock copied to clipboard
What does this todo mean?
"Expire the lock valid attribute according to the lock validity in a safe way if possible."
I don't understand what this means? Does it mean that a lock is valid even if it's released or got into timeout?
For now aioredlock doesn't track locks on redis, as soon as the lock becomes valid it will be valid forever even when it will expire on server side. For short living locks it is not a problem, for long living locks application should periodically extend all own lock lifetimes.
Periodically lock checking/extension could be implemented in aioredlock, but someone have to do it.
This is how it could be done
async def __expire_setter(self):
key_expire = self.hub_config['key_expire'] # lock lifetime
while True:
if self.__locks: # dict as {lock.id(): lock}
log().debug('Extending locks: %s',
', '.join(f'{l.resource}(id:{l.id})'
for l in self.__locks.values()))
await asyncio.gather(*(l.extend()
for l in self.__locks.values()))
await asyncio.sleep(key_expire / 2)
Also extend()
could set lock invalid on fault right here https://github.com/joanvila/aioredlock/blob/6c62f0895c93b26b87ca8e3fe36bc024c81be421/aioredlock/algorithm.py#L139'