-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Make sync worker only run when needed #12372
Conversation
92c29af
to
710bad9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my brief testing everything worked as expected. Although I didn't check any edge cases (what happens when a worker is stuck, for example). This might be out of scope for this pull request.
The suggestions are just a minor change and, in reality, just eye candy.
app/src/main/java/com/nextcloud/utils/extensions/WorkManagerExtensions.kt
Outdated
Show resolved
Hide resolved
078de3b
to
fc33f40
Compare
Signed-off-by: Jonas Mayer <[email protected]>
Signed-off-by: Jonas Mayer <[email protected]>
Signed-off-by: Jonas Mayer <[email protected]>
Signed-off-by: Jonas Mayer <[email protected]>
fc33f40
to
c420b5e
Compare
Signed-off-by: Jonas Mayer <[email protected]>
Signed-off-by: Jonas Mayer <[email protected]>
Signed-off-by: Jonas Mayer <[email protected]>
Signed-off-by: Jonas Mayer <[email protected]>
Signed-off-by: Jonas Mayer <[email protected]>
Signed-off-by: Jonas Mayer <[email protected]>
Signed-off-by: Jonas Mayer <[email protected]>
Signed-off-by: Jonas Mayer <[email protected]>
b121c21
to
cf8199e
Compare
Problem: With current implementation when periodic sync worker is started and immediate filesync is already running because of changed files it will skip periodic sync which is not intended... But it is really unlikely since immediate file sync with changed files should only run for under 1 sec. |
Signed-off-by: Jonas Mayer <[email protected]>
… into make_sync_service_run_only_once # Conflicts: # app/src/main/java/com/nextcloud/client/jobs/FilesSyncWork.kt
Signed-off-by: Jonas Mayer <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can get rid of repeated codes in WorkManagerExtensions with this code.
private const val TAG = "WorkManager"
fun WorkManager.isWorkRunning(tag: String): Boolean = checkWork(tag, listOf(WorkInfo.State.RUNNING))
fun WorkManager.isWorkScheduled(tag: String): Boolean =
checkWork(tag, listOf(WorkInfo.State.RUNNING, WorkInfo.State.ENQUEUED))
private fun WorkManager.checkWork(tag: String, stateConditions: List<WorkInfo.State>): Boolean {
val statuses: ListenableFuture<List<WorkInfo>> = getWorkInfosByTag(tag)
var workInfoList: List<WorkInfo> = emptyList()
try {
workInfoList = statuses.get()
} catch (e: ExecutionException) {
Log_OC.d(TAG, "ExecutionException in checkWork: $e")
} catch (e: InterruptedException) {
Log_OC.d(TAG, "InterruptedException in checkWork: $e")
}
return workInfoList.any { workInfo -> stateConditions.contains(workInfo.state) }
}
Signed-off-by: Jonas Mayer <[email protected]>
Signed-off-by: Jonas Mayer <[email protected]>
# Conflicts: # app/src/main/java/com/nextcloud/client/jobs/FilesSyncWork.kt
Signed-off-by: Jonas Mayer <[email protected]>
Signed-off-by: Jonas Mayer <[email protected]>
Signed-off-by: Jonas Mayer <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested didn't came across with any regression
Signed-off-by: alperozturk <[email protected]>
APK file: https://www.kaminsky.me/nc-dev/android-artifacts/12372.apk |
Before in theory 2 sync jobs could run and potentially mess with each other (maybe leads to Excessive file upload conflicts after update to 3.26.0 (not before) #11974)