From bbadea2ffe498b2adfb71e317a3b6440091cfc0f Mon Sep 17 00:00:00 2001 From: S1m Date: Wed, 1 Dec 2021 01:05:05 +0100 Subject: [PATCH] Retry every 10min on failure --- .../nextpush/services/SSEListener.kt | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/services/SSEListener.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/services/SSEListener.kt index 7da1fd7..9c58b99 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/services/SSEListener.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/services/SSEListener.kt @@ -66,22 +66,25 @@ class SSEListener (val context: Context) : EventSourceListener() { Log.d(TAG, "onFailure") isServiceStarted = false createWarningNotification(context) - if (!failed) { - failed = true - Looper.prepare() - object : CountDownTimer(2000, 1000) { + val timeStop = if (!failed) { + 2000 + } else { + 60000 + }.toLong() + Log.d(TAG, "Retrying in $timeStop ms") + failed = true + Looper.prepare() + object : CountDownTimer(timeStop, timeStop) { - override fun onTick(millisUntilFinished: Long) { - Log.d(TAG, "Restarting in $millisUntilFinished ms") - } + override fun onTick(millisUntilFinished: Long) {} - override fun onFinish() { - Log.d(TAG, "Trying to restart") - startListener(context) - } - }.start() - Looper.loop() - } + override fun onFinish() { + Log.d(TAG, "Trying to restart") + startListener(context) + } + + }.start() + Looper.loop() t?.let { Log.d(TAG, "An error occurred: $t") return