matomo-sdk-android icon indicating copy to clipboard operation
matomo-sdk-android copied to clipboard

sdk - android - max Retry option

Open arul-prasad opened this issue 6 years ago • 5 comments

In the DefaultDispatcher, we are doing a re-try when the track call goes unsuccess and the events cache has elements. Possible to have MAX_RETRY option? by this way, we can control the app running in thread without re-trying always till app is closed or kill.

For example i expect when piwik (matomo) server was down, I expect app can re-try only 5 times.

https://github.com/matomo-org/matomo-sdk-android/blob/master/tracker/src/main/java/org/matomo/sdk/dispatcher/DefaultDispatcher.java

arul-prasad avatar Jan 02 '19 12:01 arul-prasad

What would happen after exceeding the MAX_RETRY value?

How would you differentiate server down from connectivity issues, where the user is, e.g. in a subway?

d4rken avatar Jan 02 '19 15:01 d4rken

My intention is to stop the thread keep on running when there is server down or connectivity issue, probably can we write the events cache in disk and try when app re-open to push the offline track?

arul-prasad avatar Jan 03 '19 08:01 arul-prasad

Did you notice this having a negative impact? The current code would have it retry every 5 minutes, a thread consumes virtually no resources while sleeping. If the app is in the background during that time the system will kill it anyways.

d4rken avatar Jan 03 '19 14:01 d4rken

agreed when we have retry every 5 minutes our impact is low and when the app is in background this will be killed. What happens when we have dispatchInterval 0 ?

mPiwikTracker = Piwik.getInstance(getReactApplicationContext()).newTracker(TrackerConfig.createDefault(url, id)); mPiwikTracker.setDispatchInterval(0);

in this case we will have sleepTime as 0. while (mRunning) { try { long sleepTime = mDispatchInterval; if (mRetryCounter > 1) sleepTime += Math.min(mRetryCounter * mDispatchInterval, 5 * mDispatchInterval); // Either we wait the interval or forceDispatch() granted us one free pass mSleepToken.tryAcquire(sleepTime, TimeUnit.MILLISECONDS); } catch (InterruptedException e) {Timber.tag(LOGGER_TAG).e(e); }

Note: I am trying to avoid queuing in the client app, and I am trying to dispatch the track immediately to the piwik server, so dispatchInterval is 0.

arul-prasad avatar Jan 04 '19 06:01 arul-prasad

I thought of adding below check in DefaultDispatcher, let me know your comments. especially when dispatchInterval is zero. (no wait)

    if (mRetryCounter > 1) {
        if (mDispatchInterval > 0) {
            sleepTime += Math.min(mRetryCounter * mDispatchInterval, 5 * mDispatchInterval);
        } else {
            sleepTime += Math.min(mRetryCounter * DEFAULT_DISPATCH_INTERVAL, 5 * DEFAULT_DISPATCH_INTERVAL);
        }
    }

arul-prasad avatar Jan 07 '19 10:01 arul-prasad