From 758d8319623863432f686adb65726c6c1e3ae598 Mon Sep 17 00:00:00 2001 From: sim Date: Fri, 10 Jun 2022 09:32:16 +0200 Subject: [PATCH] Fix Restart worker when ping is missing --- .../distributor/nextpush/services/RestartWorker.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/services/RestartWorker.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/services/RestartWorker.kt index 5bf20f8..9ed8792 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/services/RestartWorker.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/services/RestartWorker.kt @@ -15,7 +15,7 @@ class RestartWorker (ctx: Context, params: WorkerParameters) : Worker(ctx, param companion object { private const val TAG = "RestartWorker" fun start(context: Context, delay: Long? = null) { - val work = PeriodicWorkRequestBuilder(20, TimeUnit.MINUTES) + val work = PeriodicWorkRequestBuilder(16, TimeUnit.MINUTES) if (delay != null) { lastEventDate = null work.setInitialDelay(delay, TimeUnit.SECONDS) @@ -36,9 +36,13 @@ class RestartWorker (ctx: Context, params: WorkerParameters) : Worker(ctx, param lastEventDate?.let { restartDate.time = it.time restartDate.add(Calendar.SECOND, keepalive) - } - Log.d(TAG, "restartDate: ${restartDate.time}") - if (lastEventDate == null || currentDate.after(restartDate)) { + Log.d(TAG, "restartDate: ${restartDate.time}") + if (currentDate.after(restartDate)) { + Log.d(TAG, "Restarting") + StartService.nFails = 5 // Max, will keep using the current worker + StartService.startListener(applicationContext) + } + }?:run { Log.d(TAG, "Restarting") StartService.startListener(applicationContext) }