After successfully uploading a file to Firebase, I implemented a recursive function to listen for GCP trigger logs. Everything seems to be working well, but I'm facing an issue where the recursive expand function never exits.
Despite checking the values multiple times and seeing the "ENTERED" message in the console log, the recursive call continues indefinitely without throwing any errors. How can I forcefully break the recursive calls if a certain condition is met?
public getLog(filePath: string): Observable<object[]> {
try {
...
return this.getLogChunk()
.pipe(
expand((data: any) => {
if (!environment.production && data && data.entries & data.entries.length > 0) {
console.groupCollapsed('GCP Service Info [getLog]');
console.info('[fileName]', fileName);
console.info('[some - Finished]', data.entries.some((x: any) => x.textPayload.includes('Finished')));
console.info('[some - Filename]', data.entries.some((x: any) => x.textPayload.includes(fileName)));
console.info('[some - Finished - Filename]', data.entries.some((x: any) => x.textPayload.includes('Finished') && x.textPayload.includes(fileName)));
console.info('[filter - Filename]', data.entries.filter((x: any) => x.textPayload.includes(fileName)));
console.groupEnd();
}
if (data &&
data.entries &&
data.entries.some((x: any) => x.textPayload.includes('Finished') && x.textPayload.includes(fileName))) {
console.log('ENTERED!!!!!');
return of({});
}
return this.getLogChunk().pipe(delay(2000));
}),
map(res => res),
reduce((acc: object[], val: any) => acc.concat(val), new Array<object>())
);
}catch (e) {
if (!environment.production) {
console.groupCollapsed('GCP Service Error [getLog]');
console.error('[error]', e);
console.groupEnd();
}
throw new Error(e);
}
}
When calling the `getlog` function, I ensured that it is only triggered once after the upload is complete. However, since the recursive loop within `getlog` is infinite, the `[complete] ENTERED` event is never fired.
...
const uploadTask: AngularFireUploadTask = this.storage.upload(filePath, fileToUpload);
...
uploadTask.snapshotChanges()
.pipe(
filter(task => {
if (task) {
return task.state === firebase.storage.TaskState.SUCCESS
}
return false;
})
)
.subscribe(val => {
this.gcpService.getLog(filePath)
.subscribe({
next: data => console.log('[next] ENTERED'),
complete: () => {
console.log('[complete] ENTERED');
}
});
});
...