Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 18
Implement waitForCompletionOrCreateCheckStatusResponse#115
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c134410
implement waitForCompletionOrCreateCheckStatusResponse
kaibocai c22db30
update CHANGELOG
kaibocai 80fa2fd
remove comments
kaibocai 4233350
correct PR link in CHANGELOG
kaibocai e333d8b
add javadoc
kaibocai 4ccdebc
fix javadoc
kaibocai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 52 additions & 1 deletion
53 ...unctions/src/main/java/com/microsoft/durabletask/azurefunctions/DurableClientContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,12 +9,16 @@ | ||
| import com.microsoft.azure.functions.HttpStatus; | ||
| import com.microsoft.durabletask.DurableTaskClient; | ||
| import com.microsoft.durabletask.DurableTaskGrpcClientBuilder; | ||
| import com.microsoft.durabletask.OrchestrationMetadata; | ||
| import com.microsoft.durabletask.OrchestrationRuntimeStatus; | ||
| import java.io.UnsupportedEncodingException; | ||
| import java.net.MalformedURLException; | ||
| import java.net.URL; | ||
| import java.net.URLEncoder; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.time.Duration; | ||
| import java.util.concurrent.TimeoutException; | ||
| /** | ||
| * The binding value type for the {@literal @}DurableClientInput parameter. | ||
| @@ -24,6 +28,7 @@ public class DurableClientContext { | ||
| private String rpcBaseUrl; | ||
| private String taskHubName; | ||
| private String requiredQueryStringParameters; | ||
| private DurableTaskClient client; | ||
| /** | ||
| * Gets the name of the client binding's task hub. | ||
| @@ -51,9 +56,55 @@ public DurableTaskClient getClient() { | ||
| throw new IllegalStateException("The client context RPC base URL was invalid!", ex); | ||
| } | ||
| return new DurableTaskGrpcClientBuilder().port(rpcURL.getPort()).build(); | ||
| this.client = new DurableTaskGrpcClientBuilder().port(rpcURL.getPort()).build(); | ||
| return this.client; | ||
| } | ||
| /** | ||
| * Creates an HTTP response which either contains a payload of management URLs for a non-completed instance | ||
| * or contains the payload containing the output of the completed orchestration. | ||
| * <p> | ||
| * If the orchestration instance completes within the specified timeout, then the HTTP response payload will | ||
| * contains the output of the orchestration instance formatted as JSON. However, if the orchestration does not | ||
| * complete within the specified timeout, then the HTTP response will be identical to that of the | ||
| * {@link #createCheckStatusResponse(HttpRequestMessage, String)} API. | ||
| * </p> | ||
| * @param request the HTTP request that triggered the current function | ||
| * @param instanceId the unique ID of the instance to check | ||
| * @param timeout total allowed timeout for output from the durable function | ||
| * @return an HTTP response which may include a 202 and location header or a 200 with the durable function output in the response body | ||
| */ | ||
| public HttpResponseMessage waitForCompletionOrCreateCheckStatusResponse( | ||
cgillum marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| HttpRequestMessage<?> request, | ||
| String instanceId, | ||
| Duration timeout) { | ||
| if (this.client == null) { | ||
| this.client = getClient(); | ||
| } | ||
| OrchestrationMetadata orchestration; | ||
| try { | ||
| orchestration = this.client.waitForInstanceCompletion(instanceId, timeout, true); | ||
| return request.createResponseBuilder(HttpStatus.ACCEPTED) | ||
| .header("Content-Type", "application/json") | ||
| .body(orchestration.getSerializedOutput()) | ||
| .build(); | ||
| } catch (TimeoutException e) { | ||
| return createCheckStatusResponse(request, instanceId); | ||
| } | ||
| } | ||
| /** | ||
| * Creates an HTTP response that is useful for checking the status of the specified instance. | ||
| * <p> | ||
| * The payload of the returned | ||
| * @see <a href="https://learn.microsoft.com/java/api/com.microsoft.azure.functions.httpresponsemessage">HttpResponseMessage</a> | ||
| * contains HTTP API URLs that can be used to query the status of the orchestration, raise events to the orchestration, or | ||
| * terminate the orchestration. | ||
| * </p> | ||
| * @param request the HTTP request that triggered the current orchestration instance | ||
| * @param instanceId the ID of the orchestration instance to check | ||
| * @return an HTTP 202 response with a Location header and a payload containing instance control URLs | ||
| */ | ||
| public HttpResponseMessage createCheckStatusResponse(HttpRequestMessage<?> request, String instanceId) { | ||
| // TODO: To better support scenarios involving proxies or application gateways, this | ||
| // code should take the X-Forwarded-Host, X-Forwarded-Proto, and Forwarded HTTP | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.