Skip to content

Commit

Permalink
Merge pull request #24 from Staketab/dev
Browse files Browse the repository at this point in the history
add domain scheduler for remove old reserved domains
  • Loading branch information
MrFoxogen committed Mar 15, 2024
2 parents 6ca61d2 + d23dab1 commit f995797
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.Optional;
Expand Down Expand Up @@ -45,4 +46,8 @@ public interface DomainRepository extends JpaRepository<DomainEntity, String> {
WHERE owner_address = (select owner_address from domains where id = :id)
""")
int setDefaultDomain(String id);

@Modifying
@Transactional
void deleteAllByReservationTimestampLessThan(Long reservationTimestamp);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.staketab.minanames.scheduler;

import com.staketab.minanames.service.abstraction.DomainService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
@ConditionalOnProperty(value = "scheduled.domain.enabled", havingValue = "true")
public class DomainScheduler {

private final DomainService domainService;

@Scheduled(fixedDelayString = "${scheduled.domain.upload-mills}")
public void removeReservedDomains() {
domainService.removeReservedDomains();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public interface DomainService {
DomainEntity update(DomainUpdateDTO domainUpdateDTO);
Boolean isNameReserved(String name);
Boolean setDefaultDomain(String id);
void removeReservedDomains();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Optional;

@Service
Expand Down Expand Up @@ -71,4 +73,11 @@ public Boolean isNameReserved(String name) {
public Boolean setDefaultDomain(String id) {
return domainRepository.setDefaultDomain(id) > 0;
}

@Override
public void removeReservedDomains() {
LocalDateTime localDateTime = LocalDateTime.now().minusDays(1);
long currentTimestamp = Timestamp.valueOf(localDateTime).getTime();
domainRepository.deleteAllByReservationTimestampLessThan(currentTimestamp);
}
}
8 changes: 5 additions & 3 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ logging:

scheduled:
enabled: false
tx-resync:
checker-tx-reserve:
enabled: false
initial-delay: 660000
upload-mills: 660000
upload-mills: 30000 # runs 30 seconds after the previous job
domain:
enabled: false
upload-mills: 60000 # runs 60 seconds after the previous job

0 comments on commit f995797

Please sign in to comment.