From c43e5cca01696a45fa303e394703f14e34f129d6 Mon Sep 17 00:00:00 2001 From: kaibocai Date: Tue, 27 Feb 2024 09:08:28 -0600 Subject: [PATCH] minor refactory --- workflows/javascript/sdk/README.md | 1 - .../orderProcessingWorkflow.ts | 2 +- .../sdk/order-processor/workflowApp.ts | 22 +++++-------------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/workflows/javascript/sdk/README.md b/workflows/javascript/sdk/README.md index 786d855d4..e96ea4762 100644 --- a/workflows/javascript/sdk/README.md +++ b/workflows/javascript/sdk/README.md @@ -26,7 +26,6 @@ name: build order-process app cd ./javascript/sdk npm install npm run build -cd .. ``` diff --git a/workflows/javascript/sdk/order-processor/orderProcessingWorkflow.ts b/workflows/javascript/sdk/order-processor/orderProcessingWorkflow.ts index 6326799e3..5cc3517e5 100644 --- a/workflows/javascript/sdk/order-processor/orderProcessingWorkflow.ts +++ b/workflows/javascript/sdk/order-processor/orderProcessingWorkflow.ts @@ -10,7 +10,7 @@ export const notifyActivity = async (_: WorkflowActivityContext, orderNotificati return; }; -//Defines Verify Inventory Activity. This is used by the workflow to verify if inventory is available for the order +//Defines Reserve Inventory Activity. This is used by the workflow to verify if inventory is available for the order export const reserveInventoryActivity = async (_: WorkflowActivityContext, inventoryRequest: InventoryRequest) => { console.log(`Reserving inventory for ${inventoryRequest.requestId} of ${inventoryRequest.quantity} ${inventoryRequest.itemName}`); const result = await daprClient.state.get(storeName, inventoryRequest.itemName); diff --git a/workflows/javascript/sdk/order-processor/workflowApp.ts b/workflows/javascript/sdk/order-processor/workflowApp.ts index 9e90f4997..0a7b905e8 100644 --- a/workflows/javascript/sdk/order-processor/workflowApp.ts +++ b/workflows/javascript/sdk/order-processor/workflowApp.ts @@ -4,16 +4,8 @@ import { notifyActivity, orderProcessingWorkflow, processPaymentActivity, reques async function start() { // Update the gRPC client and worker to use a local address and port - const daprHost = "localhost"; - const daprPort = "50001"; - const workflowClient = new DaprWorkflowClient({ - daprHost, - daprPort, - }); - const workflowRuntime = new WorkflowRuntime({ - daprHost, - daprPort, - }); + const workflowClient = new DaprWorkflowClient(); + const workflowWorker = new WorkflowRuntime(); const daprClient = new DaprClient(); const storeName = "statestore"; @@ -30,7 +22,7 @@ async function start() { const order = new OrderPayload("item1", 100, 10); - workflowRuntime + workflowWorker .registerWorkflow(orderProcessingWorkflow) .registerActivity(notifyActivity) .registerActivity(reserveInventoryActivity) @@ -40,7 +32,7 @@ async function start() { // Wrap the worker startup in a try-catch block to handle any errors during startup try { - await workflowRuntime.start(); + await workflowWorker.start(); console.log("Workflow runtime started successfully"); } catch (error) { console.error("Error starting workflow runtime:", error); @@ -57,13 +49,11 @@ async function start() { console.log(`Orchestration completed! Result: ${state?.serializedOutput}`); } catch (error) { console.error("Error scheduling or waiting for orchestration:", error); + throw error; } - await workflowRuntime.stop(); + await workflowWorker.stop(); await workflowClient.stop(); - - // stop the dapr side car - process.exit(0); } start().catch((e) => {