Unique periodic work stop executing after a while

0

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)

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);
}

And I use a BOOT_COMPLETED receiver to start it on boot.

In the worker I return Result.success() if everything goes OK, and Result.failure() if an exception is rised (for example no connection).

android
android-workmanager
android-jobscheduler
asked on Stack Overflow Jan 6, 2020 by Philip

1 Answer

0

You have unsatisfied constraints. This is why your Worker is not being executed.

Unsatisfied constraints: WITHIN_QUOTA [0x1000000]

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.

We added some documentation to help diagnosing this: https://developer.android.com/topic/libraries/architecture/workmanager/how-to/debugging

answered on Stack Overflow Jan 6, 2020 by Rahul

User contributions licensed under CC BY-SA 3.0