Remove lock
This commit is contained in:
parent
440dcb244d
commit
17b06703e9
|
@ -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 {
|
||||||
{
|
|
||||||
type: LockType.TRY_ONCE,
|
|
||||||
name: LockName.PERSIST_DOC_WRITETHROUGH,
|
|
||||||
resource: `${message.data.dbName}:${message.data.docId}`,
|
|
||||||
ttl: Duration.fromSeconds(60).toMs(),
|
|
||||||
},
|
|
||||||
async () => {
|
|
||||||
await this.persistToDb(message.data)
|
await this.persistToDb(message.data)
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err.status === 409) {
|
||||||
|
// If we get a 409, it means that another job updated it meanwhile. We want to retry it to persist it again.
|
||||||
|
throw new Error(`Conflict persisting message ${message.id}`)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
if (!result.executed) {
|
throw err
|
||||||
throw new Error(
|
|
||||||
`Error persisting docWritethrough message: ${message.id}`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return this
|
return this
|
||||||
|
|
|
@ -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 = {
|
||||||
|
|
Loading…
Reference in New Issue