return (source) => source.pipe(operators_1.retryWhen(e => e.pipe(operators_1.scan((errorCount, error) => { common_1.Logger.error(`Unable to connect to the database. Retrying (${errorCount + 1})...`, error.stack, 'TypeOrmModule'); if (errorCount + 1 >= retryAttempts) { throw error; } return errorCount + 1; }, 0), operators_1.delay(retryDelay))));
subscribe() { const mesos$ = container.get(MesosStreamType); const masterRequest$ = container.get(MesosMasterRequestType).pipe( tap(response => { const master = mesosStreamParsers.getMaster( this.getMaster(), JSON.parse(response) ); CompositeState.addState(master); this.setMaster(master); }) ); const parsers = pipe(...Object.values(mesosStreamParsers)); const data$ = mesos$.pipe( merge(masterRequest$), distinctUntilChanged(), map(message => parsers(this.getLastMesosState(), JSON.parse(message))), tap(state => this.setState(state), console.error) ); const wait$ = masterRequest$.pipe(zip(mesos$.pipe(take(1)))); const eventTrigger$ = data$.pipe( merge( // A lot of DCOS UI rely on the MesosStateStore emitting // MESOS_STATE_CHANGE events. After the switch to the stream, we lost this // event. To avoid a deeper refactor, we introduced this fake emitter. // // TODO: https://jira.mesosphere.com/browse/DCOS-18277 interval(Config.getRefreshRate()) ) ); // Since we introduced the fake event above, we have to guarantee certain // refresh limits to the UI. They are: // // MOST once every (Config.getRefreshRate() * 0.5) ms. due to sampleTime. // LEAST once every tick of Config.getRefreshRate() ms in // Observable.interval // // TODO: https://jira.mesosphere.com/browse/DCOS-18277 this.stream = wait$ .pipe( concat(eventTrigger$), sampleTime(Config.getRefreshRate() * 0.5), retryWhen(linearBackoff(RETRY_DELAY, -1, MAX_RETRY_DELAY)) ) .subscribe( () => Promise.resolve().then(this.onStreamData), this.onStreamError ); }