fix(medusa): Export/import fixes including export fields that contains new line char (#2150)

This commit is contained in:
Adrien de Peretti
2022-09-12 15:53:45 +02:00
committed by GitHub
parent ee8fe3a88b
commit b6161d2404
22 changed files with 699 additions and 364 deletions
+36 -23
View File
@@ -1,26 +1,31 @@
import BatchJobService from "../services/batch-job"
import EventBusService from "../services/event-bus"
import { StrategyResolverService } from "../services"
import { EntityManager } from "typeorm"
type InjectedDependencies = {
eventBusService: EventBusService
batchJobService: BatchJobService
strategyResolverService: StrategyResolverService
manager: EntityManager
}
class BatchJobSubscriber {
private readonly eventBusService_: EventBusService
private readonly batchJobService_: BatchJobService
private readonly strategyResolver_: StrategyResolverService
private readonly manager_: EntityManager
constructor({
eventBusService,
batchJobService,
strategyResolverService,
manager,
}: InjectedDependencies) {
this.eventBusService_ = eventBusService
this.batchJobService_ = batchJobService
this.strategyResolver_ = strategyResolverService
this.manager_ = manager
this.eventBusService_
.subscribe(BatchJobService.Events.CREATED, this.preProcessBatchJob)
@@ -28,37 +33,45 @@ class BatchJobSubscriber {
}
preProcessBatchJob = async (data): Promise<void> => {
const batchJob = await this.batchJobService_.retrieve(data.id)
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.preProcessBatchJob(batchJob.id)
await this.batchJobService_.setPreProcessingDone(batchJob.id)
} catch (e) {
await this.batchJobService_.setFailed(batchJob.id)
throw e
}
try {
await batchJobStrategy
.withTransaction(manager)
.preProcessBatchJob(batchJob.id)
await batchJobServiceTx.setPreProcessingDone(batchJob.id)
} catch (e) {
await this.batchJobService_.setFailed(batchJob.id)
throw e
}
})
}
processBatchJob = async (data): Promise<void> => {
const batchJob = await this.batchJobService_.retrieve(data.id)
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 this.batchJobService_.setProcessing(batchJob.id)
await batchJobServiceTx.setProcessing(batchJob.id)
try {
await batchJobStrategy.processJob(batchJob.id)
await this.batchJobService_.complete(batchJob.id)
} catch (e) {
await this.batchJobService_.setFailed(batchJob.id)
throw e
}
try {
await batchJobStrategy.withTransaction(manager).processJob(batchJob.id)
await batchJobServiceTx.complete(batchJob.id)
} catch (e) {
await this.batchJobService_.setFailed(batchJob.id)
throw e
}
})
}
}