Increase wait time with failures

This commit is contained in:
S1m 2021-12-07 07:58:18 +01:00
parent 3891936e85
commit 26531567e1
2 changed files with 12 additions and 8 deletions

View File

@ -21,7 +21,7 @@ class SSEListener (val context: Context) : EventSourceListener() {
override fun onOpen(eventSource: EventSource, response: Response) {
deleteWarningNotification(context)
failed = false
nFails = 0
try {
Log.d(TAG, "onOpen: " + response.code)
} catch (e: Exception) {
@ -65,14 +65,18 @@ class SSEListener (val context: Context) : EventSourceListener() {
override fun onFailure(eventSource: EventSource, t: Throwable?, response: Response?) {
Log.d(TAG, "onFailure")
isServiceStarted = false
createWarningNotification(context)
val timeStop = if (!failed) {
2000
} else {
60000
nFails += 1
if (nFails > 1)
createWarningNotification(context)
val timeStop = when (nFails) {
1 -> 2000 // 2sec
2 -> 20000 // 20sec
3 -> 60000 // 1min
4 -> 300000 // 5min
5 -> 600000 // 10min
else -> 1800000 // 30min
}.toLong()
Log.d(TAG, "Retrying in $timeStop ms")
failed = true
Looper.prepare()
object : CountDownTimer(timeStop, timeStop) {

View File

@ -25,7 +25,7 @@ import java.lang.Exception
private const val TAG = "StartService"
var isServiceStarted = false
var failed = false
var nFails = 0
fun startListener(context: Context){
Log.d(TAG, "Starting the Listener")