Skip to content

Commit

Permalink
Fix incorrect class name in logger definition
Browse files Browse the repository at this point in the history
  • Loading branch information
pvannierop committed Nov 19, 2024
1 parent e50c3cc commit e7aec43
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public abstract class FitbitPollingRoute implements PollingRequestRoute {
protected static final TemporalAmount ONE_SECOND = SECONDS.getDuration();
protected static final TemporalAmount ONE_MINUTE = MINUTES.getDuration();

private static final Logger logger = LoggerFactory.getLogger(FitbitSleepRoute.class);
private static final Logger logger = LoggerFactory.getLogger(FitbitPollingRoute.class);

/** Committed offsets. */
private Map<String, Instant> offsets;
Expand Down Expand Up @@ -164,7 +164,7 @@ public void requestEmpty(RestRequest request) {
@Override
public void requestFailed(RestRequest request, Response response) {
if (response != null && response.code() == 429) {
User user = ((FitbitRestRequest)request).getUser();
User user = ((FitbitRestRequest) request).getUser();
tooManyRequestsForUser.add(user);
String cooldownString = response.header("Retry-After");
Duration cooldown = getTooManyRequestsCooldown();
Expand All @@ -179,6 +179,8 @@ public void requestFailed(RestRequest request, Response response) {
lastPollPerUser.put(user.getId(), backOff);
logger.info("Too many requests for user {}. Backing off until {}",
user, backOff.plus(getPollIntervalPerUser()));
} else if (response != null) {
logger.warn("Failed to make request {}. Response is: {}", request, response);
} else {
logger.warn("Failed to make request {}", request);
}
Expand All @@ -197,8 +199,11 @@ public Stream<FitbitRestRequest> requests() {
lastPoll = Instant.now();
try {
return userRepository.stream()
// Collect Instant of nextPoll for each user
.map(u -> new AbstractMap.SimpleImmutableEntry<>(u, nextPoll(u)))
// Keep users where the lastPoll is later than the nextPoll for the user (i.e., user needs to be polled)
.filter(u -> lastPoll.isAfter(u.getValue()))
// Sort users by nextPoll (old to new?)
.sorted(Map.Entry.comparingByValue())
.flatMap(u -> this.createRequests(u.getKey()))
.filter(Objects::nonNull);
Expand Down

0 comments on commit e7aec43

Please sign in to comment.