Skip to content

Commit

Permalink
Merge pull request #130 from KvalitetsIT/status
Browse files Browse the repository at this point in the history
Correct issue where mails could be send multiple times even thuogh status not updated.
  • Loading branch information
JonasPed committed Jul 7, 2023
2 parents 56b29bb + f0a1dad commit 9a4980b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ public AdapterController(StatusUpdateService statusUpdateService) {
public ResponseEntity<Void> v1StatusPost(StatusUpdate statusUpdate) {
logger.debug("Updating or creating status");

statusUpdateService.updateStatus(new UpdateServiceModel(statusUpdate.getService(), statusUpdate.getServiceName(), Status.valueOf(Status.class, statusUpdate.getStatus().toString()), statusUpdate.getStatusTime(), statusUpdate.getMessage()));
var upd = new UpdateServiceModel(
statusUpdate.getService(),
statusUpdate.getServiceName(),
Status.valueOf(Status.class, statusUpdate.getStatus().toString()),
statusUpdate.getStatusTime(),
statusUpdate.getMessage());

statusUpdateService.updateStatus(upd);

return ResponseEntity.status(HttpStatus.CREATED).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ public List<ServiceStatusEntity> findAll() {

@Override
public Optional<ServiceStatusEntity> findLatest(String service) {
var sql = "select s.* from service_status s, service_configuration sc where s.service_configuration_id = sc.id order by status_time desc limit 1";
var sql = "select s.* " +
" from service_status s, " +
" service_configuration sc " +
" where s.service_configuration_id = sc.id " +
" and sc.service = :service" +
" order by status_time desc" +
" limit 1";

try {
return Optional.ofNullable(template.queryForObject(sql, Collections.singletonMap("service", service), DataClassRowMapper.newInstance(ServiceStatusEntity.class)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,23 @@ public void testInsert() {

@Test
public void testGetLatest() {
var statusConfiguration = testDataHelper.createServiceConfiguration("service", "name", false, defaultGroupId, "OK", "description");

var now = OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS);

testDataHelper.createServiceStatus(statusConfiguration, "OK", now);
testDataHelper.createServiceStatus(statusConfiguration, "NOT_OK", now.minus(1, ChronoUnit.MICROS));
var statusConfiguration = testDataHelper.createServiceConfiguration("service", "name", false, defaultGroupId, "OK", "description");
testDataHelper.createServiceStatus(statusConfiguration, "OK", now.minus(1, ChronoUnit.MICROS));
testDataHelper.createServiceStatus(statusConfiguration, "NOT_OK", now.minus(2, ChronoUnit.MICROS));

var anotherStatusConfiguration = testDataHelper.createServiceConfiguration("another-service", "another-name", false, defaultGroupId, "OK", "description");
testDataHelper.createServiceStatus(anotherStatusConfiguration, "OK", now);
testDataHelper.createServiceStatus(anotherStatusConfiguration, "NOT_OK", now.minus(1, ChronoUnit.MICROS));

var latest = serviceStatusDao.findLatest("service");
assertNotNull(latest);
assertTrue(latest.isPresent());

assertEquals(statusConfiguration, latest.get().serviceConfigurationId().longValue());
assertEquals("OK", latest.get().status());
assertEquals(now, latest.get().statusTime());
assertEquals(now.minus(1, ChronoUnit.MICROS), latest.get().statusTime());
assertNull(latest.get().message());
}

Expand Down

0 comments on commit 9a4980b

Please sign in to comment.