my current android application employs androidx.work.CoroutineWorker
(s) to execute long running download tasks.
api 'androidx.work:work-runtime:2.7.1'
api 'androidx.work:work-runtime-ktx:2.7.1'
the download worker is part of a chain of workers that each complete part of the download prerequisites.
I have used ExistingWorkPolicy.APPEND_OR_REPLACE
to enable my users to queue download requests. This approach works fine while each download does not fail.
ExistingWorkPolicy.APPEND_OR_REPLACE
is described as follows:-
If there is existing pending (uncompleted) work with the same unique name, append
the newly-specified work as the child of all the leaves of that work sequence.
Otherwise, insert the newly-specified work as the start of a new sequence.
Note: If there are failed or cancelled prerequisites, these prerequisites are
dropped and the newly-specified work is the start of a new sequence.
I interpreted this to mean that if I queue multiple instances of my work chain, if the first was to fail the second would still start ok.
This is not the behaviour I am seeing though. Using Android Studio App Inspection
-> Background Task Inspector
I see my second chain of workers are all blocked while the first chain is executing, then, when the first chain has a worker that fails the complete second chain is also marked as failed.
how can I achieve the required behaviour?
NOTE: I have read this question which is partly the same as mine WorkManager existing work policy APPEND_OR_REPLACE doesn't behave as expected however I want to know how to achieve the desired "expected" behaviour as well as understand the actual behaviour seen.