Skip to content

Commit 1b2944f

Browse files
Reprocessor Changes
Signed-off-by: trialblazerseee <84778104+trialblazerseee@users.noreply.github.com>
1 parent c320160 commit 1b2944f

5 files changed

Lines changed: 40 additions & 25 deletions

File tree

registration-processor/registration-processor-registration-status-service-impl/src/main/java/io/mosip/registration/processor/status/repositary/RegistrationRepositary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public List<String> getProcessedOrProcessingRegIds(@Param("regIds") List<String>
6565
@Query("SELECT registration FROM RegistrationStatusEntity registration WHERE registration.regId = :regId AND registration.registrationType = :registrationType AND registration.iteration = :iteration")
6666
public List<RegistrationStatusEntity> getByIdAndProcessAndIteration(@Param("regId") String regId, @Param("registrationType") String process, @Param("iteration") int iteration);
6767

68-
@Query(value ="SELECT * FROM registration r WHERE r.process IN :processes AND r.latest_trn_status_code IN :status AND r.reg_process_retry_count<=:reprocessCount AND r.latest_trn_dtimes <:timeDifference AND r.status_code NOT IN :statusCodes AND r.reg_stage_name NOT IN :excludeStageNames order by r.latest_trn_dtimes LIMIT :fetchSize ", nativeQuery = true)
68+
@Query(value ="SELECT * FROM registration r WHERE r.process IN :processList AND r.latest_trn_status_code IN :status AND r.reg_process_retry_count<=:reprocessCount AND r.latest_trn_dtimes <:timeDifference AND r.status_code NOT IN :statusCodes AND r.reg_stage_name NOT IN :excludeStageNames order by r.latest_trn_dtimes LIMIT :fetchSize ", nativeQuery = true)
6969
public List<RegistrationStatusEntity> getUnProcessedPackets(@Param("processList") List<String> processes, @Param("status") List<String> status,@Param("reprocessCount") Integer reprocessCount,@Param("timeDifference") LocalDateTime timeDifference,@Param("statusCodes") List<String> statusCodes,@Param("fetchSize") Integer fetchSize,@Param("excludeStageNames") List<String> excludeStageNames);
7070

7171
}

registration-processor/workflow-engine/registration-processor-reprocessor/src/main/java/io/mosip/registration/processor/reprocessor/ReprocessorApplication.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public static void main(String[] args) {
2121
"io.mosip.registration.processor.reprocessor.config",
2222
"io.mosip.registration.processor.status.config",
2323
"io.mosip.registration.processor.core.kernel.beans",
24-
"io.mosip.registration.processor.packet.storage.config");
24+
"io.mosip.registration.processor.packet.storage.config",
25+
"io.mosip.registration.processor.reprocessor.service.impl");
2526
ctx.refresh();
2627
ReprocessorVerticle reprocessorVerticle = ctx.getBean(ReprocessorVerticle.class);
2728
reprocessorVerticle.deployVerticle();
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package io.mosip.registration.processor.reprocessor.service;
22

3-
43
import io.mosip.registration.processor.status.dto.InternalRegistrationStatusDto;
5-
64
import java.util.List;
5+
import java.util.concurrent.CompletableFuture;
76

87
public interface ReprocessorVerticalService {
98

10-
List<InternalRegistrationStatusDto> fetchUnProcessedPackets(List<String> processList, Integer fetchSize, long elapseTime, Integer reprocessCount,
11-
List<String> status, List<String> excludeStageNames);
9+
CompletableFuture<List<InternalRegistrationStatusDto>> fetchUnProcessedPackets(
10+
List<String> processList,
11+
Integer fetchSize,
12+
long elapseTime,
13+
Integer reprocessCount,
14+
List<String> status,
15+
List<String> excludeStageNames);
1216
}

registration-processor/workflow-engine/registration-processor-reprocessor/src/main/java/io/mosip/registration/processor/reprocessor/service/impl/ReprocessorVerticalServiceImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
import org.springframework.scheduling.annotation.Async;
99
import org.springframework.stereotype.Service;
1010

11-
import java.util.Arrays;
1211
import java.util.List;
12+
import java.util.concurrent.CompletableFuture;
1313

