New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Jobs are scheduled with the same parameters even though different parameters are provided #335
Comments
I'm quite sure this is because of the jobdetails caching which is too aggressive. In the configuration, try using Can you report back if this solves your problem? |
This indeed seems to have solved the issue. If this is expected behavior it might be good idea to add a hint to the docs. Thank you really much for the fast response and let me know if we can help finding the issue with further tests! |
No worries, happy it is working again and glad that I can help a sponsor! You could enable caching probably again by extracting the UUID generation outside the enqueue method. Let me know how that works out. |
In the actual setup the uuid belongs to a database model and is already generated outside the lambda. Before the enqueue call i'm assigning it to a local variable to make it effectively final. |
1 similar comment
In the actual setup the uuid belongs to a database model and is already generated outside the lambda. Before the enqueue call i'm assigning it to a local variable to make it effectively final. |
Could you share that piece of code? |
In the actual setup the uuid belongs to a database model and is already generated outside the lambda. Before the enqueue call i'm assigning it to a local variable to make it effectively final. |
Unfortunately I can't share the exact code but that's basically it:
The save method is coming from an abstract class that the model class inherits. This is coming our own framework's orm (https://github.com/JavaWebStack/orm) in case thats important. |
Hi @JanHolger , I'll need some help from you to reproduce this. I've tried to do so, see https://github.com/jobrunr/jobrunr/blob/bugfix/github-issue335/core/src/test/java/org/jobrunr/scheduling/BackgroundJobByJobLambdaTest.java#L485-L492. Yet, I see 2 different UUID's logged and I've almost copied the code from you above. Can you shed some light on what you guys are doing? |
Sorry that I took so long to reply. Your test is generating the UUID in the lambda so it will of course be different. Our code is more like the one that I shared in my last comment. I've copied our code again and stripped and replaced all names because it's internal code. The actual controller method looks something like this but there are a lot more checks and multiple related entities involved: @Post
public Response create(Exchange exchange, SomeCreateRequest request) {
// Searching for related objects in the database and returning a 4xx Response in case they are invalid/missing
RelatedModel relatedObject = Repo.get(RelatedModel.class).get(request.getRelatedId());
if(relatedObject == null)
return Response.error(404, "relatedModel.notFound");
// Creating the instance of our entity
SomeModel someObject = new SomeModel()
.setName(request.getName());
someObject.save(); // This generates the id and persists the object to the database
// Assign the related entity to the newly created one
relatedObject.setSomeId(someObject.getId()).save();
// Create a field to store the uuid in because serializing the entire entity object would be pointless
UUID id = someObject.getId();
// Enqueue a job for the entity
BackgroundJob.enqueue(() -> new SomeJob().run(id));
return Response.resource(SomeResource.class, someObject); // Return the entity mapped to SomeResource
} I can try to find some time tomorrow to reproduce it in an example application that I can share. |
If you could setup an example project that reproduces this, that would be great! I also have generated the uuid outside the lambda and that worked also. It would be great if you could setup a repo that reproduces it. |
Hello! If correctly understood by the example of the author. That can be repeated in this way: void testGithubIssue335() {
UUID uuid1 = UUID.randomUUID();
System.out.println("UUID1: " + uuid1);
UUID uuid2 = UUID.randomUUID();
System.out.println("UUID2: "+ uuid2);
setJob(uuid1);
setJob(uuid2);
}
private void setJob(UUID uuid) {
BackgroundJob.enqueue(() -> new TestService.GithubIssue335().run(uuid));
} P.S. Sorry. I understand English badly. Used google translator |
Thanks, I was able to reproduce it. |
Fixed |
Are you running the latest version of JobRunr?
Yes
Describe the bug
We have a Job class with a run method that takes a uuid as it's parameter. We then enqueue the jobs using the following call:
This works perfectly fine for the first run in the process but if we call this multiple times with different id's it creates the jobs with the first id over and over. We've validated that our id's are indeed different each time so there has to be a problem in JobRunr or the way we are using it.
As we are not running in Spring, we are providing a pretty simple activator but from what I understand this doesn't really matter as our job class doesn't contain any fields and the dashboard also shows the wrong id so they are already getting scheduled with the wrong parameters.
Environment
I'm using JobRunr version: 4.0.6
I'm running on JRE / JDK (e.g. OpenJDK 1.8.0_292): OpenJDK 1.8.0_302
I'm using the following StorageProvider (e.g. Oracle / MongoDB / ...): MariaDB
How to Reproduce
Expected behavior
The job should get scheduled with 2 different id's.
The text was updated successfully, but these errors were encountered: