use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by WhisperSystems.
the class FastJobStorage method updateJobAfterRetry.
@Override
public synchronized void updateJobAfterRetry(@NonNull String id, boolean isRunning, int runAttempt, long nextRunAttemptTime, @NonNull String serializedData) {
JobSpec job = getJobById(id);
if (job == null || !job.isMemoryOnly()) {
jobDatabase.updateJobAfterRetry(id, isRunning, runAttempt, nextRunAttemptTime, serializedData);
}
ListIterator<JobSpec> iter = jobs.listIterator();
while (iter.hasNext()) {
JobSpec existing = iter.next();
if (existing.getId().equals(id)) {
JobSpec updated = new JobSpec(existing.getId(), existing.getFactoryKey(), existing.getQueueKey(), existing.getCreateTime(), nextRunAttemptTime, runAttempt, existing.getMaxAttempts(), existing.getLifespan(), serializedData, existing.getSerializedInputData(), isRunning, existing.isMemoryOnly());
iter.set(updated);
}
}
}
use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by WhisperSystems.
the class FastJobStorage method init.
@Override
public synchronized void init() {
List<JobSpec> jobSpecs = jobDatabase.getAllJobSpecs();
List<ConstraintSpec> constraintSpecs = jobDatabase.getAllConstraintSpecs();
List<DependencySpec> dependencySpecs = jobDatabase.getAllDependencySpecs();
jobs.addAll(jobSpecs);
for (ConstraintSpec constraintSpec : constraintSpecs) {
List<ConstraintSpec> jobConstraints = Util.getOrDefault(constraintsByJobId, constraintSpec.getJobSpecId(), new LinkedList<>());
jobConstraints.add(constraintSpec);
constraintsByJobId.put(constraintSpec.getJobSpecId(), jobConstraints);
}
for (DependencySpec dependencySpec : dependencySpecs) {
List<DependencySpec> jobDependencies = Util.getOrDefault(dependenciesByJobId, dependencySpec.getJobId(), new LinkedList<>());
jobDependencies.add(dependencySpec);
dependenciesByJobId.put(dependencySpec.getJobId(), jobDependencies);
}
}
use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by WhisperSystems.
the class JobController method submitJobWithExistingDependencies.
@WorkerThread
synchronized void submitJobWithExistingDependencies(@NonNull Job job, @NonNull Collection<String> dependsOn, @Nullable String dependsOnQueue) {
List<List<Job>> chain = Collections.singletonList(Collections.singletonList(job));
if (chainExceedsMaximumInstances(chain)) {
jobTracker.onStateChange(job, JobTracker.JobState.IGNORED);
Log.w(TAG, JobLogger.format(job, "Already at the max instance count. Factory limit: " + job.getParameters().getMaxInstancesForFactory() + ", Queue limit: " + job.getParameters().getMaxInstancesForQueue() + ". Skipping."));
return;
}
Set<String> allDependsOn = new HashSet<>(dependsOn);
Set<String> aliveDependsOn = Stream.of(dependsOn).filter(id -> jobStorage.getJobSpec(id) != null).collect(Collectors.toSet());
if (dependsOnQueue != null) {
List<String> inQueue = Stream.of(jobStorage.getJobsInQueue(dependsOnQueue)).map(JobSpec::getId).toList();
allDependsOn.addAll(inQueue);
aliveDependsOn.addAll(inQueue);
}
if (jobTracker.haveAnyFailed(allDependsOn)) {
Log.w(TAG, "This job depends on a job that failed! Failing this job immediately.");
List<Job> dependents = onFailure(job);
job.setContext(application);
job.onFailure();
Stream.of(dependents).forEach(Job::onFailure);
return;
}
FullSpec fullSpec = buildFullSpec(job, aliveDependsOn);
jobStorage.insertJobs(Collections.singletonList(fullSpec));
scheduleJobs(Collections.singletonList(job));
triggerOnSubmit(chain);
notifyAll();
}
use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by WhisperSystems.
the class FastJobStorageTest method updateAllJobsToBePending_allArePending.
@Test
public void updateAllJobsToBePending_allArePending() {
FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 1, 1, 1, 1, 1, EMPTY_DATA, null, true, false), Collections.emptyList(), Collections.emptyList());
FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 1, 1, 1, 1, 1, EMPTY_DATA, null, true, false), Collections.emptyList(), Collections.emptyList());
FastJobStorage subject = new FastJobStorage(fixedDataDatabase(Arrays.asList(fullSpec1, fullSpec2)));
subject.init();
subject.updateAllJobsToBePending();
assertFalse(subject.getJobSpec("1").isRunning());
assertFalse(subject.getJobSpec("2").isRunning());
}
use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by WhisperSystems.
the class FastJobStorageTest method updateJobs_writesToDatabase.
@Test
public void updateJobs_writesToDatabase() {
JobDatabase database = fixedDataDatabase(DataSet1.FULL_SPECS);
FastJobStorage subject = new FastJobStorage(database);
List<JobSpec> jobs = Collections.singletonList(new JobSpec("id1", "f1", null, 1, 1, 1, 1, 1, EMPTY_DATA, null, false, false));
subject.init();
subject.updateJobs(jobs);
verify(database).updateJobs(jobs);
}
Aggregations