Skip to content

Commit

Permalink
minor refactory
Browse files Browse the repository at this point in the history
  • Loading branch information
kaibocai committed Feb 27, 2024
1 parent 5cfcd0e commit c43e5cc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
1 change: 0 additions & 1 deletion workflows/javascript/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ name: build order-process app
cd ./javascript/sdk
npm install
npm run build
cd ..
```

<!-- END_STEP -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 6 additions & 16 deletions workflows/javascript/sdk/order-processor/workflowApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -30,7 +22,7 @@ async function start() {

const order = new OrderPayload("item1", 100, 10);

workflowRuntime
workflowWorker
.registerWorkflow(orderProcessingWorkflow)
.registerActivity(notifyActivity)
.registerActivity(reserveInventoryActivity)
Expand All @@ -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);
Expand All @@ -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) => {
Expand Down

0 comments on commit c43e5cc

Please sign in to comment.