Skip to content

Commit

Permalink
Move empty check into sendEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
steffenmllr committed Oct 30, 2024
1 parent 8508ba6 commit 79ce4ab
Showing 1 changed file with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,7 @@ public AgmaAnalyticsReporter(AgmaAnalyticsProperties agmaAnalyticsProperties,

@Override
public void initialize(Promise<Void> initializePromise) {
vertx.setPeriodic(bufferTimeoutMs, ignored -> {
final List<String> toFlush = buffer.pollAll();
if (!toFlush.isEmpty()) {
sendEvents(toFlush);
}
});
vertx.setPeriodic(bufferTimeoutMs, ignored -> sendEvents(buffer.pollAll()));
initializePromise.complete();
}

Expand Down Expand Up @@ -152,11 +147,7 @@ public <T> Future<Void> processEvent(T event) {

final String eventString = jacksonMapper.encodeToString(agmaEvent);
buffer.put(eventString, eventString.length());
final List<String> toFlush = buffer.pollToFlush();
if (!toFlush.isEmpty()) {
sendEvents(toFlush);
}

sendEvents(buffer.pollToFlush());
return Future.succeededFuture();
}

Expand Down Expand Up @@ -212,6 +203,9 @@ private static String getPublisherId(BidRequest bidRequest) {
}

private void sendEvents(List<String> events) {
if (events.isEmpty()) {
return;
}
final String payload = preparePayload(events);
final Future<HttpClientResponse> responseFuture = compressToGzip
? httpClient.request(HttpMethod.POST, url, headers, gzip(payload), httpTimeoutMs)
Expand Down

0 comments on commit 79ce4ab

Please sign in to comment.