1
0
Fork 0
mirror of synced 2024-07-07 15:25:52 +12:00
This commit is contained in:
Adria Navarro 2024-03-07 10:54:26 +01:00
parent bb5b40b61c
commit 977daff05c
2 changed files with 20 additions and 3 deletions

View file

@ -23,7 +23,7 @@ class DocWritethroughProcessor {
docWritethroughProcessorQueue.process(async message => { docWritethroughProcessorQueue.process(async message => {
const result = await locks.doWithLock( const result = await locks.doWithLock(
{ {
type: LockType.DEFAULT, type: LockType.TRY_ONCE,
name: LockName.PERSIST_DOC_WRITETHROUGH, name: LockName.PERSIST_DOC_WRITETHROUGH,
resource: `${message.data.dbName}:${message.data.docId}`, resource: `${message.data.dbName}:${message.data.docId}`,
ttl: Duration.fromSeconds(60).toMs(), ttl: Duration.fromSeconds(60).toMs(),

View file

@ -1,8 +1,9 @@
import events from "events" import events from "events"
import { timeout } from "../utils" import { newid, timeout } from "../utils"
import { Queue, QueueOptions, JobOptions } from "./queue" import { Queue, QueueOptions, JobOptions } from "./queue"
interface JobMessage { interface JobMessage {
id: string
timestamp: number timestamp: number
queue: string queue: string
data: any data: any
@ -20,6 +21,7 @@ interface JobMessage {
*/ */
function newJob(queue: string, message: any, opts?: JobOptions): JobMessage { function newJob(queue: string, message: any, opts?: JobOptions): JobMessage {
return { return {
id: newid(),
timestamp: Date.now(), timestamp: Date.now(),
queue: queue, queue: queue,
data: message, data: message,
@ -74,8 +76,23 @@ class InMemoryQueue implements Partial<Queue> {
let msg = this._messages.shift() let msg = this._messages.shift()
let resp = func(msg) let resp = func(msg)
async function retryFunc(fnc: any) {
try {
await fnc
} catch (e: any) {
await new Promise<void>(r => setTimeout(() => r(), 50))
await retryFunc(func(msg))
}
}
if (resp.then != null) { if (resp.then != null) {
await resp try {
await retryFunc(resp)
} catch (e: any) {
console.error(e)
}
} }
this._runCount++ this._runCount++
const jobId = msg?.opts?.jobId?.toString() const jobId = msg?.opts?.jobId?.toString()