Skip to content

Commit

Permalink
use MIN_BACKOFF_MILLIS constant instead of using the number 10 and ad…
Browse files Browse the repository at this point in the history
…d comments
  • Loading branch information
RitikaPahwa4444 committed Aug 30, 2023
1 parent 7f22ab4 commit 714a797
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,20 @@ public void saveContribution(Contribution contribution) {
.save(contribution)
.subscribeOn(ioThreadScheduler)
.subscribe(() -> {
/* Set backoff criteria for the updated upload work request
The default backoff policy is EXPONENTIAL, but while testing we found that it
too long for the uploads to finish. So, set the backoff policy as LINEAR with the
minimum backoff delay value of 10 seconds.
More details on when exactly it is retried:
https://developer.android.com/guide/background/persistent/getting-started/define-work#retries_backoff
*/
OneTimeWorkRequest updatedUploadRequest = new OneTimeWorkRequest
.Builder(UploadWorker.class)
.setBackoffCriteria(BackoffPolicy.LINEAR, 10, TimeUnit.SECONDS)
.setBackoffCriteria(
BackoffPolicy.LINEAR,
OneTimeWorkRequest.MIN_BACKOFF_MILLIS,
TimeUnit.MILLISECONDS)
.build();
WorkManager.getInstance(view.getContext().getApplicationContext())
.enqueueUniqueWork(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,20 @@ public void toggleLimitedConnectionMode() {
viewUtilWrapper
.showShortToast(getBaseContext(), getString(R.string.limited_connection_enabled));
} else {
/* Set backoff criteria for the restart upload request
The default backoff policy is EXPONENTIAL, but while testing we found that it
too long for the uploads to finish. So, set the backoff policy as LINEAR with the
minimum backoff delay value of 10 seconds.
More details on when exactly it is retried:
https://developer.android.com/guide/background/persistent/getting-started/define-work#retries_backoff
*/
OneTimeWorkRequest restartUploadsRequest = new OneTimeWorkRequest
.Builder(UploadWorker.class)
.setBackoffCriteria(BackoffPolicy.LINEAR, 10, TimeUnit.SECONDS)
.setBackoffCriteria(
BackoffPolicy.LINEAR,
OneTimeWorkRequest.MIN_BACKOFF_MILLIS,
TimeUnit.MILLISECONDS)
.build();
WorkManager.getInstance(getApplicationContext()).enqueueUniqueWork(
UploadWorker.class.getSimpleName(),
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,20 @@ public void updateTopCardTitle() {

@Override
public void makeUploadRequest() {
/* Set backoff criteria for the upload work request
The default backoff policy is EXPONENTIAL, but while testing we found that it
too long for the uploads to finish. So, set the backoff policy as LINEAR with the
minimum backoff delay value of 10 seconds.
More details on when exactly it is retried:
https://developer.android.com/guide/background/persistent/getting-started/define-work#retries_backoff
*/
OneTimeWorkRequest uploadRequest = new OneTimeWorkRequest
.Builder(UploadWorker.class)
.setBackoffCriteria(BackoffPolicy.LINEAR, 10, TimeUnit.SECONDS)
.setBackoffCriteria(
BackoffPolicy.LINEAR,
OneTimeWorkRequest.MIN_BACKOFF_MILLIS,
TimeUnit.MILLISECONDS)
.build();
WorkManager.getInstance(getApplicationContext()).enqueueUniqueWork(
UploadWorker.class.getSimpleName(),
Expand Down

0 comments on commit 714a797

Please sign in to comment.