android


Back-off for a fixed period with JobScheduler


What I am trying to achieve is:
Three (may increase) JobServices are scheduled.
Each job keeps invoking on a difference set of RESTful APIs from a service until it decides to end.
The service API has an hourly quota limitation, and will return a certain code when invoked too frequently.
The quota is calculated for each application, meaning invocations by all three jobs are counted as a whole.
When a job receives the error code indicating the quota is exceeded, it stops running and wait for re-schedule.
Since the quota is hourly basis, the job only needs to wait for 60 minutes for the cool-down.
To test the back-off strategy, I had an experiment building the job like this:
new JobInfo.Builder(JOB_ID, new ComponentName(this, QuickJob.class))
.setOverrideDeadline(ONE_MINUTE)
.setMinimumLatency(HALF_MINUTE)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.build();
Basicly what the QuickJob does is it logs the timestamp, calls jobFinished(params, true) and waits for Android to reschedule.
From the logs I could see that the first time the job stopped for approximately 1 minute, second time 2 minutes, then it's 4 minutes, 8, ..., which fits the description of the BACKOFF_POLICY_LINEAR policy.
However, in my case, as described in the beginning, I only need the job to back-off for an hour, not 1, 2, 4, 8 hours.
I thought about triggering the jobs at the start of every hour with AlarmManager, but I think it's nice to have the network type settings over the jobs.
Another possible solution I thought about is to have the jobs call jobFinished() with needsReschedule being false, but schedule themselves to run again in the next hour. But this just feels hacky and not... right.
So what are my choices now?

Related Links

Under Android NDK, can a native window be created without Java calls to retrieve the surface?
How to execute a query with IF and ELSE in Android sqlite?
Connecting Android device for debugging
Android Google Analytics SDK show “SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length”
Soft keyboard in webview - no “next” button to tab between input fields
Pause activity and go back to previous activity
pass a String to a class which extends PhoneStateListener
Listview Content Email
map application stops unexpectedly
Android set View visibility programmatically based on screen size
Cursor returning null for rawquery
how to include resource file in distributed jar file?
Android application crashes,force close when user check GPS provider
when greendroid and Actionbarsherlock (ABS) is used in android app
Add more views in a layout programmatically in Android
Android Widget lose pending intent

Categories

HOME
forms
apache-jena
amp-html
mjml
numbers
sublimetext
seo
google-cloud-functions
database-normalization
visual-studio-emulator
gembox-spreadsheet
hpc
mvc5
angularfire2
pattern-matching
octave
fhir
libc
nancy
symmetricds
heat
glyphicons
swagger-2.0
asp.net-core-webapi
systemtime
google-earth
magento-1.8
boost-asio
deltaspike
laravel-eloquent
mailkit
nested-lists
servicestack-text
protege4
metawidget
typesafe-config
numberpicker
visa
vmware-fusion
dcmtk
strftime
opennms
vugen
datamaps
bluez
modelsim
compiler-design
google-photos
shinobi
cubism.js
mongodb-php
expectations
tooleap
firebase-security
thread-sleep
spring-retry
gocql
avisynth
forwarding
fuelcms
android-launcher
text-search
cgi-bin
snoop
mraid
showdialog
jbake
crowd
memset
scrypt
mongohq
merb
apache-abdera
usertype
procedures
denied
cgbitmapcontextcreate
silent
alsb
escrow
localizable.strings
dsoframer

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App