Skip to content
This repository has been archived by the owner on Apr 27, 2022. It is now read-only.

Commit

Permalink
.idea
Browse files Browse the repository at this point in the history
Summary:
Delete events when all retry failed

Change time between retry

Differential Revision: http://phabricator.appaloosa-store.com/D464
  • Loading branch information
AdrienOcto committed May 29, 2015
1 parent adec658 commit e14cd7b
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@

import java.util.List;

import appaloosa_store.com.appaloosa_android_tools.Appaloosa;
import appaloosa_store.com.appaloosa_android_tools.analytics.AppaloosaAnalytics;
import appaloosa_store.com.appaloosa_android_tools.analytics.services.AnalyticsServices;
import appaloosa_store.com.appaloosa_android_tools.utils.DeviceUtils;

public class BatchSentCallback implements FutureCallback<Response<JsonObject>> {

private static final Integer MAX_NB_OF_TRY = 10;
private static final Long TIME_BETWEEN_TRY = 10000l;
private static final Long REFERENCE_TIME_BETWEEN_TRY = 30000l;

private List<Integer> eventIds;
private JsonObject sentData;
Expand Down Expand Up @@ -62,18 +61,16 @@ private boolean httpStatusCodeOk(Response<JsonObject> result) {


private void retry(JsonObject data, int currentBatchSendAttemptNb) {
Log.w(Appaloosa.APPALOOSA_LOG_TAG, "retry : " + currentBatchSendAttemptNb);
if (currentBatchSendAttemptNb < MAX_NB_OF_TRY) {
try {
Thread.sleep(currentBatchSendAttemptNb * TIME_BETWEEN_TRY);
long sleepingTime = currentBatchSendAttemptNb * currentBatchSendAttemptNb * REFERENCE_TIME_BETWEEN_TRY;
Thread.sleep(sleepingTime);
if (!DeviceUtils.getActiveNetwork().equals(DeviceUtils.NO_ACTIVE_NETWORK)) {
Log.w(Appaloosa.APPALOOSA_LOG_TAG, "send time");
AnalyticsServices.send(eventIds, data, ++currentBatchSendAttemptNb);
return;
}
} catch (InterruptedException ignored) {}
}
Log.w(Appaloosa.APPALOOSA_LOG_TAG, "deleting : " + toString(eventIds));
AnalyticsServices.deleteEventsSent(eventIds);
AnalyticsServices.sending = false;
}
Expand Down

0 comments on commit e14cd7b

Please sign in to comment.