Skip to content

Commit

Permalink
Added some random delays to avoid cloudfront rate limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
seime committed Nov 26, 2024
1 parent d56a02a commit 6f09e7e
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Random;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -151,14 +152,14 @@ public synchronized void doPoll(boolean triggerDeviceUpdate) {
updateStatus(ThingStatus.ONLINE);
if (triggerDeviceUpdate) {

AtomicLong delayIncrementer = new AtomicLong(1000);
AtomicInteger delayIncrementer = new AtomicInteger(1000);

try {
getThing().getThings().stream()
.filter(e -> e.isEnabled()
&& (e.getStatus() == ThingStatus.ONLINE || e.getStatus() == ThingStatus.OFFLINE))
.forEach(e -> {
long delay = delayIncrementer.addAndGet(random.nextLong(3000l));
int delay = delayIncrementer.addAndGet(random.nextInt(3000));
try {
scheduler.schedule(() -> ((PanasonicComfortCloudBaseThingHandler) e.getHandler())
.loadFromServer(), delay, TimeUnit.MILLISECONDS);
Expand Down

0 comments on commit 6f09e7e

Please sign in to comment.