Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wendy not syncing periodically #60

Closed
essieM opened this issue Oct 12, 2020 · 5 comments
Closed

Wendy not syncing periodically #60

essieM opened this issue Oct 12, 2020 · 5 comments

Comments

@essieM
Copy link

essieM commented Oct 12, 2020

So I've just configured Wendy on my app and have followed the sample code provided. I'm however noticing that, after the sync is done the first time, it doesn't happen again. I'm calling the sync method the first time a user logs in.

I'm still learning about the library, but my assumption was that as long as I've configured and initialized it in my application class, then configured the PendingTasksJob class as well, Wendy would be running every 15 min or whatever period of time this is set to.

My PendingTasksJob class looks as follows, just like in the sample code provided:

`internal class PendingTasksJob : Job() {

override fun onRunJob(params: Params): Job.Result {
    runTheJob()

    return Job.Result.SUCCESS
}

private fun runTheJob() {
    if (WendyConfig.automaticallyRunTasks) {
        LogUtil.d("Wendy configured to automatically run tasks. Running the periodically scheduled job.")
        Wendy.sharedInstance().runTasks(null)
    } else LogUtil.d("Wendy configured to *not* automatically run tasks. Skipping execution of periodically scheduled job.")
}

companion object {
    const val TAG = "WendyPendingTasksJob"

    fun scheduleJob() {
        JobRequest.Builder(PendingTasksJob.TAG)
                .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED)
                .setPeriodic(TimeUnit.MINUTES.toMillis(15), TimeUnit.MINUTES.toMillis(5))
                .setRequirementsEnforced(true)
                .setUpdateCurrent(true)
                .build()
                .schedule()
    }
}

}`

Am I missing something else? I would truly appreciate some help with this.

Thanks.

@levibostian
Copy link
Owner

Hey there, @essieM. Welcome to Wendy!

I am sorry you have been having this issue. The problem is that the documentation is not complete. I did not realize this until now!

Wendy does not run periodically on it's own. You need to use something like workmanager to run all Wendy tasks periodically.

@essieM
Copy link
Author

essieM commented Oct 12, 2020

Will you be adding sample code to show a quick example of how this would work with Wendy?

@levibostian
Copy link
Owner

I will add to the docs eventually. Right now I am spending all of my development time on this task.

These official docs on workmanager are pretty good to help you setup workmanager. it does not take a lot of code.

When workmanager executes, your WorkManager Job class needs to run Wendy.shared.runTasks(null). That's all the Wendy specific code there is.

@essieM
Copy link
Author

essieM commented Oct 12, 2020

Thanks for the pointers. I think that gives me an idea of what's needed.

@levibostian
Copy link
Owner

Awesome. Enjoy Wendy!

Note: I do have a sample project made that uses Wendy and WorkManager in it: https://github.com/levibostian/AndroidBlanky The problem is that it's a pretty complex app. If you are using Dagger or Hilt in your app already, then AndroidBlanky will be beneficial for you to look over. But if your app is pretty simple then this project will be overkill for you to learn from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants