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:
authored and GitHub committed 2023-08-29 13:03:11 +02:00
1 parent 4897040c92
commit 4d439bed38
2 files changed
+15 -1

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
fix(medusa): Make event enqueuer reconnect the database when it lost the connection
+10 -1
View File
@@ -1,5 +1,5 @@
import { EventBusTypes } from "@medusajs/types"
import { EventBusUtils } from "@medusajs/utils"
import { DatabaseErrorCode, EventBusUtils } from "@medusajs/utils"
import { EntityManager } from "typeorm"
import { TransactionBaseService } from "../interfaces"
import { StagedJob } from "../models"
@@ -190,6 +190,7 @@ export default class EventBusService
}
while (this.shouldEnqueuerRun) {
try {
const jobs = await this.stagedJobService_.list(listConfig)
if (!jobs.length) {
@@ -210,6 +211,14 @@ export default class EventBusService
})
await sleep(3000)
} catch (err) {
if (DatabaseErrorCode.connectionFailure === err.code) {
await sleep(3000)
continue
}
throw err
}
}
}
}