Skip to content

Commit

Permalink
Android: Start workers if pending jobs exist, refactor startWorker lo…
Browse files Browse the repository at this point in the history
…gic.

Modified worker initiation process in FileTransferBackground.java to ensure workers start if there are pending jobs at initialization. Previously, workers were only if an upload was added. Any jobs that were in the queue were ignored until then.

Additionally, we can now just call startWorkers() and it will check to see if the workers are already started. If they are, do nothing.
  • Loading branch information
nvahalik committed Jul 18, 2024
1 parent 6f49801 commit 5f394aa
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/android/FileTransferBackground.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ private void initManager(String options, final CallbackContext callbackContext)

this.uploadCallback = callbackContext;
this.ready = true;

// If we have pending jobs, start the workers.
if (AckDatabase.getInstance(cordova.getContext()).pendingUploadDao().getPendingUploadsCount() > 0) {
startWorkers();
}
}

private void addUpload(JSONObject jsonPayload) {
Expand Down Expand Up @@ -329,13 +334,16 @@ private void addUpload(JSONObject jsonPayload) {
)
);

if (!workerIsStarted) {
startWorkers();
workerIsStarted = true;
}
startWorkers();
}

private void startWorkers() {
if (workerIsStarted) {
return;
}

workerIsStarted = true;

logMessage("startUpload: Starting worker via work manager");

for (int i = 0; i < ccUpload; i++) {
Expand Down

0 comments on commit 5f394aa

Please sign in to comment.