mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-02 07:06:18 +02:00
Debug: run daily
This commit is contained in:
@@ -389,7 +389,7 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
|
||||
db.beginTransaction();
|
||||
|
||||
EntityMessage message = db.message().getMessage(mid);
|
||||
if (message == null)
|
||||
if (message == null || message.ui_hide)
|
||||
continue;
|
||||
|
||||
if (rule.matches(context, message, null, null))
|
||||
|
||||
@@ -470,10 +470,10 @@ public class EntityRule {
|
||||
|
||||
if (matched)
|
||||
EntityLog.log(context, EntityLog.Type.Rules, message,
|
||||
"Rule=" + name + ":" + order + " matched " +
|
||||
"Rule=" + name + "@" + order + " matched " +
|
||||
" needle=" + needle + " haystack=" + haystack + " regex=" + regex);
|
||||
else
|
||||
Log.i("Rule=" + name + ":" + order + " matched=" + matched +
|
||||
Log.i("Rule=" + name + "@" + order + " matched=" + matched +
|
||||
" needle=" + needle + " haystack=" + haystack + " regex=" + regex);
|
||||
return matched;
|
||||
}
|
||||
@@ -490,7 +490,8 @@ public class EntityRule {
|
||||
private boolean _execute(Context context, EntityMessage message) throws JSONException, IllegalArgumentException {
|
||||
JSONObject jaction = new JSONObject(action);
|
||||
int type = jaction.getInt("type");
|
||||
EntityLog.log(context, EntityLog.Type.Rules, message, "Executing rule=" + type + ":" + name);
|
||||
EntityLog.log(context, EntityLog.Type.Rules, message,
|
||||
"Executing rule=" + type + ":" + this.name + "@" + this.order);
|
||||
|
||||
switch (type) {
|
||||
case TYPE_NOOP:
|
||||
|
||||
@@ -1180,7 +1180,7 @@ public class FragmentFolders extends FragmentBase {
|
||||
db.beginTransaction();
|
||||
|
||||
EntityMessage message = db.message().getMessage(mid);
|
||||
if (message == null)
|
||||
if (message == null || message.ui_hide)
|
||||
continue;
|
||||
|
||||
EntityLog.log(context, "Executing rules message=" + message.id);
|
||||
|
||||
@@ -172,6 +172,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
private SwitchCompat swTest5;
|
||||
|
||||
private Button btnRepair;
|
||||
private Button btnDaily;
|
||||
private SwitchCompat swAutostart;
|
||||
private SwitchCompat swWorkManager;
|
||||
private SwitchCompat swExternalStorage;
|
||||
@@ -385,6 +386,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
swTest5 = view.findViewById(R.id.swTest5);
|
||||
|
||||
btnRepair = view.findViewById(R.id.btnRepair);
|
||||
btnDaily = view.findViewById(R.id.btnDaily);
|
||||
swAutostart = view.findViewById(R.id.swAutostart);
|
||||
swWorkManager = view.findViewById(R.id.swWorkManager);
|
||||
swExternalStorage = view.findViewById(R.id.swExternalStorage);
|
||||
@@ -1146,6 +1148,24 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
|
||||
});
|
||||
|
||||
btnDaily.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) throws Throwable {
|
||||
WorkerDailyRules.daily(context);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(FragmentOptionsMisc.this, new Bundle(), "daily");
|
||||
}
|
||||
});
|
||||
|
||||
swAutostart.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton v, boolean checked) {
|
||||
|
||||
@@ -1733,7 +1733,7 @@ public class FragmentRule extends FragmentBase {
|
||||
db.beginTransaction();
|
||||
|
||||
EntityMessage message = db.message().getMessage(mid);
|
||||
if (message == null)
|
||||
if (message == null || message.ui_hide)
|
||||
continue;
|
||||
|
||||
if (rule.matches(context, message, null, null))
|
||||
|
||||
@@ -34,9 +34,12 @@ import androidx.work.WorkerParameters;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class WorkerDailyRules extends Worker {
|
||||
private static final Semaphore semaphore = new Semaphore(1);
|
||||
|
||||
public WorkerDailyRules(@NonNull Context context, @NonNull WorkerParameters workerParams) {
|
||||
super(context, workerParams);
|
||||
Log.i("Instance " + getName());
|
||||
@@ -47,11 +50,21 @@ public class WorkerDailyRules extends Worker {
|
||||
public Result doWork() {
|
||||
Thread.currentThread().setPriority(THREAD_PRIORITY_BACKGROUND);
|
||||
|
||||
final Context context = getApplicationContext();
|
||||
try {
|
||||
daily(getApplicationContext());
|
||||
return Result.success();
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
return Result.failure();
|
||||
}
|
||||
}
|
||||
|
||||
static void daily(Context context) {
|
||||
DB db = DB.getInstance(context);
|
||||
try {
|
||||
semaphore.acquire();
|
||||
EntityLog.log(context, EntityLog.Type.Rules, "Running daily rules");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
List<EntityAccount> accounts = db.account().getSynchronizingAccounts(null);
|
||||
for (EntityAccount account : accounts) {
|
||||
List<EntityFolder> folders = db.folder().getFolders(account.id, false, false);
|
||||
@@ -65,7 +78,7 @@ public class WorkerDailyRules extends Worker {
|
||||
for (long mid : mids)
|
||||
try {
|
||||
EntityMessage message = db.message().getMessage(mid);
|
||||
if (message == null)
|
||||
if (message == null || message.ui_hide)
|
||||
continue;
|
||||
count++;
|
||||
|
||||
@@ -102,12 +115,11 @@ public class WorkerDailyRules extends Worker {
|
||||
"Executed " + count + " daily rules for " + account.name + "/" + folder.name);
|
||||
}
|
||||
}
|
||||
|
||||
EntityLog.log(context, EntityLog.Type.Rules, "Completed daily rules");
|
||||
return Result.success();
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
return Result.failure();
|
||||
} finally {
|
||||
semaphore.release();
|
||||
EntityLog.log(context, EntityLog.Type.Rules, "Completed daily rules");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,9 +137,6 @@ public class WorkerDailyRules extends Worker {
|
||||
cal.add(Calendar.DAY_OF_MONTH, 1);
|
||||
delay = cal.getTimeInMillis() - delay;
|
||||
|
||||
if (BuildConfig.DEBUG)
|
||||
delay = 0;
|
||||
|
||||
Log.i("Queuing " + getName() + " delay=" + (delay / (60 * 1000L)) + "m");
|
||||
PeriodicWorkRequest.Builder builder =
|
||||
new PeriodicWorkRequest.Builder(WorkerDailyRules.class, 1, TimeUnit.DAYS)
|
||||
|
||||
Reference in New Issue
Block a user