Skip to content
Permalink
Browse files

Move to using CoroutineWorker

  • Loading branch information...
chrisbanes committed Apr 29, 2019
1 parent e11ad9f commit e26c00eb72ce88abfd4d555464d6859f1cd181e5
@@ -130,8 +130,8 @@ object Libs {
}

object Work {
private const val version = "1.0.0-rc01"
val runtimeKtx = "android.arch.work:work-runtime-ktx:$version"
private const val version = "2.0.1"
val runtimeKtx = "androidx.work:work-runtime-ktx:$version"
}
}

@@ -17,34 +17,32 @@
package app.tivi.tasks

import android.content.Context
import androidx.work.Worker
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import app.tivi.interactors.SyncFollowedShows
import app.tivi.interactors.launchInteractor
import app.tivi.tasks.inject.ChildWorkerFactory
import app.tivi.util.Logger
import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.CoroutineDispatcher

class SyncAllFollowedShows @AssistedInject constructor(
@Assisted params: WorkerParameters,
@Assisted context: Context,
private val syncFollowedShows: SyncFollowedShows,
private val logger: Logger
) : Worker(context, params) {
) : CoroutineWorker(context, params) {
companion object {
const val TAG = "sync-all-followed-shows"
const val NIGHTLY_SYNC_TAG = "night-sync-all-followed-shows"
}

override fun doWork(): Result {
logger.d("$TAG worker running")
override val coroutineContext: CoroutineDispatcher
get() = syncFollowedShows.dispatcher

runBlocking {
GlobalScope.launchInteractor(syncFollowedShows, SyncFollowedShows.ExecuteParams(true)).join()
}
override suspend fun doWork(): Result {
logger.d("$TAG worker running")
syncFollowedShows(SyncFollowedShows.ExecuteParams(true))
return Result.success()
}

@@ -17,22 +17,22 @@
package app.tivi.tasks

import android.content.Context
import androidx.work.CoroutineWorker
import androidx.work.Data
import androidx.work.Worker
import androidx.work.WorkerParameters
import app.tivi.interactors.UpdateFollowedShowSeasonData
import app.tivi.tasks.inject.ChildWorkerFactory
import app.tivi.util.Logger
import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.CoroutineDispatcher

class SyncShowWatchedProgress @AssistedInject constructor(
@Assisted params: WorkerParameters,
@Assisted context: Context,
private val updateShowSeasonsAndWatchedProgress: UpdateFollowedShowSeasonData,
private val logger: Logger
) : Worker(context, params) {
) : CoroutineWorker(context, params) {
companion object {
const val TAG = "sync-show-watched-episodes"
private const val PARAM_SHOW_ID = "show-id"
@@ -42,16 +42,17 @@ class SyncShowWatchedProgress @AssistedInject constructor(
.build()
}

override fun doWork(): Result {
override val coroutineContext: CoroutineDispatcher
get() = updateShowSeasonsAndWatchedProgress.dispatcher

override suspend fun doWork(): Result {
val showId = inputData.getLong(PARAM_SHOW_ID, -1)
logger.d("$TAG worker running for show id: $showId")

updateShowSeasonsAndWatchedProgress.setParams(UpdateFollowedShowSeasonData.Params(showId))
updateShowSeasonsAndWatchedProgress(UpdateFollowedShowSeasonData.ExecuteParams(true))

return runBlocking {
updateShowSeasonsAndWatchedProgress(UpdateFollowedShowSeasonData.ExecuteParams(true))
Result.success()
}
return Result.success()
}

@AssistedInject.Factory

0 comments on commit e26c00e

Please sign in to comment.
You can’t perform that action at this time.