Reputation: 694
At my company, we have a use case where we need to disable all running workers and after doing some other work we can enable them again, is there a way I can do that with WorkManager directly or I will have to fallback to cancelAllWork*()
and enqueue new workers from scratch, I don't want to do the latter I just want to pause the current workers and resume them again after we finish the other work, Any solutions?
Upvotes: 3
Views: 799
Reputation: 6496
Jetpack WorkManager doesn't support to pause/resume of current Workers, you may want to add this as a feature request on the public issue tracker.
As you wrote one option is to cancel all the work and manage the stoppages of running workers as explained in WorkManager's documentation.
Another option could be to gate all your workers with a flag that you check if "work" is currently paused. In this case you can return a Result.retry()
. There are in this case some implication on the delays introduced into work's retries and on what are your requirement for workers that are already running once you pause them (are they run to completion or stopped and retried once the work is restarted).
Upvotes: 1