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

Remove lock

This commit is contained in:
Adria Navarro 2024-03-07 11:16:08 +01:00
parent 440dcb244d
commit 17b06703e9
2 changed files with 9 additions and 18 deletions

View file

@ -1,9 +1,7 @@
import { AnyDocument, Database, LockName, LockType } from "@budibase/types" import { AnyDocument, Database } from "@budibase/types"
import { JobQueue, createQueue } from "../queue" import { JobQueue, createQueue } from "../queue"
import * as dbUtils from "../db" import * as dbUtils from "../db"
import { locks } from "../redis"
import { Duration } from "../utils"
interface ProcessDocMessage { interface ProcessDocMessage {
dbName: string dbName: string
@ -24,21 +22,15 @@ export const docWritethroughProcessorQueue = createQueue<ProcessDocMessage>(
class DocWritethroughProcessor { class DocWritethroughProcessor {
init() { init() {
docWritethroughProcessorQueue.process(async message => { docWritethroughProcessorQueue.process(async message => {
const result = await locks.doWithLock( try {
{ await this.persistToDb(message.data)
type: LockType.TRY_ONCE, } catch (err: any) {
name: LockName.PERSIST_DOC_WRITETHROUGH, if (err.status === 409) {
resource: `${message.data.dbName}:${message.data.docId}`, // If we get a 409, it means that another job updated it meanwhile. We want to retry it to persist it again.
ttl: Duration.fromSeconds(60).toMs(), throw new Error(`Conflict persisting message ${message.id}`)
},
async () => {
await this.persistToDb(message.data)
} }
)
if (!result.executed) { throw err
throw new Error(
`Error persisting docWritethrough message: ${message.id}`
)
} }
}) })
return this return this

View file

@ -23,7 +23,6 @@ export enum LockName {
APP_MIGRATION = "app_migrations", APP_MIGRATION = "app_migrations",
PROCESS_AUTO_COLUMNS = "process_auto_columns", PROCESS_AUTO_COLUMNS = "process_auto_columns",
PROCESS_USER_INVITE = "process_user_invite", PROCESS_USER_INVITE = "process_user_invite",
PERSIST_DOC_WRITETHROUGH = "persist_doc_writethrough",
} }
export type LockOptions = { export type LockOptions = {