-
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.
Use Java to launch tasks for avoid introspection issues.
- Loading branch information
Showing
4 changed files
with
76 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
cython | ||
virtualenv | ||
git+https://github.com/learningequality/python-for-android@5dc7bdb3364f5ed5b573ceffdb364382ae181955#egg=python-for-android | ||
git+https://github.com/learningequality/python-for-android@6ba12f935ff753a58d396190c24a7a387b95ef9c#egg=python-for-android |
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,59 @@ | ||
package org.learningequality; | ||
|
||
import androidx.work.Data; | ||
import androidx.work.WorkManager; | ||
import androidx.work.WorkRequest; | ||
import androidx.work.OneTimeWorkRequest; | ||
import androidx.work.PeriodicWorkRequest; | ||
import androidx.work.BackoffPolicy; | ||
import androidx.work.ExistingWorkPolicy; | ||
import androidx.work.ExistingPeriodicWorkPolicy; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.learningequality.Kolibri.TaskworkerWorker; | ||
import org.kivy.android.PythonActivity; | ||
|
||
|
||
public class Task { | ||
public static void enqueueIndefinitely(String id, int interval, int delay, int retryInterval) { | ||
WorkManager workManager = WorkManager.getInstance(PythonActivity.mActivity); | ||
Data data = TaskworkerWorker.buildInputData(id); | ||
|
||
PeriodicWorkRequest.Builder workRequestBuilder = new PeriodicWorkRequest.Builder( | ||
TaskworkerWorker.class, interval, TimeUnit.SECONDS | ||
); | ||
|
||
if (retryInterval > 0) { | ||
workRequestBuilder.setBackoffCriteria( | ||
BackoffPolicy.LINEAR, retryInterval, TimeUnit.SECONDS | ||
); | ||
} | ||
if (delay > 0) { | ||
workRequestBuilder.setInitialDelay(delay, TimeUnit.SECONDS); | ||
} | ||
workRequestBuilder.setInputData(data); | ||
PeriodicWorkRequest workRequest = workRequestBuilder.build(); | ||
workManager.enqueueUniquePeriodicWork(id, ExistingPeriodicWorkPolicy.KEEP, workRequest); | ||
} | ||
public static void enqueueOnce(String id, int delay, int retryInterval, boolean keep) { | ||
WorkManager workManager = WorkManager.getInstance(PythonActivity.mActivity); | ||
Data data = TaskworkerWorker.buildInputData(id); | ||
|
||
OneTimeWorkRequest.Builder workRequestBuilder = new OneTimeWorkRequest.Builder(TaskworkerWorker.class); | ||
if (retryInterval > 0) { | ||
workRequestBuilder.setBackoffCriteria( | ||
BackoffPolicy.LINEAR, retryInterval, TimeUnit.SECONDS | ||
); | ||
} | ||
if (delay > 0) { | ||
workRequestBuilder.setInitialDelay(delay, TimeUnit.SECONDS); | ||
} | ||
workRequestBuilder.setInputData(data); | ||
OneTimeWorkRequest workRequest = workRequestBuilder.build(); | ||
if (keep) { | ||
workManager.enqueueUniqueWork(id, ExistingWorkPolicy.KEEP, workRequest); | ||
} else { | ||
workManager.enqueueUniqueWork(id, ExistingWorkPolicy.APPEND_OR_REPLACE, workRequest); | ||
} | ||
} | ||
} |
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