Skip to content

Commit

Permalink
rename DistributionActivity to DelieveryActivity
Browse files Browse the repository at this point in the history
Signed-off-by: Sky Ao <[email protected]>
  • Loading branch information
skyao committed Oct 31, 2023
1 parent 7df625f commit 6c8076c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import com.microsoft.durabletask.OrchestratorBlockedException;

import io.dapr.quickstarts.saga.activities.DistributionActivity;
import io.dapr.quickstarts.saga.activities.DeliveryActivity;
import io.dapr.quickstarts.saga.activities.NotifyActivity;
import io.dapr.quickstarts.saga.activities.ProcessPaymentActivity;
import io.dapr.quickstarts.saga.activities.RequestApprovalActivity;
Expand Down Expand Up @@ -111,8 +111,8 @@ public WorkflowStub create() {
// Update Inventory activity is succeed, register for compensation
saga.registerCompensation(UpdateInventoryActivity.class.getName(), inventoryRequest, inventoryResult);

// step6: distribution (allways be failed to trigger compensation)
ctx.callActivity(DistributionActivity.class.getName(), null).await();
// step6: delevery (allways be failed to trigger compensation)
ctx.callActivity(DeliveryActivity.class.getName(), null).await();

// step7: Let user know their order was processed(won't be executed if step6
// failed)
Expand All @@ -124,6 +124,7 @@ public WorkflowStub create() {
orderResult.setProcessed(true);
ctx.complete(orderResult);
} catch (OrchestratorBlockedException e) {
//TODO: try to improve design and remove this exception catch
throw e;
} catch (Exception e) {
orderResult.setCompensated(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import io.dapr.client.DaprClient;
import io.dapr.client.DaprClientBuilder;
import io.dapr.quickstarts.saga.activities.DistributionActivity;
import io.dapr.quickstarts.saga.activities.DeliveryActivity;
import io.dapr.quickstarts.saga.activities.NotifyActivity;
import io.dapr.quickstarts.saga.activities.ProcessPaymentActivity;
import io.dapr.quickstarts.saga.activities.RequestApprovalActivity;
Expand Down Expand Up @@ -54,7 +54,7 @@ public static void main(String[] args) throws Exception {
builder.registerActivity(RequestApprovalActivity.class);
builder.registerActivity(ReserveInventoryActivity.class);
builder.registerActivity(UpdateInventoryActivity.class);
builder.registerActivity(DistributionActivity.class);
builder.registerActivity(DeliveryActivity.class);

// Build and then start the workflow runtime pulling and executing tasks
try (WorkflowRuntime runtime = builder.build()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import io.dapr.workflows.runtime.WorkflowActivity;
import io.dapr.workflows.runtime.WorkflowActivityContext;

public class DistributionActivity implements WorkflowActivity {
private static Logger logger = LoggerFactory.getLogger(DistributionActivity.class);
public class DeliveryActivity implements WorkflowActivity {
private static Logger logger = LoggerFactory.getLogger(DeliveryActivity.class);

@Override
public Object run(WorkflowActivityContext ctx) {
// in this quickstart, we assume that the distribution will be failed
// So that the workflow will be compensated
logger.info("Distribution failed");
// in this quickstart, we assume that the Delivery will be failed
// So that the workflow will be failed and compensated
logger.info("Delivery failed");
throw new RuntimeException("Distribution failed");
}

Expand Down

0 comments on commit 6c8076c

Please sign in to comment.