-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Add Async support #204
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
base: main
Are you sure you want to change the base?
Conversation
:java_duke: JaCoCo coverage report
|
|
||||||||||||||
|
HTML test reports are available as workflow artifacts (zipped HTML). • Download: Artifacts for this run |
|
No worries. Enjoy the weekend! |
...ing-serve/docling-serve-client/src/main/java/ai/docling/serve/client/DoclingServeClient.java
Outdated
Show resolved
Hide resolved
docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/DoclingServeApi.java
Outdated
Show resolved
Hide resolved
edeandrea
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made a few general comments about how I envisioned the async to work. I was thinking that we would return CompletableFuture objects in the async operations. This would solve a number of issues, but the biggest is that the current implementation polls on the same thread that that it executes the task from. This could lead to deadlock in systems that are not thread-per-request.
Plus other downstream implementors may want to use virtual threads or some other threading mechanism.
Sticking to CompletableFuture allows more more customization by downstream frameworks.
@ThomasVitale thoughts?
.../docling-serve-api/src/main/java/ai/docling/serve/api/convert/response/ConversionStatus.java
Outdated
Show resolved
Hide resolved
docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/DoclingServeApi.java
Outdated
Show resolved
Hide resolved
...docling-serve-client/src/main/java/ai/docling/serve/client/operations/ConvertOperations.java
Outdated
Show resolved
Hide resolved
|
I proposed a new solution with CompletableFuture. If it works for all I'll change to Duration the missing field and add the section to whats new. |
edeandrea
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comments on the DoclingServeConvertApi
I think we only need a single method:
CompletableFuture<ConvertDocumentResponse> convertSource(ConvertDocumentRequest request);The implementation of that method would handle all the necessary polling to return the completed future once its complete.
At least that was my vision. Thoughts @ThomasVitale ?
docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/DoclingServeConvertApi.java
Outdated
Show resolved
Hide resolved
docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/DoclingServeConvertApi.java
Outdated
Show resolved
Hide resolved
docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/DoclingServeConvertApi.java
Outdated
Show resolved
Hide resolved
|
HTML test reports are available as workflow artifacts (zipped HTML). • Download: Artifacts for this run |
docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/DoclingServeConvertApi.java
Outdated
Show resolved
Hide resolved
docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/DoclingServeConvertApi.java
Outdated
Show resolved
Hide resolved
|
I guess I'll need to tackle this from scratch again. I was porting the logic coming from Camel, so I could have miss some parts of the API on this side. I'll rework on this next week. |
|
I think it's actually simpler than you realize. All the polling apis are already there, plus you already have the logic for polling based on a duration. It's just providing a method which ties everything together. |
02759ae to
33f4cea
Compare
|
It should be better now. I spent an hour or so looking at the API a bit deeper. |
|
HTML test reports are available as workflow artifacts (zipped HTML). • Download: Artifacts for this run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I hope you don't mind but I made a few tweaks. CompletableFuture has built-in polling capabilities, so you don't need to create your own polling executor. (see f5033ac)
I also added the polling properties to the DoclingServeApi builder so it can be configured by any client implementing the api.
@oscerd @ThomasVitale Have a look and let me know what you think.
Looks really better know. I think I should revisit a bit the Async API for Java, it's been a while.. thanks for completing the PR. +1 from my side. |
Its been a while for me too, at least with "vanilla" Java (I'm so used to Mutiny/etc). Was a good learning exercise for me too! |
|
HTML test reports are available as workflow artifacts (zipped HTML). • Download: Artifacts for this run |
|
I'll review the new changes later today |
Signed-off-by: Andrea Cosentino <[email protected]>
Simplified the async polling logic in `ConvertOperations` by replacing the custom scheduler with `CompletionStage` chaining. Improved task status handling by centralizing logic for success, failure, and retry behavior. Cleaned up imports and adjusted tests to maintain consistency with updated logic. Signed-off-by: Eric Deandrea <[email protected]>
|
HTML test reports are available as workflow artifacts (zipped HTML). • Download: Artifacts for this run |
| * {@link CompletableFuture} that completes when the conversion is done. | ||
| * | ||
| * <p>This method starts the conversion, polls the status in the background, and completes | ||
| * the future with the result when the conversion finishes. The polling happens on a separate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should remove this final sentence as it's up to the framework/client to configure how the polling happens (platform thread, virtual thread, some other mechanism provided by Mutiny/Reactor). Thoughts?
|
Looks good to me! Just left a couple of comments about the docs. I like the clean API returning |
This should fix #127