Skip to content

Commit

Permalink
Ensure Job factories pass the parameters to their created Jobs.
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-signal committed Mar 16, 2021
1 parent 8f26d63 commit d83c3d3
Showing 1 changed file with 9 additions and 2 deletions.
Expand Up @@ -14,8 +14,15 @@ class JobInstantiator {
}

public @NonNull Job instantiate(@NonNull String jobFactoryKey, @NonNull Job.Parameters parameters, @NonNull Data data) {
if (jobFactories.containsKey(jobFactoryKey)) {
return jobFactories.get(jobFactoryKey).create(parameters, data);
Job.Factory factory = jobFactories.get(jobFactoryKey);
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 {
throw new IllegalStateException("Tried to instantiate a job with key '" + jobFactoryKey + "', but no matching factory was found.");
}
Expand Down

0 comments on commit d83c3d3

Please sign in to comment.