Skip to content

Commit

Permalink
Merge pull request #36 from Staketab/dev
Browse files Browse the repository at this point in the history
add job for removing reserved domains from cart in 10 min
  • Loading branch information
MrFoxogen authored Mar 28, 2024
2 parents 68432ea + 709b775 commit 8dd062a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public enum LogInfoStatus {
FAILED("Failed tx"),
INCORRECT_AMOUNT("Incorrect amount"),
APPLIED("Applied tx"),
REMOVE_RESERVATION("Remove reservation");
REMOVE_RESERVATION("Remove reservation"),
REMOVE_CART_RESERVATION("Remove cart reservation");

private final String message;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public interface DomainRepository extends JpaRepository<DomainEntity, String> {
SELECT *
FROM domains
where reservation_timestamp < :reservationTimestamp
and status != 'ACTIVE'
and status = :status
""")
List<DomainEntity> findAllByReservationTimestampLessThan(Long reservationTimestamp);
List<DomainEntity> findAllByReservationTimestampLessThan(Long reservationTimestamp, String status);

@Modifying
@Query(nativeQuery = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ public class DomainScheduler {

private final DomainService domainService;

@Scheduled(fixedDelayString = "${scheduled.domain.upload-mills}")
@Scheduled(fixedDelayString = "${scheduled.domain.remove-reserve-upload-mills}")
public void removeReservedDomains() {
domainService.removeReservedDomains();
}

@Scheduled(fixedDelayString = "${scheduled.domain.remove-cart-reserve-upload-mills}")
public void removeCartReservedDomains() {
domainService.removeCartReservedDomains();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ public interface DomainService {
Boolean setDefaultDomain(String id);

void removeReservedDomains();

void removeCartReservedDomains();
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import static com.staketab.minanames.entity.LogInfoStatus.CART_RESERVE;
import static com.staketab.minanames.entity.LogInfoStatus.CREATE;
import static com.staketab.minanames.entity.LogInfoStatus.DELETE_CART_RESERVE;
import static com.staketab.minanames.entity.LogInfoStatus.REMOVE_CART_RESERVATION;
import static com.staketab.minanames.entity.LogInfoStatus.REMOVE_RESERVATION;
import static com.staketab.minanames.utils.Constants.DEFAULT_DENOMINATION;
import static com.staketab.minanames.utils.Constants.MINA_DENOMINATION;
Expand Down Expand Up @@ -147,7 +148,7 @@ public Boolean setDefaultDomain(String id) {
public void removeReservedDomains() {
LocalDateTime localDateTime = LocalDateTime.now().minusDays(1);
long currentTimestamp = Timestamp.valueOf(localDateTime).getTime();
List<DomainEntity> domainEntities = domainRepository.findAllByReservationTimestampLessThan(currentTimestamp);
List<DomainEntity> domainEntities = domainRepository.findAllByReservationTimestampLessThan(currentTimestamp, PENDING.name());
List<LogInfoEntity> logInfoEntities = domainEntities
.stream()
.map(domainEntity -> buildLogInfoEntity(domainEntity, REMOVE_RESERVATION))
Expand All @@ -156,6 +157,19 @@ public void removeReservedDomains() {
domainRepository.deleteAll(domainEntities);
}

@Override
public void removeCartReservedDomains() {
LocalDateTime localDateTime = LocalDateTime.now().minusMinutes(10);
long currentTimestamp = Timestamp.valueOf(localDateTime).getTime();
List<DomainEntity> domainEntities = domainRepository.findAllByReservationTimestampLessThan(currentTimestamp, RESERVED.name());
List<LogInfoEntity> logInfoEntities = domainEntities
.stream()
.map(domainEntity -> buildLogInfoEntity(domainEntity, REMOVE_CART_RESERVATION))
.toList();
logInfoService.saveAllLogInfos(logInfoEntities);
domainRepository.deleteAll(domainEntities);
}

private void saveUpdatedDomains(List<DomainEntity> domains, Map<String, CartReservedDomainDTO> cartDomainMap, PayableTransactionEntity payableTransaction) {
List<DomainEntity> domainEntities = domains
.stream()
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/staketab/minanames/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
@UtilityClass
public class Constants {
//common
public static final String MINA_ID = "mina";
public static final String API_KEY_HEADER = "x-api-key";

public static final Long MINA_DENOMINATION = 1_000_000_000L;
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ scheduled:
upload-mills: 30000 # runs 30 seconds after the previous job
domain:
enabled: true
upload-mills: 60000 # runs 60 seconds after the previous job
remove-reserve-upload-mills: 60000 # runs 60 seconds after the previous job
remove-cart-reserve-upload-mills: 60000 # runs 60 seconds after the previous job

0 comments on commit 8dd062a

Please sign in to comment.