Skip to content

Provide quick and easy way to run background repository sync tasks.  #61

@levibostian

Description

@levibostian

It's a common task for Teller users to run iOS background fetch with Teller repositories so that they can keep repository data always up-to-date.

The current method is hands on and a roadblock for devs. It requires some work:

extension AppDelegate {

    func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        let backgroundFetchResult = Wendy.shared.backgroundFetchRunTasks(application, performFetchWithCompletionHandler: completionHandler)

        // ??? What do we do about other SDKs that run background commands and return a UIBackgroundFetchResult?

        // ??? What should a Teller repository sync return as a UIBackgroundFetchResult? Currently, it's up to the developer to implement this themselves. 
        repositorySyncService.sync { (success) in
            completionHandler(backgroundFetchResult)
        }
    }

}

import RxSwift

protocol RepositorySyncService {
    func sync(onComplete: @escaping (_ success: Bool) -> Void)
}

class TellerRepositorySyncService: RepositorySyncService {

    private let reposRepository: ReposRepository
    private let githubUsernameRepository: GitHubUsernameRepository

    private let disposeBag = DisposeBag()

    init(reposRepository: ReposRepository,
         githubUsernameRepository: GitHubUsernameRepository) {
        self.reposRepository = reposRepository
        self.githubUsernameRepository = githubUsernameRepository
    }

    func sync(onComplete: @escaping (_ success: Bool) -> Void) {
        if let usernameReposToFetch = githubUsernameRepository.dataSource.value {
            reposRepository.requirements = ReposDataSource.GetDataRequirements(githubUsername: usernameReposToFetch)

            try! reposRepository.refresh(force: false)
                .subscribe(onSuccess: { (result) in
                    onComplete(result.didSucceed())
                }).disposed(by: disposeBag)
        }
    }

}

As you can see from the example above, there are some problems currently:

  1. What do developers do when trying to combine 2+ separate UIBackgroundFetchResult?
  2. Teller does not provide a way to create a UIBackgroundFetchResult for you. You must do it yourself. It would be great to do this work for you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions