From 5f394aa6861f674ec76b6f8aaee326888908f7ed Mon Sep 17 00:00:00 2001 From: Nick Vahalik Date: Wed, 17 Jul 2024 21:11:10 -0500 Subject: [PATCH] Android: Start workers if pending jobs exist, refactor startWorker logic. 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. --- src/android/FileTransferBackground.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/android/FileTransferBackground.java b/src/android/FileTransferBackground.java index 27841a0e..ed650b90 100644 --- a/src/android/FileTransferBackground.java +++ b/src/android/FileTransferBackground.java @@ -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) { @@ -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++) {