chore(): Default caching configuration and gracefull redis error handling (#13663)
* chore(): Default caching configuration and gracefull redis error handling * Create odd-moons-crash.md * chore(): Default caching configuration and gracefull redis error handling * fixes * address feedback * revert(): Test utils imit module fix * reconnect * reconnect * reconnect
This commit is contained in:
committed by
GitHub
parent
28d57b7bf8
commit
51859c38a7
@@ -42,11 +42,11 @@ export default async (
|
||||
maxRetriesPerRequest: null,
|
||||
})
|
||||
logger?.info(
|
||||
`Connection to Redis in module 'workflow-engine-redis' established`
|
||||
`[Workflow-engine-redis] Connection to Redis in module 'workflow-engine-redis' established`
|
||||
)
|
||||
} catch (err) {
|
||||
logger?.error(
|
||||
`An error occurred while connecting to Redis in module 'workflow-engine-redis': ${err}`
|
||||
`[Workflow-engine-redis] An error occurred while connecting to Redis in module 'workflow-engine-redis': ${err}`
|
||||
)
|
||||
}
|
||||
|
||||
@@ -54,11 +54,11 @@ export default async (
|
||||
redisPublisher = await getConnection(cnnPubSub.url, cnnPubSub.options)
|
||||
redisSubscriber = await getConnection(cnnPubSub.url, cnnPubSub.options)
|
||||
logger?.info(
|
||||
`Connection to Redis PubSub in module 'workflow-engine-redis' established`
|
||||
`[Workflow-engine-redis] Connection to Redis PubSub in module 'workflow-engine-redis' established`
|
||||
)
|
||||
} catch (err) {
|
||||
logger?.error(
|
||||
`An error occurred while connecting to Redis PubSub in module 'workflow-engine-redis': ${err}`
|
||||
`[Workflow-engine-redis] An error occurred while connecting to Redis PubSub in module 'workflow-engine-redis': ${err}`
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -128,6 +128,7 @@ export class RedisDistributedTransactionStorage
|
||||
}
|
||||
|
||||
async onApplicationStart() {
|
||||
await this.ensureRedisConnection()
|
||||
const allowedJobs = [
|
||||
JobType.RETRY,
|
||||
JobType.STEP_TIMEOUT,
|
||||
@@ -212,6 +213,64 @@ export class RedisDistributedTransactionStorage
|
||||
this.workflowOrchestratorService_ = workflowOrchestratorService
|
||||
}
|
||||
|
||||
private async ensureRedisConnection(): Promise<void> {
|
||||
const reconnectTasks: Promise<void>[] = []
|
||||
|
||||
if (this.redisClient.status !== "ready") {
|
||||
this.logger_.warn(
|
||||
`[Workflow-engine-redis] Redis connection is not ready (status: ${this.redisClient.status}). Attempting to reconnect...`
|
||||
)
|
||||
reconnectTasks.push(
|
||||
this.redisClient
|
||||
.connect()
|
||||
.then(() => {
|
||||
this.logger_.info(
|
||||
"[Workflow-engine-redis] Redis connection reestablished successfully"
|
||||
)
|
||||
})
|
||||
.catch((error) => {
|
||||
this.logger_.error(
|
||||
"[Workflow-engine-redis] Failed to reconnect to Redis",
|
||||
error
|
||||
)
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.DB_ERROR,
|
||||
`Redis connection failed: ${error.message}`
|
||||
)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
if (this.redisWorkerConnection.status !== "ready") {
|
||||
this.logger_.warn(
|
||||
`[Workflow-engine-redis] Redis worker connection is not ready (status: ${this.redisWorkerConnection.status}). Attempting to reconnect...`
|
||||
)
|
||||
reconnectTasks.push(
|
||||
this.redisWorkerConnection
|
||||
.connect()
|
||||
.then(() => {
|
||||
this.logger_.info(
|
||||
"[Workflow-engine-redis] Redis worker connection reestablished successfully"
|
||||
)
|
||||
})
|
||||
.catch((error) => {
|
||||
this.logger_.error(
|
||||
"[Workflow-engine-redis] Failed to reconnect to Redis worker connection",
|
||||
error
|
||||
)
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.DB_ERROR,
|
||||
`Redis worker connection failed: ${error.message}`
|
||||
)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
if (reconnectTasks.length > 0) {
|
||||
await promiseAll(reconnectTasks)
|
||||
}
|
||||
}
|
||||
|
||||
private async saveToDb(data: TransactionCheckpoint, retentionTime?: number) {
|
||||
const isNotStarted = data.flow.state === TransactionState.NOT_STARTED
|
||||
const isFinished = [
|
||||
|
||||
Reference in New Issue
Block a user