This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #5: Schedule frequent updates of experiments configuration
Closes #5: Schedule frequent updates of experiments configuration Fix serialization issues and add Sync class Don't expose SyncTask and add license headers Add jobFinished to SyncJob and add tests for SyncConfigExtensions Document Fretboard scheduleUpdateExperiments and Sync execute methods Removed serializable classes and scheduler interface and make SyncJob abstract Pass jobId as schedule parameter
- Loading branch information
1 parent
cd812f3
commit fcf13f7
Showing
7 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'jacoco' | ||
apply plugin: 'jacoco-android' | ||
|
||
android { | ||
compileSdkVersion rootProject.ext.build['compileSdkVersion'] | ||
|
||
defaultConfig { | ||
minSdkVersion rootProject.ext.build['minSdkVersion'] | ||
targetSdkVersion rootProject.ext.build['targetSdkVersion'] | ||
|
||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
lintOptions { | ||
warningsAsErrors true | ||
abortOnError true | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
jacocoAndroidUnitTestReport { | ||
csv.enabled false | ||
html.enabled true | ||
xml.enabled true | ||
} | ||
|
||
dependencies { | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib:${rootProject.ext.dependencies['kotlin']}" | ||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${rootProject.ext.dependencies['coroutines']}" | ||
implementation project(':fretboard') | ||
|
||
testImplementation "junit:junit:${rootProject.ext.dependencies['junit']}" | ||
testImplementation "org.robolectric:robolectric:${rootProject.ext.dependencies['robolectric']}" | ||
testImplementation "org.mockito:mockito-core:${rootProject.ext.dependencies['mockito']}" | ||
androidTestImplementation "com.android.support.test:runner:${rootProject.ext.dependencies['runner']}" | ||
androidTestImplementation "com.android.support:support-annotations:${rootProject.ext.dependencies['annotations']}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
5 changes: 5 additions & 0 deletions
5
fretboard-scheduler-jobscheduler/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<!-- This Source Code Form is subject to the terms of the Mozilla Public | ||
- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="mozilla.components.service.fretboard.scheduler.jobscheduler" /> |
41 changes: 41 additions & 0 deletions
41
.../mozilla/components/service/fretboard/scheduler/jobscheduler/JobSchedulerSyncScheduler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.service.fretboard.scheduler.jobscheduler | ||
|
||
import android.app.job.JobInfo | ||
import android.app.job.JobScheduler | ||
import android.content.ComponentName | ||
import android.content.Context | ||
import java.util.concurrent.TimeUnit | ||
|
||
/** | ||
* Class used to schedule sync of experiment | ||
* configuration from the server | ||
*/ | ||
class JobSchedulerSyncScheduler(context: Context) { | ||
private val jobScheduler = context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler | ||
|
||
/** | ||
* Schedule sync with the constrains specified | ||
* | ||
* @param jobInfo object with the job constraints | ||
*/ | ||
fun schedule(jobInfo: JobInfo) { | ||
jobScheduler.schedule(jobInfo) | ||
} | ||
|
||
/** | ||
* Schedule sync with the default constraints | ||
* (once a day) | ||
* | ||
* @param serviceName object with the service to run | ||
*/ | ||
fun schedule(jobId: Int, serviceName: ComponentName) { | ||
val jobInfo = JobInfo.Builder(jobId, serviceName) | ||
.setPeriodic(TimeUnit.DAYS.toMillis(1)) | ||
.build() | ||
jobScheduler.schedule(jobInfo) | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...uler/src/main/java/mozilla/components/service/fretboard/scheduler/jobscheduler/SyncJob.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.service.fretboard.scheduler.jobscheduler | ||
|
||
import android.app.job.JobParameters | ||
import android.app.job.JobService | ||
import mozilla.components.service.fretboard.Fretboard | ||
import java.util.concurrent.Executors | ||
|
||
abstract class SyncJob : JobService() { | ||
private val executor = Executors.newSingleThreadExecutor() | ||
|
||
override fun onStartJob(params: JobParameters): Boolean { | ||
executor.execute { | ||
try { | ||
getFretboard().updateExperiments() | ||
} catch (e: InterruptedException) { | ||
// Cancel thread | ||
} finally { | ||
jobFinished(params, false) | ||
} | ||
} | ||
return true | ||
} | ||
|
||
override fun onStopJob(params: JobParameters?): Boolean { | ||
executor.shutdownNow() | ||
return true | ||
} | ||
|
||
/** | ||
* Used to provide the instance of Fretboard | ||
* the app is using | ||
* | ||
* @return current Fretboard instance | ||
*/ | ||
abstract fun getFretboard(): Fretboard | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
include ':fretboard', ':fretboard-client-kinto', ':fretboard-storage-flatfile' | ||
include ':fretboard', ':fretboard-client-kinto', ':fretboard-storage-flatfile', ':fretboard-scheduler-jobscheduler' |