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
|
||||
*/
|
||||
@Component
|
||||
public class ApplicationStatusListener {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationStatusListener.class);
|
||||
public class DeclarationStatusListener {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DeclarationStatusListener.class);
|
||||
private final ObjectMapper mapper;
|
||||
private final UserApplicationListService applicationService;
|
||||
private final EncryptionService encryptionService;
|
||||
private final JwtTokenService jwtTokenService;
|
||||
|
||||
public ApplicationStatusListener(ObjectMapper mapper,
|
||||
public DeclarationStatusListener(ObjectMapper mapper,
|
||||
UserApplicationListService applicationService, EncryptionService encryptionService,
|
||||
JwtTokenService jwtTokenService) {
|
||||
this.mapper = mapper;
|
||||
|
|
@ -205,7 +205,9 @@ export class UserManagementService extends Behavior {
|
|||
if (code !== '200') {
|
||||
this.saveError(appNumber, response.msg);
|
||||
}
|
||||
this.statusUpdateService.trackApplication(appNumber);
|
||||
else {
|
||||
this.statusUpdateService.trackDeclaration(appNumber);
|
||||
}
|
||||
})
|
||||
.catch(reason => {
|
||||
console.error("Error while executing request:", reason.toString());
|
||||
|
|
|
|||
|
|
@ -19,13 +19,13 @@ export class StatusUpdateService {
|
|||
}
|
||||
|
||||
public statusMessage = new BehaviorSubject<any>(null);
|
||||
private pendingApplications = new Map<number, number>();
|
||||
private pendingDeclarations = new Map<number, number>();
|
||||
private pollingInterval: any;
|
||||
private readonly MAX_ATTEMPTS = 12;
|
||||
|
||||
public trackApplication(appNumber: number): void {
|
||||
if (!this.pendingApplications.has(appNumber)) {
|
||||
this.pendingApplications.set(appNumber, 0);
|
||||
public trackDeclaration(appNumber: number): void {
|
||||
if (!this.pendingDeclarations.has(appNumber)) {
|
||||
this.pendingDeclarations.set(appNumber, 0);
|
||||
this.startPolling();
|
||||
}
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ export class StatusUpdateService {
|
|||
}
|
||||
|
||||
private startPolling(): void {
|
||||
if (this.pendingApplications.size === 0 || this.pollingInterval) {
|
||||
if (this.pendingDeclarations.size === 0 || this.pollingInterval) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ export class StatusUpdateService {
|
|||
}
|
||||
|
||||
private checkPendingStatuses(): void {
|
||||
const appNumbers = Array.from(this.pendingApplications.keys());
|
||||
const appNumbers = Array.from(this.pendingDeclarations.keys());
|
||||
if (appNumbers.length === 0) {
|
||||
this.stopPolling();
|
||||
return;
|
||||
|
|
@ -67,32 +67,32 @@ export class StatusUpdateService {
|
|||
.toPromise()
|
||||
.then(responses => {
|
||||
responses.forEach(response => {
|
||||
const attemptCount = (this.pendingApplications.get(response.appNumber) || 0) + 1;
|
||||
this.pendingApplications.set(response.appNumber, attemptCount);
|
||||
const attemptCount = (this.pendingDeclarations.get(response.appNumber) || 0) + 1;
|
||||
this.pendingDeclarations.set(response.appNumber, attemptCount);
|
||||
|
||||
if (response.status !== 'SENT') {
|
||||
this.pendingApplications.delete(response.appNumber);
|
||||
this.pendingDeclarations.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}`);
|
||||
this.pendingDeclarations.delete(response.appNumber);
|
||||
console.warn(`Max attempts exceeded for declaration ${response.appNumber}`);
|
||||
}
|
||||
});
|
||||
|
||||
if (this.pendingApplications.size === 0) {
|
||||
if (this.pendingDeclarations.size === 0) {
|
||||
this.stopPolling();
|
||||
}
|
||||
})
|
||||
.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);
|
||||
const attemptCount = (this.pendingDeclarations.get(appNumber) || 0) + 1;
|
||||
this.pendingDeclarations.set(appNumber, attemptCount);
|
||||
|
||||
if (attemptCount >= this.MAX_ATTEMPTS) {
|
||||
this.pendingApplications.delete(appNumber);
|
||||
console.warn(`Max attempts exceeded for application ${appNumber} due to errors`);
|
||||
this.pendingDeclarations.delete(appNumber);
|
||||
console.warn(`Max attempts exceeded for declaration ${appNumber} due to errors`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue