SUPPORT-9416: fix
This commit is contained in:
parent
38a95b7ec0
commit
dc9eec7fda
6 changed files with 66 additions and 36 deletions
|
|
@ -7,7 +7,7 @@ import {
|
|||
TextField,
|
||||
Visible
|
||||
} from "@webbpm/base-package";
|
||||
import {HttpClient, HttpErrorResponse, HttpResponse} from "@angular/common/http";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {FormField} from "../field/FormField";
|
||||
import {AuthorizationService} from "../../../modules/app/service/authorization.service";
|
||||
import {ApplicationKind} from "../enum/ApplicationKind";
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {Injectable, OnDestroy} from "@angular/core";
|
||||
import {Injectable} from "@angular/core";
|
||||
import {Subject} from "rxjs";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
|
||||
|
|
|
|||
|
|
@ -20,23 +20,30 @@ export class StatusUpdateService {
|
|||
}
|
||||
|
||||
public statusMessage = new BehaviorSubject<any>(null);
|
||||
private pendingApplications = new Set<number>();
|
||||
private pendingApplications = new Map<number, number>();
|
||||
private pollingInterval: any;
|
||||
private readonly MAX_ATTEMPTS = 12;
|
||||
|
||||
public trackApplication(appNumber: number): void {
|
||||
this.pendingApplications.add(appNumber);
|
||||
this.startPolling();
|
||||
if (!this.pendingApplications.has(appNumber)) {
|
||||
this.pendingApplications.set(appNumber, 0);
|
||||
this.startPolling();
|
||||
}
|
||||
}
|
||||
|
||||
public publishStatus(appNumber: number, accepted: boolean) {
|
||||
this.statusMessage.next({
|
||||
appNumber: appNumber,
|
||||
status: accepted ? ApplicationStatus.ACCEPTED : ApplicationStatus.AGREED
|
||||
status: accepted
|
||||
? ApplicationStatus.ACCEPTED
|
||||
: ApplicationStatus.AGREED
|
||||
});
|
||||
}
|
||||
|
||||
private startPolling(): void {
|
||||
if (this.pendingApplications.size === 0 || this.pollingInterval) return;
|
||||
if (this.pendingApplications.size === 0 || this.pollingInterval) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.pollingInterval = setInterval(() => {
|
||||
this.checkPendingStatuses();
|
||||
|
|
@ -51,7 +58,7 @@ export class StatusUpdateService {
|
|||
}
|
||||
|
||||
private checkPendingStatuses(): void {
|
||||
const appNumbers = Array.from(this.pendingApplications);
|
||||
const appNumbers = Array.from(this.pendingApplications.keys());
|
||||
if (appNumbers.length === 0) {
|
||||
this.stopPolling();
|
||||
return;
|
||||
|
|
@ -61,16 +68,34 @@ export class StatusUpdateService {
|
|||
.toPromise()
|
||||
.then(responses => {
|
||||
responses.forEach(response => {
|
||||
const attemptCount = (this.pendingApplications.get(response.appNumber) || 0) + 1;
|
||||
this.pendingApplications.set(response.appNumber, attemptCount);
|
||||
|
||||
if (response.status !== 'SENT') {
|
||||
this.pendingApplications.delete(response.appNumber);
|
||||
this.publishStatus(response.appNumber, response.status === 'ACCEPTED');
|
||||
}
|
||||
else if (attemptCount >= this.MAX_ATTEMPTS) {
|
||||
this.pendingApplications.delete(response.appNumber);
|
||||
console.warn(`Max attempts exceeded for application ${response.appNumber}`);
|
||||
}
|
||||
});
|
||||
|
||||
if (this.pendingApplications.size === 0) {
|
||||
this.stopPolling();
|
||||
}
|
||||
})
|
||||
.catch(err => console.error('Failed to check statuses', err));
|
||||
.catch(err => {
|
||||
console.error('Failed to check statuses', err);
|
||||
appNumbers.forEach(appNumber => {
|
||||
const attemptCount = (this.pendingApplications.get(appNumber) || 0) + 1;
|
||||
this.pendingApplications.set(appNumber, attemptCount);
|
||||
|
||||
if (attemptCount >= this.MAX_ATTEMPTS) {
|
||||
this.pendingApplications.delete(appNumber);
|
||||
console.warn(`Max attempts exceeded for application ${appNumber} due to errors`);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue