+ dataSubscription(): Subscription {
+ let prodId = [];
+ const jobs$ = this.eiSvc.getProducerIds().pipe(
+ tap((data) => (prodId = data)),
+ mergeMap((prodIds) =>
+ forkJoin(prodIds.map((id) => this.eiSvc.getJobsForProducer(id)))
+ ),
+ finalize(() => this.loadingSubject$.next(false))
+ );
+
+ const refreshedJobs$ = this.refresh$
+ .pipe(
+ switchMap((_) => timer(0, 10000).pipe(
+ tap((_) => {
+ this.loadingSubject$.next(true);
+ }),
+ switchMap((_) => jobs$),
+ map((response) => this.extractJobs(prodId, response))
+ )
+ )
+ );
+
+ return this.polling$.pipe(
+ switchMap(p => {
+ return p ? refreshedJobs$ : EMPTY;
+ })
+ ).subscribe();
+ }
+