This commit is contained in:
Adria Navarro 2023-11-29 18:20:11 +01:00
parent f71e1ac03a
commit 3073397800
1 changed files with 3 additions and 2 deletions

View File

@ -111,14 +111,15 @@ export async function doWithLock<T>(
try {
const name = getLockName(opts)
let ttl = opts.ttl || Duration.fromSeconds(15).toMs()
let ttl = opts.ttl || Duration.fromSeconds(30).toMs()
// create the lock
lock = await redlock.lock(name, ttl)
if (!opts.ttl) {
// No TTL is provided, so we keep extending the lock while the task is running
interval = setInterval(() => {
lock!.extend(ttl)
lock?.extend(ttl / 2)
}, ttl / 2)
}