diff --git a/src/app/core/data/processes/process-data.service.ts b/src/app/core/data/processes/process-data.service.ts index 938895c276..a89e3c6fa3 100644 --- a/src/app/core/data/processes/process-data.service.ts +++ b/src/app/core/data/processes/process-data.service.ts @@ -6,7 +6,7 @@ import { HALEndpointService } from '../../shared/hal-endpoint.service'; import { Process } from '../../../process-page/processes/process.model'; import { PROCESS } from '../../../process-page/processes/process.resource-type'; import { Observable } from 'rxjs'; -import { switchMap, filter, distinctUntilChanged, find } from 'rxjs/operators'; +import { switchMap, filter, distinctUntilChanged, find, tap, throttleTime } from 'rxjs/operators'; import { PaginatedList } from '../paginated-list.model'; import { Bitstream } from '../../shared/bitstream.model'; import { RemoteData } from '../remote-data'; @@ -113,7 +113,6 @@ export class ProcessDataService extends IdentifiableDataService impleme } /** - * * @param searchMethod The search method for the Process * @param options The FindListOptions object * @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's @@ -129,6 +128,28 @@ export class ProcessDataService extends IdentifiableDataService impleme return this.searchData.searchBy(searchMethod, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); } + /** + * @param searchMethod The search method for the Process + * @param options The FindListOptions object + * @param pollingIntervalInMs The interval by which the search will be repeated + * @param linksToFollow List of {@link FollowLinkConfig} that indicate which + * {@link HALLink}s should automatically be resolved. + * @return {Observable>>} + * Return an observable that emits a paginated list of processes every interval + */ + autoRefreshingSearchBy(searchMethod: string, options?: FindListOptions, pollingIntervalInMs: number = 5000, ...linksToFollow: FollowLinkConfig[]): Observable>> { + return this.searchBy(searchMethod, options, false, true, ...linksToFollow) + .pipe( + getAllCompletedRemoteData(), + throttleTime(pollingIntervalInMs), + tap((processListRD: RemoteData>) => { + setTimeout(() => { + this.invalidateByHref(processListRD.payload._links.self.href); + }, pollingIntervalInMs); + }), + ); + } + /** * Delete an existing object on the server * @param objectId The id of the object to be removed