distributed-lock
distributed-lock copied to clipboard
Option not to throw exception on lock fail
Hi,
We have a use case where we run a cron on a Spring service spawned in multiple instances and we need to run it only on one instance. For this we use @RedisLocked
and we expect that all of the locks will fail BUT the winning one. This is working now as expected, but the failing ones throw DistributedLockException
in LockMethodInterceptor.invoke
from method executeLockedMethod
.
This is not the ideal case for us, as these exceptions are hard to catch in spring (@RedisLocked
is on the same level as @Scheduled
) and are not welcome in our usecase.
It would be nice to have an option on @RedisLocked
annotation to suppress this exception and log it in warn instead. For example @RedisLocked(logFailedLock = true)
or @RedisLocked(suppressFailure = true)
.
Cron is not the only usecase, this option can help any usecase that needs to lock across multiple instances without raising exceptions.
I am prepared to create PR for you.