-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Access kolibri's job storage database to reconcile tasks
- Loading branch information
Showing
13 changed files
with
701 additions
and
30 deletions.
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
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
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
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
47 changes: 47 additions & 0 deletions
47
...for-android/dists/kolibri/src/main/java/org/learningequality/Kolibri/ReconcileWorker.java
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,47 @@ | ||
package org.learningequality.Kolibri; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.util.Log; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.work.ListenableWorker; | ||
import androidx.work.WorkerParameters; | ||
import androidx.work.impl.utils.futures.SettableFuture; | ||
|
||
import com.google.common.util.concurrent.ListenableFuture; | ||
|
||
import java9.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.Executor; | ||
|
||
import org.learningequality.Task; | ||
|
||
public class ReconcileWorker extends ListenableWorker { | ||
public static final String TAG = "Kolibri.ReconcileWorker"; | ||
|
||
public ReconcileWorker(@NonNull Context appContext, @NonNull WorkerParameters workerParams) { | ||
super(appContext, workerParams); | ||
} | ||
|
||
@SuppressLint("RestrictedApi") | ||
@NonNull | ||
public ListenableFuture<Result> startWork() { | ||
Log.i(TAG, "Starting reconcile task"); | ||
SettableFuture<Result> future = SettableFuture.create(); | ||
Executor executor = getBackgroundExecutor(); | ||
|
||
CompletableFuture<Boolean> f = Task.reconcile(getApplicationContext(), executor); | ||
|
||
f.whenCompleteAsync((result, throwable) -> { | ||
if (throwable != null) { | ||
Log.e(TAG, "Reconcile task failed", throwable); | ||
future.setException(throwable); | ||
} else { | ||
Log.i(TAG, "Reconcile task completed: " + (result ? "success" : "failure")); | ||
future.set(result ? Result.success() : Result.failure()); | ||
} | ||
}, executor); | ||
|
||
return future; | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
...r-android/dists/kolibri/src/main/java/org/learningequality/Kolibri/sqlite/JobStorage.java
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,39 @@ | ||
package org.learningequality.Kolibri.sqlite; | ||
|
||
import org.learningequality.sqlite.schema.DatabaseTable; | ||
|
||
public class JobStorage { | ||
public static final String DATABASE_NAME = "job_storage.sqlite3"; | ||
|
||
public static class Jobs implements DatabaseTable { | ||
public static final String TABLE_NAME = "jobs"; | ||
|
||
public String getTableName() { | ||
return TABLE_NAME; | ||
} | ||
|
||
public static final StringColumn id = new StringColumn("id"); | ||
public static final StringColumn worker_process = new StringColumn("worker_process"); | ||
public static final StringColumn worker_thread = new StringColumn("worker_thread"); | ||
public static final StringColumn worker_extra = new StringColumn("worker_extra"); | ||
public static final StringColumn time_updated = new StringColumn("time_updated"); | ||
public static final StringColumn state = new StringColumn("state"); | ||
|
||
public enum State implements ColumnEnum<String> { | ||
PENDING, | ||
QUEUED, | ||
SCHEDULED, | ||
SELECTED, | ||
RUNNING, | ||
CANCELING, | ||
CANCELED, | ||
FAILED, | ||
COMPLETED | ||
; | ||
|
||
public StringColumn getColumn() { | ||
return state; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.