Merge pull request #6837 from vector-im/feature/adm/missing-notifications
Missing notifications due to stuck background workers
This commit is contained in:
commit
841ee33c82
1
changelog.d/6836.bugfix
Normal file
1
changelog.d/6836.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fixes uncaught exceptions in the SyncWorker to cause the worker to become stuck in the failure state
|
@ -53,7 +53,7 @@ internal class MultipleEventSendingDispatcherWorker(context: Context, params: Wo
|
|||||||
@Inject lateinit var timelineSendEventWorkCommon: TimelineSendEventWorkCommon
|
@Inject lateinit var timelineSendEventWorkCommon: TimelineSendEventWorkCommon
|
||||||
@Inject lateinit var localEchoRepository: LocalEchoRepository
|
@Inject lateinit var localEchoRepository: LocalEchoRepository
|
||||||
|
|
||||||
override fun doOnError(params: Params): Result {
|
override fun doOnError(params: Params, failureMessage: String): Result {
|
||||||
params.localEchoIds.forEach { localEchoIds ->
|
params.localEchoIds.forEach { localEchoIds ->
|
||||||
localEchoRepository.updateSendState(
|
localEchoRepository.updateSendState(
|
||||||
eventId = localEchoIds.eventId,
|
eventId = localEchoIds.eventId,
|
||||||
@ -63,7 +63,7 @@ internal class MultipleEventSendingDispatcherWorker(context: Context, params: Wo
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.doOnError(params)
|
return super.doOnError(params, failureMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun injectWith(injector: SessionComponent) {
|
override fun injectWith(injector: SessionComponent) {
|
||||||
|
@ -30,6 +30,7 @@ import org.matrix.android.sdk.internal.session.sync.SyncTask
|
|||||||
import org.matrix.android.sdk.internal.worker.SessionSafeCoroutineWorker
|
import org.matrix.android.sdk.internal.worker.SessionSafeCoroutineWorker
|
||||||
import org.matrix.android.sdk.internal.worker.SessionWorkerParams
|
import org.matrix.android.sdk.internal.worker.SessionWorkerParams
|
||||||
import org.matrix.android.sdk.internal.worker.WorkerParamsFactory
|
import org.matrix.android.sdk.internal.worker.WorkerParamsFactory
|
||||||
|
import org.matrix.android.sdk.internal.worker.startChain
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -136,6 +137,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters,
|
|||||||
.setConstraints(WorkManagerProvider.workConstraints)
|
.setConstraints(WorkManagerProvider.workConstraints)
|
||||||
.setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS)
|
.setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS)
|
||||||
.setInputData(data)
|
.setInputData(data)
|
||||||
|
.startChain(true)
|
||||||
.build()
|
.build()
|
||||||
workManagerProvider.workManager
|
workManagerProvider.workManager
|
||||||
.enqueueUniqueWork(BG_SYNC_WORK_NAME, ExistingWorkPolicy.APPEND_OR_REPLACE, workRequest)
|
.enqueueUniqueWork(BG_SYNC_WORK_NAME, ExistingWorkPolicy.APPEND_OR_REPLACE, workRequest)
|
||||||
|
@ -55,14 +55,16 @@ internal abstract class SessionSafeCoroutineWorker<PARAM : SessionWorkerParams>(
|
|||||||
|
|
||||||
// Make sure to inject before handling error as you may need some dependencies to process them.
|
// Make sure to inject before handling error as you may need some dependencies to process them.
|
||||||
injectWith(sessionComponent)
|
injectWith(sessionComponent)
|
||||||
if (params.lastFailureMessage != null) {
|
|
||||||
// Forward error to the next workers
|
when (val lastFailureMessage = params.lastFailureMessage) {
|
||||||
doOnError(params)
|
null -> doSafeWork(params)
|
||||||
} else {
|
else -> {
|
||||||
doSafeWork(params)
|
// Forward error to the next workers
|
||||||
|
doOnError(params, lastFailureMessage)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (throwable: Throwable) {
|
} catch (throwable: Throwable) {
|
||||||
buildErrorResult(params, throwable.localizedMessage ?: "error")
|
buildErrorResult(params, "${throwable::class.java.name}: ${throwable.localizedMessage ?: "N/A error message"}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,10 +91,10 @@ internal abstract class SessionSafeCoroutineWorker<PARAM : SessionWorkerParams>(
|
|||||||
* This is called when the input parameters are correct, but contain an error from the previous worker.
|
* This is called when the input parameters are correct, but contain an error from the previous worker.
|
||||||
*/
|
*/
|
||||||
@CallSuper
|
@CallSuper
|
||||||
open fun doOnError(params: PARAM): Result {
|
open fun doOnError(params: PARAM, failureMessage: String): Result {
|
||||||
// Forward the error
|
// Forward the error
|
||||||
return Result.success(inputData)
|
return Result.success(inputData)
|
||||||
.also { Timber.e("Work cancelled due to input error from parent") }
|
.also { Timber.e("Work cancelled due to input error from parent: $failureMessage") }
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
Loading…
Reference in New Issue
Block a user