Add job to clean up early message receipts.

This commit is contained in:
Greyson Parrelli
2022-03-21 18:40:17 -04:00
parent 093dd7c62c
commit 142979ce93
8 changed files with 166 additions and 28 deletions

View File

@@ -242,7 +242,7 @@ public abstract class Job {
public static final class Parameters {
public static final String MIGRATION_QUEUE_KEY = "MIGRATION";
public static final int IMMORTAL = -1;
public static final long IMMORTAL = -1;
public static final int UNLIMITED = -1;
private final String id;

View File

@@ -26,6 +26,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
/**
* Manages the queue of jobs. This is the only class that should write to {@link JobStorage} to
@@ -190,6 +191,13 @@ class JobController {
notifyAll();
}
@WorkerThread
synchronized List<JobSpec> findJobs(@NonNull Predicate<JobSpec> predicate) {
return Stream.of(jobStorage.getAllJobSpecs())
.filter(predicate::test)
.toList();
}
@WorkerThread
synchronized void onRetry(@NonNull Job job, long backoffInterval) {
if (backoffInterval <= 0) {

View File

@@ -13,6 +13,7 @@ import org.signal.core.util.ThreadUtil;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.jobmanager.impl.DefaultExecutorFactory;
import org.thoughtcrime.securesms.jobmanager.impl.JsonDataSerializer;
import org.thoughtcrime.securesms.jobmanager.persistence.JobSpec;
import org.thoughtcrime.securesms.jobmanager.persistence.JobStorage;
import org.thoughtcrime.securesms.util.Debouncer;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
@@ -33,6 +34,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate;
/**
* Allows the scheduling of durable jobs that will be run as early as possible.
@@ -234,6 +236,15 @@ public class JobManager implements ConstraintObserver.Notifier {
runOnExecutor(() -> jobController.update(updater));
}
/**
* Search through the list of pending jobs and find all that match a given predicate. Note that there will always be races here, and the result you get back
* may not be valid anymore by the time you get it. Use with caution.
*/
public @NonNull List<JobSpec> find(@NonNull Predicate<JobSpec> predicate) {
waitUntilInitialized();
return jobController.findJobs(predicate);
}
/**
* Runs the specified job synchronously. Beware: All normal dependencies are respected, meaning
* you must take great care where you call this. It could take a very long time to complete!