prevent the flags log from spamming

This commit is contained in:
Braydon 2024-09-18 20:39:41 -04:00
parent b458e24f29
commit 993dfafed9
2 changed files with 22 additions and 1 deletions

@ -2,6 +2,8 @@ package cc.pulseapp.api.model;
import lombok.*;
import java.util.Objects;
/**
* A feature flag.
*
@ -30,6 +32,8 @@ public enum Feature {
*/
@Setter private Object value;
/**
* Get a feature by its id.
*
@ -44,4 +48,18 @@ public enum Feature {
}
return null;
}
/**
* Get the combined hash
* code of all features.
*
* @return the combined hash code
*/
public static int hash() {
int hash = 0;
for (Feature feature : VALUES) {
hash+= Objects.hash(feature.isEnabled(), feature.getValue());
}
return hash;
}
}

@ -45,6 +45,7 @@ public final class FlagsService {
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override @SneakyThrows
public void run() {
int oldFlags = Feature.hash();
for (BaseFlag flag : client.getEnvironmentFlags().getAllFlags()) {
Feature feature = Feature.getById(flag.getFeatureName());
if (feature == null) {
@ -54,7 +55,9 @@ public final class FlagsService {
feature.setEnabled(flag.getEnabled());
feature.setValue(value instanceof String stringedValue && (stringedValue.isBlank()) ? null : value);
}
log.info("Fetched new flags (:");
if (oldFlags != Feature.hash()) {
log.info("Fetched new flags (:");
}
}
}, 0L, FETCH_INTERVAL);
}