Skip to content

Commit

Permalink
Added Healthchecks for Loki and RivenBot services (#106)
Browse files Browse the repository at this point in the history
* Forgot to get rid of the dependency Loki had on the bot

* Added healthchecks for Loki and Rivenbot before startup
  • Loading branch information
Daniel Villavicencio authored Jun 25, 2024
1 parent d4bcdfc commit 027e238
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
14 changes: 11 additions & 3 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ services:
ports:
- "8080:8080"
depends_on:
- redis
- mongodb
- loki
loki:
condition: service_healthy
redis:
condition: service_started
mongodb:
condition: service_started
secrets:
- mongo_username
- mongo_password
Expand Down Expand Up @@ -46,6 +49,11 @@ services:
image: grafana/loki:2.9.0
ports:
- "3100:3100"
healthcheck:
test: ["CMD-SHELL", "wget --spider --quiet http://localhost:3100/ready || exit 1"]
interval: 30s
timeout: 10s
retries: 3
grafana:
container_name: grafana
environment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.deahtstroke.rivenbot.entity.RaidStatistics;
import com.deahtstroke.rivenbot.entity.UserDetails;
import com.deahtstroke.rivenbot.enums.RaidDifficulty;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneId;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
Expand Down Expand Up @@ -122,16 +124,14 @@ private static Aggregation raidStatisticsAggregationPipeline(String userId) {
*/
public Flux<RaidStatistics> calculateRaidStats(String uniqueUsername, String membershipId,
Integer membershipType) {
Instant now = Instant.now(); // Timestamp for this action
Mono<UserDetails> createAction = createUser(
now, uniqueUsername, membershipType, membershipId);
Mono<UserDetails> updateAction = updateUser(
now, uniqueUsername, membershipType, membershipId);
Instant now = Instant.now(Clock.system(ZoneId.of("PST")));
Mono<UserDetails> createAction = createUser(now, uniqueUsername, membershipType, membershipId);
Mono<UserDetails> updateAction = updateUser(now, uniqueUsername, membershipType, membershipId);

Aggregation aggregation = raidStatisticsAggregationPipeline(uniqueUsername);

return userRaidDetailsService.existsById(uniqueUsername)
.flatMap(exists -> exists ? updateAction : createAction)
.flatMap(exists -> Boolean.TRUE.equals(exists) ? updateAction : createAction)
.flatMapMany(userDetails -> reactiveMongoTemplate.aggregate(aggregation,
UserDetails.class, RaidStatistics.class));
}
Expand Down

0 comments on commit 027e238

Please sign in to comment.