Skip to content

Commit

Permalink
persitent scheduled checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Gorzala committed Mar 29, 2024
1 parent 375ca11 commit 97515d3
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
package net.dancier.kikeriki.adapter.out.infomail;

import lombok.RequiredArgsConstructor;
import net.dancier.kikeriki.application.port.ScheduleInfomailCheckPort;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Objects;

@Component
@RequiredArgsConstructor
public class InfomailAdapter implements ScheduleInfomailCheckPort {

Logger log = LoggerFactory.getLogger(InfomailAdapter.class);
private final static Logger log = LoggerFactory.getLogger(InfomailAdapter.class);

private final ScheduledInfoMailCheckJpaRepository scheduledInfoMailCheckJpaRepository;

@Override
public void schedule(LocalDateTime when, String dancerId) {
Objects.requireNonNull(when);
Objects.requireNonNull(dancerId);
log.info("Scheduling check!!!");

ScheduledInfoMailCheckJpaEntity scheduledInfoMailCheckJpaEntity = new ScheduledInfoMailCheckJpaEntity();
scheduledInfoMailCheckJpaEntity.setStatus(ScheduledInfoMailCheckJpaEntity.STATUS.NEW);
scheduledInfoMailCheckJpaEntity.setDancerId(dancerId);
scheduledInfoMailCheckJpaEntity.setCheckAt(when);
scheduledInfoMailCheckJpaRepository.save(scheduledInfoMailCheckJpaEntity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.dancier.kikeriki.adapter.out.infomail;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.UUID;

@Data
@Entity
@Table(name = "scheduled_at")
@NoArgsConstructor
public class ScheduledInfoMailCheckJpaEntity {

@Id
@GeneratedValue
private UUID id;

@NotNull
@Enumerated(EnumType.STRING)
private STATUS status;

@NotNull
private String dancerId;

@NotNull
private LocalDateTime checkAt;

public static enum STATUS {
NEW,
TEMPORARY_FAILED,
FINALLY_FAILED,
DONE
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.dancier.kikeriki.adapter.out.infomail;

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.UUID;

public interface ScheduledInfoMailCheckJpaRepository extends JpaRepository<ScheduledInfoMailCheckJpaEntity, UUID> {
}
10 changes: 10 additions & 0 deletions src/main/resources/liquibase-changeLog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,15 @@
);
</sql>
</changeSet>
<changeSet id="2024-03-28" author="Marc Gorzala">
<sql>
CREATE TABLE scheduled_at (
id UUID PRIMARY KEY,
status VARCHAR(256) NOT NULL,
dancer_id VARCHAR(256) NOT NULL,
check_at TIMESTAMP WITHOUT TIME ZONE
);
</sql>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public void newUnreadMessage() {
assertThat(resultingState.getLastTimeOfInfoMail()).isEmpty();
assertThat(resultingState.isCandidateForSendingMail(LocalDateTime.now())).isTrue();


}

}

0 comments on commit 97515d3

Please sign in to comment.