Fixed scheduling daily / sync workers

pull/212/head
M66B 2 years ago
parent 61554af6e9
commit c118b753cd

@ -129,13 +129,15 @@ public class WorkerDailyRules extends Worker {
try { try {
if (enabled) { if (enabled) {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
long delay = cal.getTimeInMillis(); long now = cal.getTimeInMillis();
cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.SECOND, 0); cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0); cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.HOUR_OF_DAY, 1); cal.set(Calendar.HOUR_OF_DAY, 1);
cal.add(Calendar.DAY_OF_MONTH, 1); long delay = cal.getTimeInMillis() - now;
delay = cal.getTimeInMillis() - delay; if (delay < 0)
cal.add(Calendar.DATE, 1);
delay = cal.getTimeInMillis() - now;
Log.i("Queuing " + getName() + " delay=" + (delay / (60 * 1000L)) + "m"); Log.i("Queuing " + getName() + " delay=" + (delay / (60 * 1000L)) + "m");
PeriodicWorkRequest.Builder builder = PeriodicWorkRequest.Builder builder =

@ -72,16 +72,19 @@ public class WorkerSync extends Worker {
String user = prefs.getString("cloud_user", null); String user = prefs.getString("cloud_user", null);
String password = prefs.getString("cloud_password", null); String password = prefs.getString("cloud_password", null);
boolean enabled = !(TextUtils.isEmpty(user) || TextUtils.isEmpty(password)); boolean enabled = !(TextUtils.isEmpty(user) || TextUtils.isEmpty(password));
Log.i("Cloud worker enabled=" + enabled);
try { try {
if (enabled) { if (enabled) {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
long delay = cal.getTimeInMillis(); long now = cal.getTimeInMillis();
cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.SECOND, 0); cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 30); cal.set(Calendar.MINUTE, 30);
cal.set(Calendar.HOUR_OF_DAY, 1); cal.set(Calendar.HOUR_OF_DAY, 8);
cal.add(Calendar.DAY_OF_MONTH, 1); long delay = cal.getTimeInMillis() - now;
delay = cal.getTimeInMillis() - delay; if (delay < 0)
cal.add(Calendar.DATE, 1);
delay = cal.getTimeInMillis() - now;
EntityLog.log(context, EntityLog.Type.Cloud, EntityLog.log(context, EntityLog.Type.Cloud,
"Queuing " + getName() + " delay=" + (delay / (60 * 1000L)) + "m"); "Queuing " + getName() + " delay=" + (delay / (60 * 1000L)) + "m");

Loading…
Cancel
Save