Skip to content

Commit d40a293

Browse files
committed
[DSC-1852] Fix issue with process notification which were frozen without updating the status of the process
1 parent 5320325 commit d40a293

4 files changed

Lines changed: 52 additions & 51 deletions

File tree

src/app/core/data/processes/process-data.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ export class ProcessDataService extends IdentifiableDataService<Process> impleme
123123
* @param processId The ID of the process
124124
*/
125125
getProcess(processId: string): Observable<RemoteData<Process>> {
126-
const href$ = this.getProcessEndpoint(processId);
127-
return this.findByHref(href$,false);
126+
return this.findById(processId, false);
128127
}
129128

130129
/**

src/app/shared/notifications/process-notification/process-notification.component.html

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="notification alert {{notificationType}} alert-dismissible m-3 shadow" role="alert"
1+
<div class="notification alert {{(notificationType$ | async)}} alert-dismissible m-3 shadow" role="alert"
22
[@enterLeave]="animate">
33

44
<button *ngIf="notification.options.clickToClose"
@@ -25,8 +25,8 @@
2525
</strong>
2626
</div>
2727

28-
<span *ngIf="(finished | async)" class="notification-content pl-1">
29-
{{process.processStatus.toString() | titlecase}}
28+
<span *ngIf="(finished | async)" class="notification-content pl-1">
29+
{{(processStatus$ | async) | translate}}
3030
</span>
3131
<span *ngIf="!(finished | async)" class="notification-content pl-1">
3232
{{'process.new.notification.process.processing' | translate}}
@@ -37,17 +37,13 @@
3737
</div>
3838
</div>
3939

40-
<div *ngIf="(finished | async) && files && files?.length > 0">
40+
<div *ngIf="(finished | async) && (files$ | async)?.length > 0">
4141
<div class="notification-content pl-1">{{ 'process.new.notification.process.files' | translate}}</div>
42+
<ds-file-download-link class="pl-1" *ngFor="let file of (files$ | async); let last=last;" [bitstream]="file">
43+
<span>{{getFileName(file)}}</span>
44+
<span>({{(file?.sizeBytes) | dsFileSize }})</span>
45+
</ds-file-download-link>
4246
</div>
43-
44-
<div class="pl-2" *ngIf="(finished | async) && files && files?.length > 0">
45-
<ds-file-download-link *ngFor="let file of files; let last=last;" [bitstream]="file">
46-
<span>{{getFileName(file)}}</span>
47-
<span>({{(file?.sizeBytes) | dsFileSize }})</span>
48-
</ds-file-download-link>
49-
</div>
50-
5147
</div>
5248

5349

src/app/shared/notifications/process-notification/process-notification.component.ts

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ import { IProcessNotification } from '../models/process-notification.model';
2626
import { ProcessDataService } from '../../../core/data/processes/process-data.service';
2727
import { Process } from '../../../process-page/processes/process.model';
2828
import { Bitstream } from '../../../core/shared/bitstream.model';
29-
import { getFirstCompletedRemoteData, getFirstSucceededRemoteListPayload } from '../../../core/shared/operators';
29+
import {
30+
getAllCompletedRemoteData, getFirstCompletedRemoteData
31+
} from '../../../core/shared/operators';
3032
import { DSONameService } from '../../../core/breadcrumbs/dso-name.service';
3133
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
34+
import { filter, map, switchMap, take } from 'rxjs/operators';
35+
import { RemoteData } from '../../../core/data/remote-data';
3236

3337
@Component({
3438
selector: 'ds-process-notification',
@@ -84,7 +88,7 @@ export class ProcessNotificationComponent implements OnInit, OnDestroy {
8488
/**
8589
* The process that is being checked.
8690
*/
87-
public process: Process;
91+
public processStatus$: BehaviorSubject<string> = new BehaviorSubject('');
8892

8993
/**
9094
* If process checking is finished.
@@ -94,12 +98,12 @@ export class ProcessNotificationComponent implements OnInit, OnDestroy {
9498
/**
9599
* Files generated from process end.
96100
*/
97-
public files: Bitstream[];
101+
public files$: BehaviorSubject<Bitstream[]> = new BehaviorSubject<Bitstream[]>([]);
98102

