minor refactory

Signed-off-by: kaibocai <kaibocai@microsoft.com>
This commit is contained in:
kaibocai 2024-02-27 09:08:28 -06:00
parent 5cfcd0e030
commit 9aecc356c7
3 changed files with 7 additions and 18 deletions

View File

@ -26,7 +26,6 @@ name: build order-process app
cd ./javascript/sdk
npm install
npm run build
cd ..
```
<!-- END_STEP -->

View File

@ -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);

View File

@ -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) => {