Skip to content

Commit

Permalink
expose favorite tools sync via the SyncManager
Browse files Browse the repository at this point in the history
  • Loading branch information
frett committed Oct 2, 2023
1 parent ddd09b8 commit 118feeb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.cru.godtools.sync.task.FollowupSyncTasks
import org.cru.godtools.sync.task.LanguagesSyncTasks
import org.cru.godtools.sync.task.ToolSyncTasks
import org.cru.godtools.sync.task.UserCounterSyncTasks
import org.cru.godtools.sync.task.UserFavoriteToolsSyncTasks
import org.cru.godtools.sync.task.UserSyncTasks
import org.cru.godtools.sync.work.scheduleSyncFollowupsWork
import org.cru.godtools.sync.work.scheduleSyncLanguagesWork
Expand Down Expand Up @@ -104,6 +105,18 @@ class GodToolsSyncService @VisibleForTesting internal constructor(
}
}

suspend fun syncFavoriteTools(force: Boolean) = try {
executeSync<UserFavoriteToolsSyncTasks> { syncFavoriteTools(force) }
} finally {
coroutineScope.launch { syncDirtyFavoriteTools() }
}
suspend fun syncDirtyFavoriteTools() = try {
executeSync<UserFavoriteToolsSyncTasks> { syncDirtyFavoriteTools() }
} catch (e: CancellationException) {
// TODO: work manager job
throw e
}

fun syncToolSharesAsync() = coroutineScope.async { syncToolShares() }
private suspend fun syncToolShares() = try {
executeSync<ToolSyncTasks> { syncShares() }.also { if (!it) workManager.scheduleSyncToolSharesWork() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ internal abstract class SyncTaskModule {
@IntoMap
@SyncTaskKey(UserCounterSyncTasks::class)
internal abstract fun userCounterSyncTasks(tasks: UserCounterSyncTasks): BaseSyncTasks

@Binds
@IntoMap
@SyncTaskKey(UserFavoriteToolsSyncTasks::class)
internal abstract fun userFavoriteToolsSyncTasks(tasks: UserFavoriteToolsSyncTasks): BaseSyncTasks
}

0 comments on commit 118feeb

Please sign in to comment.