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

Android taking camera return empty intent
How to pass the extras to intent when the application gets launched using Alarm Manager?
Android KeyStore to store the SecretKey for encryption/decryption
How can I set three icon vertically to SwipeMenuItem in SwipeMenuListView
Download files from android application
What's the better way for a complex animation in android?
Can't type Farsi text on Android edit text
BuildConfig.DEBUG always return flase
Connecting Android Phone to local host
App rejected because of Google Pay
Converting singleton to service
android navigation drawer material design webview no scrolling vertically
Content Resolver query returns empty cursor only on a Samsung Galaxy S4 running Lollipop
Android strings.xml can't escape double quote
uploading image with volley and multer node js
Publish Android Lint results from Pipeline project

Categories

HOME
shell
sonarqube
azure-stream-analytics
merge
obfuscation
mstest
pdfbox
edge
square
jquery-ui
google-schemas
ycsb
jsonpath
gource
enterprise-architect
magnetic-cards
docx
altera
linear-algebra
job-scheduling
nim
enterprise-miner
pimcore
ms-access-2003
wcag
magento-1.8
utorrent
r-grid
laravel-eloquent
modalviewcontroller
searchkit
sharepoint-workflow
apiary.io
verifiable-c
vmware-fusion
chronicle-map
avcapturedevice
android-checkbox
facebook-social-plugins
ovf
proget
jquery-ui-draggable
chai-as-promised
twilio-click-to-call
trojan
carrot2
arq
tinkerpop
wpas
opengl-4
monkey
rackspace-cloud
objectscript
rsa-archer-grc
reachability
rocks
aurora
libav
spring-retry
wiredep
zen-cart
toolkit
canalyzer
procedural-programming
delayed-execution
webmatrix-3
strawberry-perl
xml-namespaces
build-script
multiautocompletetextview
spring-3
ora-06550
scrypt
observium
actiondispatch
windows-98
qtconcurrent
cuda-gdb
failing-tests
stress
gobject-introspection
update-statement
jqote
clrstoredprocedure
mtu
visualj#
information-management
httpcookie

Resources

Encrypt Message