1

I am scheduling a job with Firebase Job Dispatcher to be executed periodically every 1 minute. Here is my configuration:

Job job = dispatcher.newJobBuilder()
                .setLifetime(Lifetime.FOREVER)
                .setService(JobService.class)
                .setTag("JobDispatcher")
                .setReplaceCurrent(false)
                .setRecurring(true)
                .setTrigger(Trigger.executionWindow(30, 60))
                .setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
                .build();

I have kept a logger on the onStartJob of the job service to check when the jobs are executed. Although I have kept 30-60 second window as job interval time, the job is executed every 20-25 mins after a while. The logger looks like this:

Job start 2018-02-14 9:28:16
Job start 2018-02-14 9:30:25
Job start 2018-02-14 9:31:11
Job start 2018-02-14 9:32:46
Job start 2018-02-14 9:34:22
Job start 2018-02-14 9:37:16
Job start 2018-02-14 9:42:27
Job start 2018-02-14 9:48:36
Job start 2018-02-14 9:57:33
Job start 2018-02-14 10:09:11
Job start 2018-02-14 10:24:29
Job start 2018-02-14 10:41:16
Job start 2018-02-14 11:01:52
Job start 2018-02-14 11:25:16
Job start 2018-02-14 11:52:27
Job start 2018-02-14 12:15:06

For first few minutes, the service runs every 1-2 mins which is fine. After some time, interval increases in a linear manner.

NB: I am testing on Android 5.1.1 and in Huwaei Device, the app is enlisted as protected app.

Sabid Habib
  • 419
  • 1
  • 4
  • 16

1 Answers1

2

This is due to your

.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)

If you have a look at this file https://github.com/firebase/firebase-jobdispatcher-android/blob/master/jobdispatcher/src/main/java/com/firebase/jobdispatcher/RetryStrategy.java its is evident that the retry statergy increases linearly in

/** Expected schedule is: [30s, 60s, 90s, 120s, ..., 3600s] */

You can try creating your own custom retry policy by following the link below

https://github.com/firebase/firebase-jobdispatcher-android/issues/179

Ragesh Ramesh
  • 3,470
  • 2
  • 14
  • 20
  • the documentation states that retry strategy is applicable for job execution failure, does this implicate my job is being triggered after initial failure every time? – Sabid Habib Feb 14 '18 at 05:10
  • 1
    Yes it looks so. Since you are triggering in very low frequency(1-2) min, this might happen. – Ragesh Ramesh Feb 14 '18 at 05:27
  • I have implemented customized retrystrategy, but *max back off* must be set to minimum of 5 mins. so, it's causing the service to run in 6-7 min interval now. any work around to reduce this interval to 1 min? – Sabid Habib Feb 14 '18 at 08:19
  • 1
    Both Job scheduler and Firebase Job dispatcher were meant for tasks that have a considerable duration. (ex - more than 10 min). For 1 min tasks its better to use AlarmManager. https://developer.android.com/training/scheduling/alarms.html – Ragesh Ramesh Feb 14 '18 at 09:07