feat(medusa/product-export-strategy): Implement the Product export strategy (#1688)

This commit is contained in:
Adrien de Peretti authored and GitHub committed 2022-06-22 23:42:31 +02:00
1 parent 0e34800573
commit 7b09b8c36c
26 files changed
+2017 -106

No files matched your search

@@ -0,0 +1,57 @@
import BatchJobService from "../services/batch-job"
import EventBusService from "../services/event-bus"
import { StrategyResolverService } from "../services"
type InjectedDependencies = {
eventBusService: EventBusService
batchJobService: BatchJobService
strategyResolverService: StrategyResolverService
}
class BatchJobSubscriber {
private readonly eventBusService_: EventBusService
private readonly batchJobService_: BatchJobService
private readonly strategyResolver_: StrategyResolverService
constructor({
eventBusService,
batchJobService,
strategyResolverService,
}: InjectedDependencies) {
this.eventBusService_ = eventBusService
this.batchJobService_ = batchJobService
this.strategyResolver_ = strategyResolverService
this.eventBusService_
.subscribe(BatchJobService.Events.CREATED, this.preProcessBatchJob)
.subscribe(BatchJobService.Events.CONFIRMED, this.processBatchJob)
}
preProcessBatchJob = async (data): Promise<void> => {
const batchJob = await this.batchJobService_.retrieve(data.id)
const batchJobStrategy = this.strategyResolver_.resolveBatchJobByType(
batchJob.type
)
await batchJobStrategy.preProcessBatchJob(batchJob.id)
await this.batchJobService_.setPreProcessingDone(batchJob.id)
}
processBatchJob = async (data): Promise<void> => {
const batchJob = await this.batchJobService_.retrieve(data.id)
const batchJobStrategy = this.strategyResolver_.resolveBatchJobByType(
batchJob.type
)
await this.batchJobService_.setProcessing(batchJob.id)
await batchJobStrategy.processJob(batchJob.id)
await this.batchJobService_.complete(batchJob.id)
}
}
export default BatchJobSubscriber