import BatchReader from "./BatchReader" ; import BatchProcessor from "./BatchProcessor" ; import BatchWriter from "./BatchWriter" ; import AbstractJob from "./AbstractJob" ; export default class BatchJob extends AbstractJob { constructor ( public jobName , private reader , private processors , private writer ) { super ( jobName ) ; } protected async doRun ( executionContext ? ) { await this . reader . open ( executionContext ) ; while ( true ) { let item = await this . reader . read ( executionContext ) ; if ( item === null ) break ; await this . processItem ( item , executionContext ) ; } await this . reader . close ( executionContext ) ; } private async processItem ( item , executionContext ? ) { for ( let processor of this . processors ) { item = await processor . process ( item , executionContext ) ; } await this . writer . write ( item , executionContext ) ; } }