1
0
Fork 0
mirror of synced 2024-07-06 15:00:49 +12:00

Improve redlock non executed response

This commit is contained in:
Adria Navarro 2024-03-05 15:02:02 +01:00
parent 0649497ab5
commit 2b25f9f0cb
2 changed files with 18 additions and 1 deletions

View file

@ -44,6 +44,15 @@ docWritethroughProcessorQueue.process(async message => {
)
if (!lockResponse.executed) {
if (
lockResponse.reason !==
locks.UnsuccessfulRedlockExecutionReason.LockTakenWithTryOnce
) {
console.error("Error persisting docWritethrough", {
data: message.data,
})
throw "Error persisting docWritethrough"
}
console.log(`Ignoring redlock conflict in write-through cache`)
}
})

View file

@ -82,6 +82,11 @@ type SuccessfulRedlockExecution<T> = {
}
type UnsuccessfulRedlockExecution = {
executed: false
reason: UnsuccessfulRedlockExecutionReason
}
export const enum UnsuccessfulRedlockExecutionReason {
LockTakenWithTryOnce = "LOCK_TAKEN_WITH_TRY_ONCE",
}
type RedlockExecution<T> =
@ -141,7 +146,10 @@ export async function doWithLock<T>(
if (opts.type === LockType.TRY_ONCE) {
// don't throw for try-once locks, they will always error
// due to retry count (0) exceeded
return { executed: false }
return {
executed: false,
reason: UnsuccessfulRedlockExecutionReason.LockTakenWithTryOnce,
}
} else {
throw e
}