Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling inside the worker #1

Open
VillePakarinen opened this issue Aug 13, 2019 · 1 comment
Open

Error handling inside the worker #1

VillePakarinen opened this issue Aug 13, 2019 · 1 comment

Comments

@VillePakarinen
Copy link

VillePakarinen commented Aug 13, 2019

Hello,

I tested out the library I noticed one issue which might need some explaining

By the spec of WorkInfo.State:
WorkInfo.State - FAILED Used to indicate that the WorkRequest has completed in a failure state.

I'm not getting this State Failed out of the worker by listening to it with

WorkManager.getInstance().getWorkInfoByIdObservable(workRequest.id)

Dummy worker class below

class UpdateWorker(appContext: Context, params: WorkerParameters) : RxWorker(appContext, params) {
. . . 
override fun createWork(): Single<Result> {
        val inputValue = inputData.getString(KEY_ID) ?: ""
        return locaRepository.getById(inputValue)
            .flatMap { object ->
                remoteRepository.update(object)
            }
            .doOnError { error ->
                Timber.e(error)
            }
            .toSingleDefault(Result.success())
            .onErrorReturnItem(Result.failure())
    }
}

When the API request fails onErrorReturnItem(Result.failure()) is getting called. However

WorkManager.getInstance().getWorkInfoByIdObservable(workRequest.id)

Function throws an error in the stream. Now what I would expect to happen is to receive Observable where WorkInfo.State == Failed.

Is this expected behaviour or could you add ignore error flag here as well ?

@dominik-korsa
Copy link

I agree, it should also apply to getWorkDataByIdSingle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants