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