fix(medusa): Make event enqueuer reconnect the database when it lost the connection (#4855)
* Try to periodically reconnect database from enqueuer * Create great-months-train.md --------- Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
This commit is contained in:
2 files changed
+15
-1
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(medusa): Make event enqueuer reconnect the database when it lost the connection
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { EventBusTypes } from "@medusajs/types"
|
import { EventBusTypes } from "@medusajs/types"
|
||||||
import { EventBusUtils } from "@medusajs/utils"
|
import { DatabaseErrorCode, EventBusUtils } from "@medusajs/utils"
|
||||||
import { EntityManager } from "typeorm"
|
import { EntityManager } from "typeorm"
|
||||||
import { TransactionBaseService } from "../interfaces"
|
import { TransactionBaseService } from "../interfaces"
|
||||||
import { StagedJob } from "../models"
|
import { StagedJob } from "../models"
|
||||||
@@ -190,6 +190,7 @@ export default class EventBusService
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (this.shouldEnqueuerRun) {
|
while (this.shouldEnqueuerRun) {
|
||||||
|
try {
|
||||||
const jobs = await this.stagedJobService_.list(listConfig)
|
const jobs = await this.stagedJobService_.list(listConfig)
|
||||||
|
|
||||||
if (!jobs.length) {
|
if (!jobs.length) {
|
||||||
@@ -210,6 +211,14 @@ export default class EventBusService
|
|||||||
})
|
})
|
||||||
|
|
||||||
await sleep(3000)
|
await sleep(3000)
|
||||||
|
} catch (err) {
|
||||||
|
if (DatabaseErrorCode.connectionFailure === err.code) {
|
||||||
|
await sleep(3000)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
throw err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user