1414
@Service
1515
public class ReprocessorVerticalServiceImpl implements ReprocessorVerticalService {
1616

1717
/** The registration status service. */
1818
@Autowired
19-
RegistrationStatusService<String, InternalRegistrationStatusDto, RegistrationStatusDto> registrationStatusService;
20-
19+
private RegistrationStatusService<String, InternalRegistrationStatusDto, RegistrationStatusDto> registrationStatusService;
2120

2221
@Override
2322
@Async
24-
public List<InternalRegistrationStatusDto> fetchUnProcessedPackets(List<String> processList, Integer fetchSize, long elapseTime, Integer reprocessCount, List<String> status, List<String> excludeStageNames) {
25-
return registrationStatusService.getUnProcessedPackets(processList, fetchSize, elapseTime,
23+
public CompletableFuture<List<InternalRegistrationStatusDto>> fetchUnProcessedPackets(List<String> processList, Integer fetchSize, long elapseTime, Integer reprocessCount, List<String> status, List<String> excludeStageNames) {
24+
List<InternalRegistrationStatusDto> result = registrationStatusService.getUnProcessedPackets(processList, fetchSize, elapseTime,
2625
reprocessCount, status, excludeStageNames);
26+
return CompletableFuture.completedFuture(result);
2727
}
2828
}

registration-processor/workflow-engine/registration-processor-reprocessor/src/main/java/io/mosip/registration/processor/reprocessor/verticle/ReprocessorVerticle.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ public class ReprocessorVerticle extends MosipVerticleAPIManager {
155155
public void deployVerticle() {
156156
mosipEventBus = this.getEventBus(this, clusterManagerUrl);
157157
deployScheduler(getVertx());
158-
159158
}
160159

161160
/**
@@ -371,7 +370,11 @@ public MessageDTO process(MessageDTO object) {
371370
auditLogRequestBuilder.createAuditRequestBuilder(description.getMessage(), eventId, eventName,
372371
eventType, moduleId, moduleName, registrationId);
373372
}
374-
},sendExecutor)).collect(Collectors.toList());
373+
},sendExecutor).exceptionally(ex -> {
374+
regProcLogger.error(LoggerFileConstant.SESSIONID.toString(),
375+
description.getCode() + " -- ",
376+
PlatformErrorMessages.RPR_RGS_REGISTRATION_TABLE_NOT_ACCESSIBLE.getMessage(), ex.toString()); return null;
377+
})).collect(Collectors.toList());
375378

376379
CompletableFuture.allOf(sendTasks.toArray(new CompletableFuture[0])).join();
377380
}
@@ -384,7 +387,7 @@ public MessageDTO process(MessageDTO object) {
384387
description.getCode() + " -- ",
385388
PlatformErrorMessages.RPR_RGS_REGISTRATION_TABLE_NOT_ACCESSIBLE.getMessage(), e.toString());
386389

387-
}catch (Exception ex) {
390+
} catch (Exception ex) {
388391
isTransactionSuccessful.set(false);
389392
description.setMessage(PlatformErrorMessages.REPROCESSOR_VERTICLE_FAILED.getMessage());
390393
description.setCode(PlatformErrorMessages.REPROCESSOR_VERTICLE_FAILED.getCode());
@@ -519,7 +522,7 @@ private void fetchPacketsIfBelowThreshold(LinkedHashMap<String, Integer> require
519522
Deque<?> cachedPackets = packetCacheMap.get(entry.getKey());
520523
return cachedPackets == null || cachedPackets.size() < threasholdForFetch;
521524
})
522-
.map(entry -> CompletableFuture.runAsync(() -> {
525+
.map(entry -> {
523526
String key = entry.getKey();
524527

525528
// Parse key into Process & Status
@@ -528,16 +531,23 @@ private void fetchPacketsIfBelowThreshold(LinkedHashMap<String, Integer> require
528531
List<String> statusValList = entryPair.getValue();
529532

530533
// Fetch unprocessed packets
531-
List<InternalRegistrationStatusDto> registratiobRegistrationStatusDtos = reprocessorVerticalService.fetchUnProcessedPackets(processList, recordFetchSize, elapseTime,
532-
reprocessCount, (!statusValList.isEmpty() ? statusValList : statusList), reprocessExcludeStageNames);
533-
534-
// Thread-safe update to cache
535-
packetCacheMap.compute(key, (k, existingList) -> {
536-
if (existingList == null) return new ConcurrentLinkedDeque<>(registratiobRegistrationStatusDtos);
537-
existingList.addAll(new ArrayList<>(registratiobRegistrationStatusDtos));
538-
return existingList;
539-
});
540-
}, fetchExecutor))
534+
return reprocessorVerticalService.fetchUnProcessedPackets(processList, recordFetchSize, elapseTime,
535+
reprocessCount, (!statusValList.isEmpty() ? statusValList : statusList), reprocessExcludeStageNames)
536+
.thenAccept(result -> {
537+
// Thread-safe update to cache
538+
packetCacheMap.compute(key, (k, existingList) -> {
539+
if (existingList == null) return new ConcurrentLinkedDeque<>(result);
540+
existingList.addAll(new ArrayList<>(result));
541+
return existingList;
542+
});
543+
})
544+
.exceptionally(ex -> {
545+
regProcLogger.error(LoggerFileConstant.SESSIONID.toString(),
546+
"Error Fetching UnprocessedPackets -- ",
547+
" Error Triggered for Process [" + String.join(",", processList) + "] and Status [" + String.join(",", (!statusValList.isEmpty() ? statusValList : statusList)) + "]", ExceptionUtils.getStackTrace(ex));
548+
return null;
549+
});
550+
})
541551
.collect(Collectors.toList());
542552

543553
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();

0 commit comments

Comments
 (0)