Reputation: 992
We are using 2.1.0 version of WorkManager.
implementation "androidx.work:work-runtime:2.1.0"
When we run a service which takes care of importing data from web and inserting to local sqlite, it takes around 15 mins. but after 10 mins we are getting below error from the system.
2 2567-2567/? I/JobServiceContext: Client timed out while executing (no jobFinished received). sending onStop. com.xxxx/androidx.work.impl.background.systemjob.SystemJobService jId=353, u0
08-05 16:58:10.467 29795-29858/com.xxxx I/WM-WorkerWrapper: Work [ id=5e29ca91-fa5a-4d08-838f-01db64522f4a, tags={ com.xxx.xxxSync, RWORK_XXX_SYNC } ] was cancelled
java.util.concurrent.CancellationException: Task was cancelled.
at androidx.work.impl.utils.futures.AbstractFuture.cancellationExceptionWithCause(AbstractFuture.java:1184)
at androidx.work.impl.utils.futures.AbstractFuture.getDoneValue(AbstractFuture.java:514)
at androidx.work.impl.utils.futures.AbstractFuture.get(AbstractFuture.java:475)
at androidx.work.impl.WorkerWrapper$2.run(WorkerWrapper.java:284)
at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:75)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
But what happens really is the background service still continues to download and insert in to the DB.
Is there any way to increase the time out manually?
Upvotes: 0
Views: 2137
Reputation: 21104
JobScheduler
requires that you complete execution in 10
minutes. You can split up your WorkRequest
s and chain then using a WorkContinuation
. Look at the variants of WorkManager.beginWith
APIs for more information.
For e.g.
Upvotes: 0
Reputation: 3562
Is there any way to increase the time out manually?
There is no way to change timeout time, for long running tasks it is better to divide the work and chain it.
You can divide the entries into chunks and even have them execute in parallel, this might even increase performance.
However, For an operation that runs for 15 minutes, it is not a good idea to put it in background. It will consume a lot of network resources and battery power as well. Your user may want to cancel/pause the operation or see progress at anytime.
A Foreground Service is better since it will keep running as long as the notification is visible and you user can see the progress of the task and can interact with it.
Upvotes: 1