Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public TaskOrchestratorResult execute(List<HistoryEvent> pastEvents, List<Histor
context.fail(new FailureDetails(e));
}

if (context.continuedAsNew || (completed && context.pendingActions.isEmpty() && !context.waitingForEvents())) {
if ((context.continuedAsNew && !context.isComplete) || (completed && context.pendingActions.isEmpty() && !context.waitingForEvents())) {
// There are no further actions for the orchestrator to take so auto-complete the orchestration.
context.complete(null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.functions;

import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.HttpMethod;
import com.microsoft.azure.functions.HttpRequestMessage;
import com.microsoft.azure.functions.HttpResponseMessage;
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.DurableClientContext;
import com.microsoft.durabletask.azurefunctions.DurableClientInput;
import com.microsoft.durabletask.azurefunctions.DurableOrchestrationTrigger;

import java.time.Duration;
import java.util.Optional;

public class ContinueAsNew {
@FunctionName("ContinueAsNew")
public HttpResponseMessage continueAsNew(
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
@DurableClientInput(name = "durableContext") DurableClientContext durableContext,
final ExecutionContext context) {
context.getLogger().info("Java HTTP trigger processed a request.");

DurableTaskClient client = durableContext.getClient();
String instanceId = client.scheduleNewOrchestrationInstance("EternalOrchestrator");
context.getLogger().info("Created new Java orchestration with instance ID = " + instanceId);
return durableContext.createCheckStatusResponse(request, instanceId);
}

@FunctionName("EternalOrchestrator")
public void eternalOrchestrator(@DurableOrchestrationTrigger(name = "runtimeState") TaskOrchestrationContext ctx)
{
System.out.println("Processing stuff...");
ctx.createTimer(Duration.ofSeconds(2)).await();
ctx.continueAsNew(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@

@Tag("e2e")
public class EndToEndTests {
private static final String hostHealthPingPath = "/admin/host/ping";
private static final String startOrchestrationPath = "/api/StartOrchestration";

@Order(1)
@Test
public void setupHost() {
String hostHealthPingPath = "/admin/host/ping";
post(hostHealthPingPath).then().statusCode(200);
}

@Test
public void basicChain() throws InterruptedException {
String startOrchestrationPath = "/api/StartOrchestration";
Response response = post(startOrchestrationPath);
JsonPath jsonPath = response.jsonPath();
String statusQueryGetUri = jsonPath.get("statusQueryGetUri");
Expand All @@ -36,4 +36,27 @@ public void basicChain() throws InterruptedException {
}
assertEquals("Completed", runTimeStatus);
}


@Test
public void continueAsNew() throws InterruptedException {
String startOrchestrationPath = "api/ContinueAsNew";
Response response = post(startOrchestrationPath);
JsonPath jsonPath = response.jsonPath();
String statusQueryGetUri = jsonPath.get("statusQueryGetUri");
String runTimeStatus;
//assert that the orchestration is always running.
for (int i = 0; i < 10; i++) {
Response statusResponse = get(statusQueryGetUri);
runTimeStatus = statusResponse.jsonPath().get("runtimeStatus");
assertEquals("Running", runTimeStatus);
Thread.sleep(1000);
}
String terminatePostUri = jsonPath.get("terminatePostUri");
post(terminatePostUri, "Terminated the test");
Thread.sleep(1000);
Response statusResponse = get(statusQueryGetUri);
runTimeStatus = statusResponse.jsonPath().get("runtimeStatus");
assertEquals("Terminated", runTimeStatus);
}
}