import { ToolingLog } from '@kbn/dev-utils' ; import * as Rx from 'rxjs' ; import { tap } from 'rxjs/operators' ; import { OptimizerUpdate } from './run_optimizer' ; const PROGRESS_REPORT_INTERVAL = 10000 ; export function logOptimizerProgress ( log ) { return ( update$ ) => new Rx . Observable ( ( subscriber ) => { const allBundleIds = new Set ( ) ; const completeBundles = new Set ( ) ; let loggedCompletion = new Set ( ) ; subscriber . add ( update$ . pipe ( tap ( ( { state } ) => { for ( const { bundleId , type } of state . compilerStates ) { allBundleIds . add ( bundleId ) ; if ( type !== 'running' ) { completeBundles . add ( bundleId ) ; } } } ) , tap ( subscriber ) ) . subscribe ( ) ) ; subscriber . add ( Rx . interval ( PROGRESS_REPORT_INTERVAL ) . subscribe ( ( ) => { if ( completeBundles . size - loggedCompletion . size < 3 ) { return ; } log . info ( `[${ completeBundles . size }/${ allBundleIds . size }] initial bundle builds complete` ) ; loggedCompletion = new Set ( completeBundles ) ; } , ( error ) => subscriber . error ( error ) ) ) ; } ) ; }