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

listview resets/jumps to top when scrolling fast
How can you use a loading placeholder that is an animated spinner with image loaders like Glide, Picasso etc?
My Application doing too much work in main thread for loading images from SD in android
Contextual ActionBar copy text from custom ListView
Make a video fit in a TextureView (Parts of it are outside (not visible)) using MediaPlayer
findFragmentByTag Strange behavior on Switching Tabs
redirect_uri_missing error is displayed when trying to authenticate in box-api in android
Global Variable Magically Getting Set To Null??
How can Hide/Show some parts of my layout? [closed]
The markup in the document preceding the root element must be well formed
store and get cookies for the code using HttpURLConnection
Implementing back, home and recent apps button for android
Custom DNS on an Ad Hoc network
Querying in-app product inventory without connectivity
Is a Dialog asynchronous on Android?
Android Volley makes 2 requests to the server when retry policy is set to 0

Categories

HOME
android
httparty
nunit
obfuscation
saml-2.0
solver
vscode-extensions
replace
mips
ado.net
text-mining
datastage
xcodebuild
rtf
favicon
gkturnbasedmatch
null-pointer
sigma.js
nodemcu
boost-icl
dataflow-diagram
flask-sqlalchemy
monit
xunit
mount
gpio
flooding
exchangewebservices
mql
record
sharding
reverse
engine.io
salesforce-communities
google-earth-engine
plaintext
levenshtein-distance
apriori
datacachefactory
escpos
http-request
vaadin-charts
uiimage
optimizely
fwrite
lampp
chai-as-promised
spring-integration-sftp
globalize
rserve
corruption
mouseleave
d3-force-directed
winusb
webjars
lrs
tinkerpop3
watch-os-2
respondcms
pre-build-event
hadoop-partitioning
database-relations
beanstalk
mobiledoc-kit
concurrentmodification
assertion
rate-limiting
sapscript
vacuum
keyup
zxspectrum
public-html
rapidsvn
android-vibration
pseudo-class
big-ip
spy++
cocos3d
mobility
lambda-architecture
personalization
matrix-inverse
fpdi
multiautocompletetextview
windows-embedded-standard
high-resolution
stacky
twisted.web
intersect
inkcanvas
mapping-by-code
usertype
urlrewriter
box2d-iphone
node-redis
luajava
blender-2.49
lxr
wordprocessingml
flvplayback
change-management

Resources

Encrypt Message