fix(medusa): Batch job not saving the errors properly (#2812)
This commit is contained in:
@@ -33,45 +33,44 @@ class BatchJobSubscriber {
|
||||
}
|
||||
|
||||
preProcessBatchJob = async (data): Promise<void> => {
|
||||
await this.manager_.transaction(async (manager) => {
|
||||
const batchJobServiceTx = this.batchJobService_.withTransaction(manager)
|
||||
const batchJob = await batchJobServiceTx.retrieve(data.id)
|
||||
try {
|
||||
await this.manager_.transaction(async (manager) => {
|
||||
const batchJobServiceTx = this.batchJobService_.withTransaction(manager)
|
||||
const batchJob = await batchJobServiceTx.retrieve(data.id)
|
||||
|
||||
const batchJobStrategy = this.strategyResolver_.resolveBatchJobByType(
|
||||
batchJob.type
|
||||
)
|
||||
const batchJobStrategy = this.strategyResolver_.resolveBatchJobByType(
|
||||
batchJob.type
|
||||
)
|
||||
|
||||
try {
|
||||
await batchJobStrategy
|
||||
.withTransaction(manager)
|
||||
.preProcessBatchJob(batchJob.id)
|
||||
await batchJobServiceTx.setPreProcessingDone(batchJob.id)
|
||||
} catch (e) {
|
||||
await this.batchJobService_.setFailed(batchJob.id, e.message)
|
||||
throw e
|
||||
}
|
||||
})
|
||||
})
|
||||
} catch (e) {
|
||||
await this.batchJobService_.setFailed(data.id, e.message)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
processBatchJob = async (data): Promise<void> => {
|
||||
await this.manager_.transaction(async (manager) => {
|
||||
const batchJobServiceTx = this.batchJobService_.withTransaction(manager)
|
||||
const batchJob = await batchJobServiceTx.retrieve(data.id)
|
||||
try {
|
||||
await this.manager_.transaction(async (manager) => {
|
||||
const batchJobServiceTx = this.batchJobService_.withTransaction(manager)
|
||||
const batchJob = await batchJobServiceTx.retrieve(data.id)
|
||||
|
||||
const batchJobStrategy = this.strategyResolver_.resolveBatchJobByType(
|
||||
batchJob.type
|
||||
)
|
||||
const batchJobStrategy = this.strategyResolver_.resolveBatchJobByType(
|
||||
batchJob.type
|
||||
)
|
||||
|
||||
await batchJobServiceTx.setProcessing(batchJob.id)
|
||||
|
||||
try {
|
||||
await batchJobServiceTx.setProcessing(batchJob.id)
|
||||
await batchJobStrategy.withTransaction(manager).processJob(batchJob.id)
|
||||
await batchJobServiceTx.complete(batchJob.id)
|
||||
} catch (e) {
|
||||
await this.batchJobService_.setFailed(batchJob.id, e.message)
|
||||
throw e
|
||||
}
|
||||
})
|
||||
})
|
||||
} catch (e) {
|
||||
await this.batchJobService_.setFailed(data.id, e.message)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user