mirror of
https://codeberg.org/NextPush/nextpush-android.git
synced 2025-01-16 20:02:33 +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 {
|
companion object {
|
||||||
private const val TAG = "RestartWorker"
|
private const val TAG = "RestartWorker"
|
||||||
fun start(context: Context, delay: Long? = null) {
|
fun start(context: Context, delay: Long? = null) {
|
||||||
val work = PeriodicWorkRequestBuilder<RestartWorker>(20, TimeUnit.MINUTES)
|
val work = PeriodicWorkRequestBuilder<RestartWorker>(16, TimeUnit.MINUTES)
|
||||||
if (delay != null) {
|
if (delay != null) {
|
||||||
lastEventDate = null
|
lastEventDate = null
|
||||||
work.setInitialDelay(delay, TimeUnit.SECONDS)
|
work.setInitialDelay(delay, TimeUnit.SECONDS)
|
||||||
@ -36,9 +36,13 @@ class RestartWorker (ctx: Context, params: WorkerParameters) : Worker(ctx, param
|
|||||||
lastEventDate?.let {
|
lastEventDate?.let {
|
||||||
restartDate.time = it.time
|
restartDate.time = it.time
|
||||||
restartDate.add(Calendar.SECOND, keepalive)
|
restartDate.add(Calendar.SECOND, keepalive)
|
||||||
}
|
Log.d(TAG, "restartDate: ${restartDate.time}")
|
||||||
Log.d(TAG, "restartDate: ${restartDate.time}")
|
if (currentDate.after(restartDate)) {
|
||||||
if (lastEventDate == null || 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")
|
Log.d(TAG, "Restarting")
|
||||||
StartService.startListener(applicationContext)
|
StartService.startListener(applicationContext)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user