Skip to content

Instantly share code, notes, and snippets.

@sfeatherstone
Created April 30, 2020 13:11
Show Gist options
  • Select an option

  • Save sfeatherstone/5cccc31bbaff0b6ca57364ca302ae8e6 to your computer and use it in GitHub Desktop.

Select an option

Save sfeatherstone/5cccc31bbaff0b6ca57364ca302ae8e6 to your computer and use it in GitHub Desktop.
WM REST: Job enquerer
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