SUPPORT-9416: fix from review
This commit is contained in:
parent
cf09440280
commit
72976e5f40
3 changed files with 22 additions and 20 deletions
|
|
@ -18,14 +18,14 @@ import ru.micord.ervu.account_applications.service.UserApplicationListService;
|
||||||
* @author Adel Kalimullin
|
* @author Adel Kalimullin
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class ApplicationStatusListener {
|
public class DeclarationStatusListener {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationStatusListener.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(DeclarationStatusListener.class);
|
||||||
private final ObjectMapper mapper;
|
private final ObjectMapper mapper;
|
||||||
private final UserApplicationListService applicationService;
|
private final UserApplicationListService applicationService;
|
||||||
private final EncryptionService encryptionService;
|
private final EncryptionService encryptionService;
|
||||||
private final JwtTokenService jwtTokenService;
|
private final JwtTokenService jwtTokenService;
|
||||||
|
|
||||||
public ApplicationStatusListener(ObjectMapper mapper,
|
public DeclarationStatusListener(ObjectMapper mapper,
|
||||||
UserApplicationListService applicationService, EncryptionService encryptionService,
|
UserApplicationListService applicationService, EncryptionService encryptionService,
|
||||||
JwtTokenService jwtTokenService) {
|
JwtTokenService jwtTokenService) {
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
|
|
@ -205,7 +205,9 @@ export class UserManagementService extends Behavior {
|
||||||
if (code !== '200') {
|
if (code !== '200') {
|
||||||
this.saveError(appNumber, response.msg);
|
this.saveError(appNumber, response.msg);
|
||||||
}
|
}
|
||||||
this.statusUpdateService.trackApplication(appNumber);
|
else {
|
||||||
|
this.statusUpdateService.trackDeclaration(appNumber);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(reason => {
|
.catch(reason => {
|
||||||
console.error("Error while executing request:", reason.toString());
|
console.error("Error while executing request:", reason.toString());
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,13 @@ export class StatusUpdateService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public statusMessage = new BehaviorSubject<any>(null);
|
public statusMessage = new BehaviorSubject<any>(null);
|
||||||
private pendingApplications = new Map<number, number>();
|
private pendingDeclarations = new Map<number, number>();
|
||||||
private pollingInterval: any;
|
private pollingInterval: any;
|
||||||
private readonly MAX_ATTEMPTS = 12;
|
private readonly MAX_ATTEMPTS = 12;
|
||||||
|
|
||||||
public trackApplication(appNumber: number): void {
|
public trackDeclaration(appNumber: number): void {
|
||||||
if (!this.pendingApplications.has(appNumber)) {
|
if (!this.pendingDeclarations.has(appNumber)) {
|
||||||
this.pendingApplications.set(appNumber, 0);
|
this.pendingDeclarations.set(appNumber, 0);
|
||||||
this.startPolling();
|
this.startPolling();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -40,7 +40,7 @@ export class StatusUpdateService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private startPolling(): void {
|
private startPolling(): void {
|
||||||
if (this.pendingApplications.size === 0 || this.pollingInterval) {
|
if (this.pendingDeclarations.size === 0 || this.pollingInterval) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,7 +57,7 @@ export class StatusUpdateService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkPendingStatuses(): void {
|
private checkPendingStatuses(): void {
|
||||||
const appNumbers = Array.from(this.pendingApplications.keys());
|
const appNumbers = Array.from(this.pendingDeclarations.keys());
|
||||||
if (appNumbers.length === 0) {
|
if (appNumbers.length === 0) {
|
||||||
this.stopPolling();
|
this.stopPolling();
|
||||||
return;
|
return;
|
||||||
|
|
@ -67,32 +67,32 @@ export class StatusUpdateService {
|
||||||
.toPromise()
|
.toPromise()
|
||||||
.then(responses => {
|
.then(responses => {
|
||||||
responses.forEach(response => {
|
responses.forEach(response => {
|
||||||
const attemptCount = (this.pendingApplications.get(response.appNumber) || 0) + 1;
|
const attemptCount = (this.pendingDeclarations.get(response.appNumber) || 0) + 1;
|
||||||
this.pendingApplications.set(response.appNumber, attemptCount);
|
this.pendingDeclarations.set(response.appNumber, attemptCount);
|
||||||
|
|
||||||
if (response.status !== 'SENT') {
|
if (response.status !== 'SENT') {
|
||||||
this.pendingApplications.delete(response.appNumber);
|
this.pendingDeclarations.delete(response.appNumber);
|
||||||
this.publishStatus(response.appNumber, response.status === 'ACCEPTED');
|
this.publishStatus(response.appNumber, response.status === 'ACCEPTED');
|
||||||
}
|
}
|
||||||
else if (attemptCount >= this.MAX_ATTEMPTS) {
|
else if (attemptCount >= this.MAX_ATTEMPTS) {
|
||||||
this.pendingApplications.delete(response.appNumber);
|
this.pendingDeclarations.delete(response.appNumber);
|
||||||
console.warn(`Max attempts exceeded for application ${response.appNumber}`);
|
console.warn(`Max attempts exceeded for declaration ${response.appNumber}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.pendingApplications.size === 0) {
|
if (this.pendingDeclarations.size === 0) {
|
||||||
this.stopPolling();
|
this.stopPolling();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error('Failed to check statuses', err);
|
console.error('Failed to check statuses', err);
|
||||||
appNumbers.forEach(appNumber => {
|
appNumbers.forEach(appNumber => {
|
||||||
const attemptCount = (this.pendingApplications.get(appNumber) || 0) + 1;
|
const attemptCount = (this.pendingDeclarations.get(appNumber) || 0) + 1;
|
||||||
this.pendingApplications.set(appNumber, attemptCount);
|
this.pendingDeclarations.set(appNumber, attemptCount);
|
||||||
|
|
||||||
if (attemptCount >= this.MAX_ATTEMPTS) {
|
if (attemptCount >= this.MAX_ATTEMPTS) {
|
||||||
this.pendingApplications.delete(appNumber);
|
this.pendingDeclarations.delete(appNumber);
|
||||||
console.warn(`Max attempts exceeded for application ${appNumber} due to errors`);
|
console.warn(`Max attempts exceeded for declaration ${appNumber} due to errors`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue