Add username sync job to be run after new registrations.

This commit is contained in:
Alex Hart
2023-03-06 14:23:30 -04:00
parent 877a62b809
commit e222f96310
7 changed files with 104 additions and 4 deletions

View File

@@ -497,6 +497,34 @@ public class JobManager implements ConstraintObserver.Notifier {
enqueue();
}
public Optional<JobTracker.JobState> enqueueAndBlockUntilCompletion(long timeout) {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<JobTracker.JobState> resultState = new AtomicReference<>();
JobTracker.JobListener listener = new JobTracker.JobListener() {
@Override
public void onStateChanged(@NonNull Job job, @NonNull JobTracker.JobState jobState) {
if (jobState.isComplete()) {
jobManager.removeListener(this);
resultState.set(jobState);
latch.countDown();
}
}
};
enqueue(listener);
try {
if (!latch.await(timeout, TimeUnit.MILLISECONDS)) {
return Optional.empty();
}
} catch (InterruptedException e) {
Log.w(TAG, "Interrupted during enqueueSynchronously()", e);
return Optional.empty();
}
return Optional.ofNullable(resultState.get());
}
@VisibleForTesting
public List<List<Job>> getJobListChain() {
return jobs;