From c118b753cd39744930fe9f2d40f6aec17ce9a6d7 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 24 Jan 2023 08:01:41 +0100 Subject: [PATCH] Fixed scheduling daily / sync workers --- .../main/java/eu/faircode/email/WorkerDailyRules.java | 8 +++++--- app/src/main/java/eu/faircode/email/WorkerSync.java | 11 +++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/WorkerDailyRules.java b/app/src/main/java/eu/faircode/email/WorkerDailyRules.java index 5a5cd41551..c8c4e6f935 100644 --- a/app/src/main/java/eu/faircode/email/WorkerDailyRules.java +++ b/app/src/main/java/eu/faircode/email/WorkerDailyRules.java @@ -129,13 +129,15 @@ public class WorkerDailyRules extends Worker { try { if (enabled) { Calendar cal = Calendar.getInstance(); - long delay = cal.getTimeInMillis(); + long now = cal.getTimeInMillis(); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.HOUR_OF_DAY, 1); - cal.add(Calendar.DAY_OF_MONTH, 1); - delay = cal.getTimeInMillis() - delay; + long delay = cal.getTimeInMillis() - now; + if (delay < 0) + cal.add(Calendar.DATE, 1); + delay = cal.getTimeInMillis() - now; Log.i("Queuing " + getName() + " delay=" + (delay / (60 * 1000L)) + "m"); PeriodicWorkRequest.Builder builder = diff --git a/app/src/main/java/eu/faircode/email/WorkerSync.java b/app/src/main/java/eu/faircode/email/WorkerSync.java index f852550363..6ab86d45fb 100644 --- a/app/src/main/java/eu/faircode/email/WorkerSync.java +++ b/app/src/main/java/eu/faircode/email/WorkerSync.java @@ -72,16 +72,19 @@ public class WorkerSync extends Worker { String user = prefs.getString("cloud_user", null); String password = prefs.getString("cloud_password", null); boolean enabled = !(TextUtils.isEmpty(user) || TextUtils.isEmpty(password)); + Log.i("Cloud worker enabled=" + enabled); try { if (enabled) { Calendar cal = Calendar.getInstance(); - long delay = cal.getTimeInMillis(); + long now = cal.getTimeInMillis(); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MINUTE, 30); - cal.set(Calendar.HOUR_OF_DAY, 1); - cal.add(Calendar.DAY_OF_MONTH, 1); - delay = cal.getTimeInMillis() - delay; + cal.set(Calendar.HOUR_OF_DAY, 8); + long delay = cal.getTimeInMillis() - now; + if (delay < 0) + cal.add(Calendar.DATE, 1); + delay = cal.getTimeInMillis() - now; EntityLog.log(context, EntityLog.Type.Cloud, "Queuing " + getName() + " delay=" + (delay / (60 * 1000L)) + "m");