added poll back
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package com.billpaymentservice.bbps.util;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.billpaymentservice.bbps.dto.ResponseModel;
|
||||
import com.billpaymentservice.bbps.dto.request.MerchantRequestModel;
|
||||
import com.billpaymentservice.bbps.entites.BBPSMerchantValidation;
|
||||
import com.billpaymentservice.bbps.exception.CustomException;
|
||||
@@ -11,6 +15,7 @@ import com.billpaymentservice.bbps.repository.MerchantRepository;
|
||||
|
||||
|
||||
@Component
|
||||
|
||||
public class Helper {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Helper.class);
|
||||
@@ -24,7 +29,42 @@ public class Helper {
|
||||
* @param requestModel MerchantRequestModel containing merchant details
|
||||
* @return true if merchant exists and is active
|
||||
* @throws CustomException if merchant is invalid or inactive
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public <T> void startPolling(
|
||||
T requestObject, // Request object (any type)
|
||||
Function<T, ResponseModel> apiCallFunction, // Function to call API
|
||||
int intervalSeconds, // gap between two polls
|
||||
int maxDurationSeconds // total polling time
|
||||
) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
int maxAttempts = maxDurationSeconds / intervalSeconds;
|
||||
|
||||
for (int i = 0; i < maxAttempts; i++) {
|
||||
LOGGER.info("⏳ Polling attempt {}...", i + 1);
|
||||
|
||||
ResponseModel response = apiCallFunction.apply(requestObject);
|
||||
LOGGER.info("📥 Poll response: {}", response);
|
||||
|
||||
if ("SUCCESS".equalsIgnoreCase(response.getStatus())) {
|
||||
LOGGER.info("✅ Polling successful, stopping early.");
|
||||
break;
|
||||
}
|
||||
|
||||
Thread.sleep(intervalSeconds * 1000L);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("❌ Error in polling thread: {}", e.getMessage(), e);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public boolean isMerchantValidAndActive(MerchantRequestModel requestModel) {
|
||||
|
||||
if (requestModel == null || requestModel.getMid() == null) {
|
||||
|
||||
Reference in New Issue
Block a user