-
Notifications
You must be signed in to change notification settings - Fork 15
Add rewind client API #123
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
Open
shreyas-gopalakrishna
wants to merge
4
commits into
main
Choose a base branch
from
shreyasg/rewind
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
65ae95e
Added support for rewinding a failed instance
shreyas-gopalakrishna f2e6fc2
Simplified test and fixed review comments
shreyas-gopalakrishna d76307c
Added test for RewindInstanceHttpAPI and addressed review comments
shreyas-gopalakrishna 55502ab
Rebased with latest main
shreyas-gopalakrishna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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
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
95 changes: 95 additions & 0 deletions
95
samples-azure-functions/src/main/java/com/functions/RewindInstance.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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.functions; | ||
|
||
import com.microsoft.azure.functions.*; | ||
import com.microsoft.azure.functions.annotation.AuthorizationLevel; | ||
import com.microsoft.azure.functions.annotation.FunctionName; | ||
import com.microsoft.azure.functions.annotation.HttpTrigger; | ||
import com.microsoft.durabletask.DurableTaskClient; | ||
import com.microsoft.durabletask.TaskOrchestrationContext; | ||
import com.microsoft.durabletask.azurefunctions.DurableActivityTrigger; | ||
import com.microsoft.durabletask.azurefunctions.DurableClientContext; | ||
import com.microsoft.durabletask.azurefunctions.DurableClientInput; | ||
import com.microsoft.durabletask.azurefunctions.DurableOrchestrationTrigger; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Azure Durable Functions with HTTP trigger - Rewind instance sample. | ||
*/ | ||
public class RewindInstance { | ||
private static int approvalFlag = 0; | ||
|
||
/** | ||
* This HTTP-triggered function starts the approval orchestration. | ||
*/ | ||
@FunctionName("ApprovalWorkflowOrchestration") | ||
public HttpResponseMessage approvalWorkflowOrchestration( | ||
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request, | ||
@DurableClientInput(name = "durableContext") DurableClientContext durableContext, | ||
final ExecutionContext context) throws InterruptedException { | ||
context.getLogger().info("Java HTTP trigger processed a request."); | ||
|
||
DurableTaskClient client = durableContext.getClient(); | ||
String instanceId = client.scheduleNewOrchestrationInstance("ApprovalWorkflow"); | ||
context.getLogger().info("Created new Java orchestration with instance ID = " + instanceId); | ||
return durableContext.createCheckStatusResponse(request, instanceId); | ||
} | ||
|
||
@FunctionName("ApprovalWorkflow") | ||
public int approvalWorkflow( | ||
@DurableOrchestrationTrigger(name = "ctx") TaskOrchestrationContext ctx) { | ||
int result = 0; | ||
result += ctx.callActivity("RequestPrimaryApproval", 1, Integer.class).await(); | ||
result += ctx.callActivity("RequestSecondaryApproval", 1, Integer.class).await(); | ||
return result; | ||
} | ||
|
||
/** | ||
* This is the activity function that gets invoked by the approval orchestration. | ||
*/ | ||
@FunctionName("RequestPrimaryApproval") | ||
public int requestPrimaryApproval( | ||
@DurableActivityTrigger(name = "name") int number, | ||
final ExecutionContext context) { | ||
return 1; | ||
} | ||
|
||
/** | ||
* This is the activity function that fails the first try and is then revived. | ||
*/ | ||
@FunctionName("RequestSecondaryApproval") | ||
public int requestSecondaryApproval( | ||
@DurableActivityTrigger(name = "name") int number, | ||
final ExecutionContext context) throws InterruptedException { | ||
return number / approvalFlag++; | ||
} | ||
|
||
/** | ||
* This HTTP-triggered function rewinds the orchestration using instanceId. | ||
*/ | ||
@FunctionName("RewindInstance") | ||
public String rewindInstance( | ||
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request, | ||
@DurableClientInput(name = "durableContext") DurableClientContext durableContext, | ||
final ExecutionContext context) { | ||
String instanceId = request.getQueryParameters().getOrDefault("instanceId", ""); | ||
String reason = "Orchestrator failed and needs to be revived."; | ||
|
||
DurableTaskClient client = durableContext.getClient(); | ||
client.rewindInstance(instanceId, reason); | ||
return "Failed orchestration instance is scheduled for rewind."; | ||
} | ||
|
||
/** | ||
* This HTTP-triggered function resets the approvalFlag variable for testing purposes. | ||
*/ | ||
@FunctionName("ResetApproval") | ||
public static HttpResponseMessage resetApproval( | ||
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) | ||
HttpRequestMessage<Optional<String>> request, | ||
final ExecutionContext context) { | ||
context.getLogger().info("ResetApproval function invoked."); | ||
approvalFlag = 0; | ||
return request.createResponseBuilder(HttpStatus.OK).body(approvalFlag).build(); | ||
} | ||
} |
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
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.