Worker called multiply times and very often
See original GitHub issueI Use version 1.0.0-alpha10 of worker lib.
I create simple worker implementation -
class CacheWorker(context: Context, workerParameters: WorkerParameters) : Worker(context, workerParameters) {
override fun doWork(): Result {
Log.d(CacheWorker::class.java.simpleName, "doWork() called")
val cacheUseCase = UseCaseCacheAssembly.provide(applicationContext)
try {
cacheUseCase.sendCachedRequests()
} catch (e: Exception) {
}
return Result.SUCCESS
}
}
it should periodically start if there is Internet connection and try to send cached data from app. If there is any error - no problem, we just wait when worker starts again and try to send.
Here is code of starting worker:
fun startCashWorker() {
val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
val cashWorkRequest =
PeriodicWorkRequest.Builder(CacheWorker::class.java, 15, TimeUnit.MINUTES)
.setConstraints(constraints)
.build()
WorkManager.getInstance().enqueueUniquePeriodicWork(
"caching",
ExistingPeriodicWorkPolicy.REPLACE,
cashWorkRequest
)
}
This function called once on start of app.
But when internet is on, worker called VERY MANY times, just look at logs of method ‘doCall’ (more then 10 times at the moment and next calls is after only one minute (not 15 minutes as it created in code):
10-29 14:44:58.444 23687-23704/ru.biatech.fleettms I/WorkerWrapper: Worker result SUCCESS for Work [ id=387c91af-060c-473d-ab4e-c8d65172e48b, tags={ ru.biatech.fleettms.daemons.CacheWorker } ]
10-29 14:44:58.474 23687-24047/ru.biatech.fleettms D/CacheWorker: doWork() called
10-29 14:44:58.493 23687-23704/ru.biatech.fleettms I/WorkerWrapper: Worker result SUCCESS for Work [ id=e889913c-fbd8-468a-9ae8-4e13aba0f943, tags={ ru.biatech.fleettms.daemons.CacheWorker } ]
10-29 14:44:58.520 23687-24052/ru.biatech.fleettms D/CacheWorker: doWork() called
10-29 14:44:58.540 23687-23704/ru.biatech.fleettms I/WorkerWrapper: Worker result SUCCESS for Work [ id=f7d25122-67b2-4e91-b2bb-677614559c7f, tags={ ru.biatech.fleettms.daemons.CacheWorker } ]
10-29 14:44:58.588 23687-24051/ru.biatech.fleettms D/CacheWorker: doWork() called
10-29 14:44:58.607 23687-23704/ru.biatech.fleettms I/WorkerWrapper: Worker result SUCCESS for Work [ id=0052c751-22c5-4c42-830a-ba93334e48ce, tags={ ru.biatech.fleettms.daemons.CacheWorker } ]
10-29 14:44:58.638 23687-24047/ru.biatech.fleettms D/CacheWorker: doWork() called
10-29 14:44:58.657 23687-23704/ru.biatech.fleettms I/WorkerWrapper: Worker result SUCCESS for Work [ id=387c91af-060c-473d-ab4e-c8d65172e48b, tags={ ru.biatech.fleettms.daemons.CacheWorker } ]
10-29 14:44:58.692 23687-24052/ru.biatech.fleettms D/CacheWorker: doWork() called
10-29 14:44:58.716 23687-24051/ru.biatech.fleettms D/CacheWorker: doWork() called
10-29 14:44:58.717 23687-23704/ru.biatech.fleettms I/WorkerWrapper: Worker result SUCCESS for Work [ id=0a3c7f69-7bae-4e72-9e7b-cf9672ff2e17, tags={ ru.biatech.fleettms.daemons.CacheWorker } ]
10-29 14:44:58.725 23687-24047/ru.biatech.fleettms D/CacheWorker: doWork() called
10-29 14:44:58.741 23687-23704/ru.biatech.fleettms I/WorkerWrapper: Worker result SUCCESS for Work [ id=d8f9e4e5-5abc-47cf-a6bb-7e159ca415b9, tags={ ru.biatech.fleettms.daemons.CacheWorker } ]
10-29 14:44:58.749 23687-23704/ru.biatech.fleettms I/WorkerWrapper: Worker result SUCCESS for Work [ id=f7d25122-67b2-4e91-b2bb-677614559c7f, tags={ ru.biatech.fleettms.daemons.CacheWorker } ]
10-29 14:44:58.791 23687-24052/ru.biatech.fleettms D/CacheWorker: doWork() called
10-29 14:44:58.796 23687-24047/ru.biatech.fleettms D/CacheWorker: doWork() called
10-29 14:44:58.814 23687-23704/ru.biatech.fleettms I/WorkerWrapper: Worker result SUCCESS for Work [ id=86cc2efa-b0b0-4fa3-ac1f-ce884073e897, tags={ ru.biatech.fleettms.daemons.CacheWorker } ]
10-29 14:44:58.824 23687-23704/ru.biatech.fleettms I/WorkerWrapper: Worker result SUCCESS for Work [ id=dce3b734-cc37-4076-ba31-65eff7abcde9, tags={ ru.biatech.fleettms.daemons.CacheWorker } ]
10-29 14:44:58.865 23687-24051/ru.biatech.fleettms D/CacheWorker: doWork() called
10-29 14:44:58.884 23687-23704/ru.biatech.fleettms I/WorkerWrapper: Worker result SUCCESS for Work [ id=026979a5-12d0-420d-8328-7bab7c5ee624, tags={ ru.biatech.fleettms.daemons.CacheWorker } ]
10-29 14:44:58.915 23687-24047/ru.biatech.fleettms D/CacheWorker: doWork() called
10-29 14:44:58.933 23687-23704/ru.biatech.fleettms I/WorkerWrapper: Worker result SUCCESS for Work [ id=d8f9e4e5-5abc-47cf-a6bb-7e159ca415b9, tags={ ru.biatech.fleettms.daemons.CacheWorker } ]
10-29 14:44:58.946 23687-24052/ru.biatech.fleettms D/CacheWorker: doWork() called
10-29 14:44:58.956 23687-24051/ru.biatech.fleettms D/CacheWorker: doWork() called
10-29 14:44:58.975 23687-23704/ru.biatech.fleettms I/WorkerWrapper: Worker result SUCCESS for Work [ id=026979a5-12d0-420d-8328-7bab7c5ee624, tags={ ru.biatech.fleettms.daemons.CacheWorker } ]
10-29 14:44:58.996 23687-23704/ru.biatech.fleettms I/WorkerWrapper: Worker result SUCCESS for Work [ id=bb15463f-4812-422a-9d90-2a003c793e10, tags={ ru.biatech.fleettms.daemons.CacheWorker } ]
10-29 14:44:59.057 23687-24047/ru.biatech.fleettms D/CacheWorker: doWork() called
10-29 14:44:59.078 23687-23704/ru.biatech.fleettms I/WorkerWrapper: Worker result SUCCESS for Work [ id=cf9c8aea-e142-4e42-bb13-17dcb322d481, tags={ ru.biatech.fleettms.daemons.CacheWorker } ]
10-29 14:45:01.534 23687-24052/ru.biatech.fleettms D/CacheWorker: doWork() called
10-29 14:45:01.551 23687-23704/ru.biatech.fleettms I/WorkerWrapper: Worker result SUCCESS for Work [ id=333ee0c9-653f-4c82-8e41-32bc79120811, tags={ ru.biatech.fleettms.daemons.CacheWorker } ]
10-29 14:45:01.568 23687-24051/ru.biatech.fleettms D/CacheWorker: doWork() called
10-29 14:45:01.584 23687-23704/ru.biatech.fleettms I/WorkerWrapper: Worker result SUCCESS for Work [ id=333ee0c9-653f-4c82-8e41-32bc79120811, tags={ ru.biatech.fleettms.daemons.CacheWorker } ]
So, my question is - why worker called SO MANY times, and why so often?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Worker called multiply times and very often · Issue #496 - GitHub
I Use version 1.0.0-alpha10 of worker lib. I create simple worker implementation - class CacheWorker(context: Context, workerParameters: ...
Read more >android - RxWorker being called multiple times even when not ...
the execution of the work starts at the moment when subscribe method of Single object get called. So your statement is not correct:....
Read more >Periodic worker gets called multiple times [121998363]
Sometimes Periodic workManager gets called two times. If Periodic workManager gets called only one time than you have to uninstall the app and...
Read more >What to Do With Employees Calling in Sick Too Often
One of the ways employees calling in sick too often abuse sick time is if they don't have to speak with a supervisor...
Read more >How to Deal With an Employee Always Calling in Sick
The Hartford Small Biz Ahead website suggests one way to counteract employees taking too much sick time is to merge sick days with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Please file issues with WorkManager on the issue tracker with a sample project that reproduces your issue.
这是来自QQ邮箱的假期自动回复邮件。 您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。