Created
April 30, 2020 13:11
-
-
Save sfeatherstone/5cccc31bbaff0b6ca57364ca302ae8e6 to your computer and use it in GitHub Desktop.
WM REST: Job enquerer
This file contains hidden or 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
| companion object { | |
| fun submitPost(applicationContext: Context, duration: Int, successPercent:Int, tagName: String): UUID { | |
| val constraints = Constraints.Builder() | |
| .setRequiredNetworkType(NetworkType.CONNECTED) | |
| .build() | |
| val restWorkRequest = OneTimeWorkRequestBuilder<PostToServerWorker>() | |
| .setInputData(workDataOf(JOB_TIME to duration, | |
| JOB_SUCCESS_CHANCE to successPercent, | |
| ATTEMPT_RETRIES to 2)) | |
| .setConstraints(constraints) | |
| .addTag(tagName) | |
| .build() | |
| val workManager = WorkManager.getInstance(applicationContext) | |
| workManager.enqueue(restWorkRequest) | |
| return restWorkRequest.id | |
| } | |
| const val Progress = "Progress" | |
| private const val JOB_TIME = "JOB_TIME_INT" | |
| private const val JOB_SUCCESS_CHANCE = "JOB_FAIL_CHANCE_FLOAT" | |
| private const val ATTEMPT_RETRIES = "ATTEMPT_RETRIES_INT" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment