mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Handle 428 rate limiting.
This commit is contained in:
@@ -176,6 +176,23 @@ class JobController {
|
||||
.forEach(this::cancelJob);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
synchronized void update(@NonNull JobUpdater updater) {
|
||||
List<JobSpec> allJobs = jobStorage.getAllJobSpecs();
|
||||
List<JobSpec> updatedJobs = new LinkedList<>();
|
||||
|
||||
for (JobSpec job : allJobs) {
|
||||
JobSpec updated = updater.update(job, dataSerializer);
|
||||
if (updated != job) {
|
||||
updatedJobs.add(updated);
|
||||
}
|
||||
}
|
||||
|
||||
jobStorage.updateJobs(updatedJobs);
|
||||
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
synchronized void onRetry(@NonNull Job job, long backoffInterval) {
|
||||
if (backoffInterval <= 0) {
|
||||
|
||||
@@ -223,6 +223,15 @@ public class JobManager implements ConstraintObserver.Notifier {
|
||||
runOnExecutor(() -> jobController.cancelAllInQueue(queue));
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an arbitrary update on enqueued jobs. Will not apply to jobs that are already running.
|
||||
* You shouldn't use this if you can help it. You give yourself an opportunity to really screw
|
||||
* things up.
|
||||
*/
|
||||
public void update(@NonNull JobUpdater updater) {
|
||||
runOnExecutor(() -> jobController.update(updater));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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!
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.thoughtcrime.securesms.jobmanager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.jobmanager.persistence.JobSpec;
|
||||
|
||||
public interface JobUpdater {
|
||||
/**
|
||||
* Called for each enqueued job, giving you an opportunity to update each one.
|
||||
*
|
||||
* @param jobSpec An object representing data about an enqueued job.
|
||||
* @param serializer An object that can be used to serialize/deserialize data if necessary for
|
||||
* your update.
|
||||
*
|
||||
* @return The updated JobSpec you want persisted. If you do not wish to make an update, return
|
||||
* the literal same JobSpec instance you were provided.
|
||||
*/
|
||||
@NonNull JobSpec update(@NonNull JobSpec jobSpec, @NonNull Data.Serializer serializer);
|
||||
}
|
||||
@@ -49,6 +49,10 @@ public final class JobSpec {
|
||||
this.memoryOnly = memoryOnly;
|
||||
}
|
||||
|
||||
public @NonNull JobSpec withNextRunAttemptTime(long updated) {
|
||||
return new JobSpec(id, factoryKey, queueKey, createTime, updated, runAttempt, maxAttempts, lifespan, serializedData, serializedInputData, isRunning, memoryOnly);
|
||||
}
|
||||
|
||||
public @NonNull String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user