mirror of
https://codeberg.org/NextPush/nextpush-android.git
synced 2024-12-28 02:30:16 +01:00
Fix Restart worker when ping is missing
This commit is contained in:
parent
43fca82597
commit
758d831962
@ -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<RestartWorker>(20, TimeUnit.MINUTES)
|
||||
val work = PeriodicWorkRequestBuilder<RestartWorker>(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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user