I am currently polling for the status of a process. My goal is to continue polling until I receive a status from the server that is not marked as IN_PROGRESS. At the same time, I want to update the status of the process in my store. Below is how I have been approaching this task:
pollForProcessStatusEffect = createEffect(() =>
this.actions$.pipe(
ofType(MigrationActions.importInProcess),
switchMap((payload) =>
this.pollForProcessStatus(payload.importedFileId).pipe(
map(data => MigrationActions.importProcessFinished(data.status)),
catchError(() => of(MigrationActions.importInProcess(payload.importedFileId)))
)
)
)
);
private pollForProcessStatus(importedFileId: number): Observable<ImportFileProcessStatus> {
return timer(0, 2000).pipe(
concatMap(() => this.apiClient.getImportProcessStatus(importedFileId)),
tap((importFileProcessStatus: ImportFileProcessStatus) =>
// This action won't be dispatched:
MigrationActions.importStatusUpdated(importFileProcessStatus)
),
takeWhile((importFileProcessStatus: ImportFileProcessStatus) =>
importFileProcessStatus.status === FileStatus.IN_PROGRESS, true
),
takeLast(1)
);
}
I've observed that the importStatusUpdated
action is not being triggered. I'm unsure if there's an issue with my approach.