Skip to content

Commit

Permalink
feat(admin-ui): Improve polling logic for jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Jun 6, 2019
1 parent 8066d9b commit ced3990
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions admin-ui/src/app/core/providers/job-queue/job-queue.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import { Injectable, OnDestroy } from '@angular/core';
import { combineLatest, interval, Observable, Subject, Subscription } from 'rxjs';
import {
debounceTime,
distinctUntilChanged,
map,
scan,
shareReplay,
throttle,
throttleTime,
} from 'rxjs/operators';
import { assertNever } from 'shared/shared-utils';
import { interval, Observable, of, Subject, Subscription } from 'rxjs';
import { debounceTime, map, mapTo, scan, shareReplay, switchMap } from 'rxjs/operators';

import { GetJobInfo, JobInfoFragment, JobState } from '../../../common/generated-types';
import { JobInfoFragment, JobState } from '../../../common/generated-types';
import { DataService } from '../../../data/providers/data.service';

@Injectable()
Expand All @@ -37,14 +28,24 @@ export class JobQueueService implements OnDestroy {
shareReplay(1),
);

this.subscription = combineLatest(this.activeJobs$, interval(5000))
.pipe(throttleTime(5000))
.subscribe(([jobs]) => {
this.dataService.settings.pollJobs(jobs.map(j => j.id)).single$.subscribe(data => {
data.jobs.forEach(job => {
this.updateJob$.next(job);
this.subscription = this.activeJobs$
.pipe(
switchMap(jobs => {
if (jobs.length) {
return interval(2500).pipe(mapTo(jobs));
} else {
return of([]);
}
}),
)
.subscribe(jobs => {
if (jobs.length) {
this.dataService.settings.pollJobs(jobs.map(j => j.id)).single$.subscribe(data => {
data.jobs.forEach(job => {
this.updateJob$.next(job);
});
});
});
}
});
}

Expand Down

0 comments on commit ced3990

Please sign in to comment.