Retry
This commit is contained in:
parent
bb5b40b61c
commit
977daff05c
|
@ -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(),
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue