mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
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 localEchoRepository: LocalEchoRepository
|
||||
|
||||
override fun doOnError(params: Params): Result {
|
||||
override fun doOnError(params: Params, failureMessage: String): Result {
|
||||
params.localEchoIds.forEach { localEchoIds ->
|
||||
localEchoRepository.updateSendState(
|
||||
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) {
|
||||
|
@ -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.SessionWorkerParams
|
||||
import org.matrix.android.sdk.internal.worker.WorkerParamsFactory
|
||||
import org.matrix.android.sdk.internal.worker.startChain
|
||||
import timber.log.Timber
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
@ -136,6 +137,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters,
|
||||
.setConstraints(WorkManagerProvider.workConstraints)
|
||||
.setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS)
|
||||
.setInputData(data)
|
||||
.startChain(true)
|
||||
.build()
|
||||
workManagerProvider.workManager
|
||||
.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.
|
||||
injectWith(sessionComponent)
|
||||
if (params.lastFailureMessage != null) {
|
||||
// Forward error to the next workers
|
||||
doOnError(params)
|
||||
} else {
|
||||
doSafeWork(params)
|
||||
|
||||
when (val lastFailureMessage = params.lastFailureMessage) {
|
||||
null -> doSafeWork(params)
|
||||
else -> {
|
||||
// Forward error to the next workers
|
||||
doOnError(params, lastFailureMessage)
|
||||
}
|
||||
}
|
||||
} 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.
|
||||
*/
|
||||
@CallSuper
|
||||
open fun doOnError(params: PARAM): Result {
|
||||
open fun doOnError(params: PARAM, failureMessage: String): Result {
|
||||
// Forward the error
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user