question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JobRescheduleService incorrectly reschedules my job

See original GitHub issue

Hello guys,

Your library is helping me a lot and you have my sincerest appreciation for your work. However, I think I have stumbled upon a bug.

The way I’m using the library is similar to a calendar type app. I am scheduling exact type jobs. When a job runs I schedule another job for tomorrow at the exact same time or next week at the exact same day and time.

I think I have found an issue where the JobRescheduleService class will incorrectly reschedule one of my jobs. It basically reschedules the job for right now without a delay, when initially it was scheduled with a 24 hour delay.

I have prepared a detailed log together with explanations of what the app is doing at every point in the log and in what state the app is.

I have managed to reproduce the issue with the exact steps below on Android versions 6.0 & 7.1.1. Whatever else information I should provide please let me know.

//Open app, schedule a job in a few seconds

D/JobProxy14: Scheduled alarm, request{id=1, tag=activity:55f8b160dba84c2e86759bf384d0a118}, delay 00:00:26, exact true, reschedule count 0

//Close app completely (swipe off app in recent apps)
//Job time comes and it starts

08-09 17:53:00.581 9635-9667/? D/JobRescheduleService: Reschedule service started
08-09 17:53:00.585 9635-9668/? D/PlatformAlarmService: Run job, request{id=1, tag=activity:55f8b160dba84c2e86759bf384d0a118}, waited 00:00:26, delay 00:00:26
08-09 17:53:00.590 9635-9668/? I/JobExecutor: Executing request{id=1, tag=activity:55f8b160dba84c2e86759bf384d0a118}, context PlatformAlarmService

//Job runs. My job does 2 things. Fires up a notification (opening the app process).  And schedules another job with a delay of 24 hours (Tomorrow at the same time)
//If you're wondering why I'm not using a periodic job, it's because I need daily and weekly reminders at the exact same time.

08-09 17:53:00.632 9635-9669/? D/JobProxy14: Scheduled alarm, request{id=2, tag=activity:55f8b160dba84c2e86759bf384d0a118}, delay 23:59:59, exact true, reschedule count 0
08-09 17:53:00.632 9635-9669/? I/JobExecutor: Finished job{id=1, finished=true, result=SUCCESS, canceled=false, periodic=false, class=ReminderJob, tag=activity:55f8b160dba84c2e86759bf384d0a118}
08-09 17:53:00.635 9635-9668/? D/PlatformAlarmService: Finished job, request{id=1, tag=activity:55f8b160dba84c2e86759bf384d0a118} SUCCESS

//at this point the Job ran, displayed the notification and correctly scheduled the next job for tomorrow (id = 2)
//I tap on the notification which opens the app (the app was completely closed) and then I immediately background the app.

09 17:53:10.616 9635-9667/? I/JobManager: Found pending job request{id=2, tag=activity:55f8b160dba84c2e86759bf384d0a118}, canceling
08-09 17:53:10.628 9635-9667/? D/JobProxy14: Scheduled alarm, request{id=2, tag=activity:55f8b160dba84c2e86759bf384d0a118}, delay 00:00:00, exact true, reschedule count 0
08-09 17:53:10.628 9635-9667/? D/JobRescheduleService: Reschedule 1 jobs of 1 jobs
08-09 17:53:10.932 9635-9856/? D/PlatformAlarmService: Run job, request{id=2, tag=activity:55f8b160dba84c2e86759bf384d0a118}, waited 00:00:00, delay 00:00:00
08-09 17:53:10.940 9635-9856/io.healthsteps.healthsteps I/JobExecutor: Executing request{id=2, tag=activity:55f8b160dba84c2e86759bf384d0a118}, context PlatformAlarmService

//Since the app has just been started (by way of the notification) it looks like your *JobRescheduleService* runs at app start and is cleaning up all the jobs and reschedules them or something.

//The problem is that the job I scheduled above for tomorrow is cancelled and is incorrectly rescheduled for right now, without a delay.
//And immediately, it runs:

08-09 17:53:10.984 9635-9669/? D/JobProxy14: Scheduled alarm, request{id=3, tag=activity:55f8b160dba84c2e86759bf384d0a118}, delay 23:59:49 (+1 day), exact true, reschedule count 0
08-09 17:53:10.985 9635-9669/? I/JobExecutor: Finished job{id=2, finished=true, result=SUCCESS, canceled=false, periodic=false, class=ReminderJob, tag=activity:55f8b160dba84c2e86759bf384d0a118}
08-09 17:53:10.989 9635-9856/? D/PlatformAlarmService: Finished job, request{id=2, tag=activity:55f8b160dba84c2e86759bf384d0a118} SUCCESS

I can reproduce this issue 100% of the time provided I follow the exact steps above. The app must be closed off after the first job is scheduled. The app must be opened when the job runs and then it must be backgrounded (paused). These last last 2 steps must be done before the JobRescheduleService starts doing its thing.

I forgot to mention, this is how I’m scheduling the jobs:

    new JobRequest.Builder(repeatingReminder.getActivityID())
              .setExact(timeToFireIn)
              .setExtras(extras)
              .setPersisted(true)
              .build()
              .schedule();

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15

github_iconTop GitHub Comments

1reaction
vRallevcommented, Sep 10, 2017

@AndreiHarasemiuc @dshatz I’m pretty confident that I found the cause for the bug. Thanks for your patience! Could you give version 1.2.0-RC2 a try? This one includes the fix.

1reaction
vRallevcommented, Sep 5, 2017

@Abdullah-Hussein https://developer.android.com/reference/android/app/AlarmManager.html#set(int, long, android.app.PendingIntent) Please don’t post in this issue anymore. If you still have questions, create another issue. Your “problem” is expected behavior and working properly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exact jobs always rescheduled in JobRescheduleService #215
For my app I schedule a series of jobs to be executed at an exact time to notify the user of an event....
Read more >
JobRescheduleService (library 1.2.4 API)
This service reschedules your jobs in case this should be necessary. Usually rescheduling is necessary after a reboot. If you don't want that...
Read more >
How To Professionally Reschedule a Job Interview | Indeed.com
Here's everything you need to know about rescheduling your job interview, including respectful reasons and how to do so respectfully.
Read more >
This Is How You Reschedule An Interview Without Losing the ...
Yes, it is certainly possibly to reschedule an interview without sabotaging your chances of getting the job. These are the situations when ...
Read more >
How to reschedule a job in android in case of failure using job ...
The JobService method jobFinished() has a needsReschedule parameter. Try calling this method after you received the unrecoverable error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found