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

Realm DB & RecyclerView timing issue while deleting items
Android 7 Nougat Notification large icon
Android Button onClick inside Recyclerview gives null object exception [duplicate]
android – How to check if webview is available?
Android NoClassDefFoundError after adding constraint layout
Mandatory fields in android
AudioTrack in Android SDK vs Android NDK for Real-time audio processing?
How can set path of folder in FileProvider in android?
exMsg=Didn't find class “android.support.v7.app.AppCompatDelegateImplV7” on path: DexPathList[[…]]
Best Server-Side Language(s) For Web App With Search Algorithms / Heavy Database Use etc
when syncing webservices with SQLite, array and object error appear
ti not recognized as internal or external command
Location base notification
SurfaceView will never fill when preview camera2?
Find height of an object programmatically in android
Firebase RealTime Database + Google Sign In

Categories

HOME
paraview
eslint
apache-jena
datastore
socket.io
mips
google-cloud-datalab
mvc5
joomla3.0
augeas
text-mining
project-intu
spring-social
heat
linear-algebra
alpacajs
scsi
production
ksh
resourcebundle
gmock
roundup
ckfinder
apktool
rpgle
datastax-enterprise-graph
carrierwave
google-earth
boost-asio
panoramas
sql-server-2000
database-comparison
cart
fstream
activexobject
indy10
salesforce-communities
linq-to-objects
google-data-api
portforwarding
file-sharing
plan-9
pom.xml
ntvs
gitlist
fclose
rserve
activeperl
datamaps
carrot2
arq
qtranslate
jqchart
google-photos
cd-burning
rxtx
jboss-tools
i386
lean
google-query-language
cfchart
createprocess
jbase
atan2
phonertc
haskell-warp
airbrake
zend-currency
dot.js
bcache
viewer
entry-point
ora-00904
extjs2
menubar
visual-studio-express
embedded-fonts
jeromq
rolify
cnf
apache-abdera
intersect
paginator
oracle-enterprise-linux
fitbounds
cross-database
luabind
instantiationexception
drupal-fivestar
lalr
interop-domino
alsb
wysiwym
fault-tolerance
application-planning

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile