Cancel typing jobs when you send a group message.

This commit is contained in:
Greyson Parrelli
2020-06-12 07:06:20 -07:00
committed by GitHub
parent 8891b6c930
commit 3fad007ae0
8 changed files with 118 additions and 19 deletions

View File

@@ -23,6 +23,7 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
@@ -150,6 +151,14 @@ class JobController {
}
}
@WorkerThread
synchronized void cancelAllInQueue(@NonNull String queue) {
Stream.of(runningJobs.values())
.filter(j -> Objects.equals(j.getParameters().getQueue(), queue))
.map(Job::getId)
.forEach(this::cancelJob);
}
@WorkerThread
synchronized void onRetry(@NonNull Job job) {
int nextRunAttempt = job.getRunAttempt() + 1;

View File

@@ -198,6 +198,13 @@ public class JobManager implements ConstraintObserver.Notifier {
executor.execute(() -> jobController.cancelJob(id));
}
/**
* Cancels all jobs in the specified queue. See {@link #cancel(String)} for details.
*/
public void cancelAllInQueue(@NonNull String queue) {
executor.execute(() -> jobController.cancelAllInQueue(queue));
}
/**
* 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!