Debug: run daily

pull/210/head
M66B 3 years ago
parent 34c878c7ec
commit fc2ab4542e

@ -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)

@ -1084,6 +1084,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCaptionDebug" />
<Button
android:id="@+id/btnDaily"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:drawableEnd="@drawable/twotone_hourglass_top_24"
android:drawablePadding="6dp"
android:text="@string/title_advanced_daily"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnRepair" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAutostart"
android:layout_width="0dp"
@ -1093,7 +1105,7 @@
android:text="@string/title_advanced_autostart"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnRepair"
app:layout_constraintTop_toBottomOf="@id/btnDaily"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

@ -794,6 +794,7 @@
<string name="title_advanced_test4" translatable="false">Test #4</string>
<string name="title_advanced_test5" translatable="false">Test #5</string>
<string name="title_advanced_repair" translatable="false">Repair</string>
<string name="title_advanced_daily" translatable="false">Daily</string>
<string name="title_advanced_autostart" translatable="false">Autostart app</string>
<string name="title_advanced_work_manager" translatable="false">Initialize work manager</string>
<string name="title_advanced_external_storage" translatable="false">Use external storage</string>

Loading…
Cancel
Save