Ensure Job factories pass the parameters to their created Jobs.

This commit is contained in:
Alan Evans 2021-03-16 10:07:21 -03:00
parent 8f26d63d6f
commit d83c3d35eb

View file

@ -14,8 +14,15 @@ class JobInstantiator {
} }
public @NonNull Job instantiate(@NonNull String jobFactoryKey, @NonNull Job.Parameters parameters, @NonNull Data data) { public @NonNull Job instantiate(@NonNull String jobFactoryKey, @NonNull Job.Parameters parameters, @NonNull Data data) {
if (jobFactories.containsKey(jobFactoryKey)) { Job.Factory factory = jobFactories.get(jobFactoryKey);
return jobFactories.get(jobFactoryKey).create(parameters, data); if (factory != null) {
Job job = factory.create(parameters, data);
if (!job.getId().equals(parameters.getId())) {
throw new AssertionError("Parameters not supplied to job during creation");
}
return job;
} else { } else {
throw new IllegalStateException("Tried to instantiate a job with key '" + jobFactoryKey + "', but no matching factory was found."); throw new IllegalStateException("Tried to instantiate a job with key '" + jobFactoryKey + "', but no matching factory was found.");
} }