独特的定期工作会在一段时间后停止执行 [英] Unique periodic work stop executing after a while
问题描述
我已经在我的应用程序中使用WorkManager API实现了唯一定期工作.该工作必须每30分钟检查一次在线资源,并在有未读通知的情况下显示通知.是的,我需要定期工作,因为该资源是IMAP服务器,因此无法使用FCM通知.但是,正如我在 dumpsys jobscheduler
中看到的那样,已正确安排了作业,但是稍后执行了作业.当我运行 dumpsys jobscheduler
时,我读到的内容是这样的:
I've implemented a Unique Periodic Work with WorkManager API in my app. The work has to check every 30min an online resource and show a notification if there are some unread notifications. Yes, I need a periodic work because the resource is a IMAP server, and thus I cannot use FCM notifications.
However the job is correctly scheduled as I can see with dumpsys jobscheduler
, but after a while the job sto executing. When I run dumpsys jobscheduler
I read something like this:
JOB #u0a360/7: aa1b828 com.mypackage.app/androidx.work.impl.background.systemjob.SystemJobService
u0a360 tag=*job*/com.mypackage.app/androidx.work.impl.background.systemjob.SystemJobService
Source: uid=u0a360 user=0 pkg=com.mypackage.app
JobInfo:
Service: com.mypackage.app/androidx.work.impl.background.systemjob.SystemJobService
Requires: charging=false batteryNotLow=false deviceIdle=false
Extras: mParcelledData.dataSize=180
Minimum latency: +29m59s973ms
Backoff: policy=1 initial=+30s0ms
Has early constraint
Required constraints: TIMING_DELAY [0x80000000]
Satisfied constraints: TIMING_DELAY DEVICE_NOT_DOZING BACKGROUND_NOT_RESTRICTED [0x82400000]
Unsatisfied constraints: WITHIN_QUOTA [0x1000000]
Tracking: TIME QUOTA
Implicit constraints:
readyNotDozing: true
readyNotRestrictedInBg: true
Standby bucket: FREQUENT
Base heartbeat: 0
Deferred since: -1h47m30s949ms
Enqueue time: -1h48m0s986ms
Run time: earliest=-1h18m1s13ms, latest=none, original latest=none
Last run heartbeat: 0
Ready: false (job=false user=true !pending=true !active=true !backingup=true comp=true)
这是问题不满意的约束:WITHIN_QUOTA [0x1000000]
,但是很遗憾,我无法找到有关此类错误的文档.Google的官方网站非常模糊: https://developer.android.com/topic/libraries/architecture/workmanager/how-to/debugging
This is the problem Unsatisfied constraints: WITHIN_QUOTA [0x1000000]
, but unfortunately I not able to find a documentation for this kind of errors. The official one from google is quite vague: https://developer.android.com/topic/libraries/architecture/workmanager/how-to/debugging
这是我安排工作的方式:
This is how I schedule the Work:
if (PreferenceController.getInstance().getEmailNotificationInerval() != -1) {
int interval = PreferenceController.getInstance().getEmailNotificationInerval();
Constraints constraints = new Constraints.Builder().build();
PeriodicWorkRequest emailsRequest = new PeriodicWorkRequest.Builder(CheckNewEmailWorker.class, interval, TimeUnit.SECONDS)
.setConstraints(constraints)
.build();
WorkManager.getInstance(context).enqueueUniquePeriodicWork(CheckNewEmailWorker.TAG, ExistingPeriodicWorkPolicy.KEEP, emailsRequest);
}
我使用 BOOT_COMPLETED
接收器在启动时启动它.
And I use a BOOT_COMPLETED
receiver to start it on boot.
在工作程序中,如果一切正常,我返回 Result.success()
,如果出现异常(例如,无连接),则返回 Result.failure()
.
In the worker I return Result.success()
if everything goes OK, and Result.failure()
if an exception is rised (for example no connection).
推荐答案
您有不满意的约束.这就是为什么您的 Worker
未被执行的原因.
You have unsatisfied constraints. This is why your Worker
is not being executed.
Unsatisfied constraints: WITHIN_QUOTA [0x1000000]
这通常意味着您的应用程序正在运行太多的作业计划程序作业.这就是为什么您用完 quota
的原因.另外,您的 quota
由应用程序待机存储桶确定您可能最终会进入.
This usually means that your application is running too many job scheduler jobs. That's why you are running out of quota
. Also, your quota
is determined by the app standby bucket you might be ending up in.
我们添加了一些文档来帮助诊断: https://developer.android.com/topic/libraries/架构/工作经理/操作方法/调试
We added some documentation to help diagnosing this: https://developer.android.com/topic/libraries/architecture/workmanager/how-to/debugging
这篇关于独特的定期工作会在一段时间后停止执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!