99103
/**
100104
* Type of the notification visualisation.
101105
*/
102-
public notificationType = 'alert-info';
106+
public notificationType$: BehaviorSubject<string> = new BehaviorSubject('alert-info');
103107

104108
constructor(private notificationService: NotificationsService,
105109
private domSanitizer: DomSanitizer,
@@ -114,55 +118,53 @@ export class ProcessNotificationComponent implements OnInit, OnDestroy {
114118
*/
115119
ngOnInit(): void {
116120
this.animate = this.notification.options.animate + NotificationAnimationsStatus.In;
117-
this.initCheckProcess();
121+
this.pollUntilProcessFinished();
118122
this.html = this.notification.html;
119123
this.contentType(this.notification.title, 'title');
120124
}
121125

122126
/**
123-
* Initialization of timer.
127+
* Poll process endpoint until it's finished.
124128
*/
125-
initCheckProcess() {
126-
const source = timer(0, this.notification.checkTime);
127-
this.sub = source.subscribe(val => {
128-
this.checkProcess();
129+
pollUntilProcessFinished() {
130+
timer(0, 5000).pipe(
131+
switchMap(() => this.processService.getProcess(this.notification.processId)),
132+
getAllCompletedRemoteData(),
133+
filter((res: RemoteData<Process>) => res?.payload?.processStatus.toString() === 'COMPLETED' || res?.payload?.processStatus.toString() === 'FAILED'),
134+
take(1),
135+
).subscribe((res: RemoteData<Process>) => {
136+
this.pollingFinishedFor(res.payload);
129137
});
130138
}
131139

132140
/**
133-
* Send request to get the updated process information.
134-
*/
135-
checkProcess() {
136-
this.processService.getProcess(this.notification.processId)
137-
.pipe(getFirstCompletedRemoteData())
138-
.subscribe( (res) => {
139-
this.process = res.payload;
140-
this.zone.run(() => this.cdr.detectChanges());
141-
if (this.process.processStatus.toString() === 'COMPLETED' || this.process.processStatus.toString() === 'FAILED') {
142-
this.sub.unsubscribe();
143-
if (this.process.processStatus.toString() === 'COMPLETED') {
144-
this.notificationType = 'alert-success';
145-
this.getFiles();
146-
} else {
147-
this.notificationType = 'alert-danger';
148-
this.zone.run(() => this.cdr.detectChanges());
149-
}
150-
this.finished.next(true);
151-
}
152-
});
141+
* Handle process results
142+
*
143+
* @param process The process finished
144+
*/
145+
pollingFinishedFor(process: Process) {
146+
const processStatus = process.processStatus.toString();
147+
if (processStatus === 'COMPLETED') {
148+
this.notificationType$.next('alert-success');
149+
this.processStatus$.next('process.new.notification.process.status.completed');
150+
this.getFiles();
151+
} else {
152+
this.processStatus$.next('process.new.notification.process.status.failed');
153+
this.notificationType$.next('alert-danger');
154+
}
155+
this.finished.next(true);
153156
}
154157

155158
/**
156159
* When the process is completed get the files output.
157160
*/
158161
getFiles() {
159-
this.processService.getFiles(this.notification.processId)
160-
.pipe(
161-
getFirstSucceededRemoteListPayload(),
162-
)
163-
.subscribe( (files: Bitstream[]) => {
164-
this.files = files.filter( (file) => !this.getFileName(file).includes('.log'));
165-
this.zone.run(() => this.cdr.detectChanges());
162+
this.processService.getFiles(this.notification.processId).pipe(
163+
getFirstCompletedRemoteData(),
164+
map((response) => response.hasSucceeded ? response.payload.page : [])
165+
).subscribe( (files: Bitstream[]) => {
166+
const logFiles = files.filter( (file) => !this.getFileName(file).includes('.log'));
167+
this.files$.next(logFiles);
166168
});
167169
}
168170

src/assets/i18n/en.json5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4459,6 +4459,10 @@
44594459

44604460
"process.new.notification.process.files": "Output Files: ",
44614461

4462+
"process.new.notification.process.status.completed": "Completed",
4463+
4464+
"process.new.notification.process.status.failed": "Failed",
4465+
44624466
"process.new.header": "Create a new process",
44634467

44644468
"process.new.title": "Create a new process",

0 commit comments

Comments
 (0)