Skip to content

Commit

Permalink
Some fixes and changed delay time
Browse files Browse the repository at this point in the history
  • Loading branch information
CriMDev97 committed Dec 13, 2023
1 parent 440df0a commit 9b41fe4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
@Setter
public class AppConfig {

private String delayDays;
private String delayHours;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import it.pagopa.interop.signalhub.history.cleanup.controller.SignalServiceController;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
Expand All @@ -11,7 +10,7 @@
@Component
@AllArgsConstructor
public class BatchTaskExecutor implements CommandLineRunner {
private SignalServiceController signalServiceController;
private final SignalServiceController signalServiceController;

@Override
public void run(String... args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,23 @@
import it.pagopa.interop.signalhub.history.cleanup.service.SignalService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.Instant;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

@Slf4j
@AllArgsConstructor
@Service
public class SignalServiceImpl implements SignalService {

@Autowired
private SignalRepository signalRepository;

@Autowired
private AppConfig appConfig;
private final SignalRepository signalRepository;
private final AppConfig appConfig;

public void cleanSignal() {
Instant pastDate = Instant.now().minus(Long.parseLong(appConfig.getDelayDays()), ChronoUnit.DAYS);
Instant pastDate = Instant.now().minus(Long.parseLong(appConfig.getDelayHours()), ChronoUnit.HOURS);
signalRepository.deleteByDate(pastDate)
.doOnSuccess(x -> log.info("clean complete with success"))
.doOnError(ex -> log.error("Error on signal cleanup {}",ex))
.doOnError(ex -> log.error("Error on signal cleanup", ex))
.subscribe();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ spring.r2dbc.pool.initial-size=5
spring.r2dbc.pool.enabled=true
spring.data.r2dbc.repositories.enabled=true

pdnd.history-cleanup.delay-days=30
pdnd.history-cleanup.delay-hours=30
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

@ExtendWith(MockitoExtension.class)
public class AppConfigTest {
class AppConfigTest {

@InjectMocks
AppConfig appConfig;

@Test
void testDelayDays() {
appConfig.setDelayDays("10");
assertEquals("10", appConfig.getDelayDays());
appConfig.setDelayHours("10");
assertEquals("10", appConfig.getDelayHours());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import it.pagopa.interop.signalhub.history.cleanup.config.AppConfig;
import it.pagopa.interop.signalhub.history.cleanup.repository.SignalRepository;
import it.pagopa.interop.signalhub.history.cleanup.service.impl.SignalServiceImpl;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand All @@ -24,7 +23,7 @@ class SignalServiceImplTest {

@Test
void testDeleteSignal() {
Mockito.when(appConfig.getDelayDays()).thenReturn("30");
Mockito.when(appConfig.getDelayHours()).thenReturn("30");
Mockito.when(signalRepository.deleteByDate(Mockito.any())).thenReturn(Mono.empty());
signalService.cleanSignal();
Mockito.verify(signalRepository, Mockito.times(1)).deleteByDate(Mockito.any());
Expand Down

0 comments on commit 9b41fe4

Please sign in to comment.