dapr / js-sdk

Dapr SDK for Javascript
Apache License 2.0
192 stars 80 forks source link

workflow example management missing components folder #569

Closed sce9sc closed 3 months ago

sce9sc commented 6 months ago

Components folder is missing from the Example in workflow/management

Also I find it difficult to undestand how can I call the sequence example in authoring from the management example.

Any help is much appreciated.

Thanks

shubham1172 commented 6 months ago

Thanks @sce9sc for finding this issue, we can reuse the same components from https://github.com/dapr/js-sdk/tree/main/examples/workflow/authoring/components (an actor state store is all that's required). Please feel free to send in a PR to fix it!

sce9sc commented 6 months ago

I will be very happy to contribute and fix any issues as well as creating more examples . Can you also explain to me why I cannot call the sequence workflow by changing the name like so

  const instanceId = await client.workflow.start("sequence");

What is the diffenece between DaprWorkflowClient and client.workflow ?

shubham1172 commented 6 months ago

Can you also explain to me why I cannot call the sequence workflow by changing the name like so

What error message do you get?

What is the diffenece between DaprWorkflowClient and client.workflow ?

In management code client.workflow, points to the IClientWorkflow in DaprClient. This can be used for management purpose, as defined by https://github.com/dapr/js-sdk/blob/main/src/interfaces/Client/IClientWorkflow.ts#L16. If you look at the implementation, it does so by making HTTP calls to the Dapr sidecar https://github.com/dapr/js-sdk/blob/main/src/implementation/Client/HTTPClient/workflow.ts.

DaprWorkflowClient does something similar, using gRPC https://github.com/dapr/js-sdk/blob/main/src/workflow/client/DaprWorkflowClient.ts#L27, by talking to the underlying TaskHub client.

Now that I think more about it, I think we should converge these to avoid confusion. What are your thoughts @DeepanshuA?

sce9sc commented 6 months ago

I get

Error starting workflow instance: {"error":"Bad Request","error_msg":"{\"errorCode\":\"ERR_WORKFLOW_COMPONENT_NOT_FOUND\",\"message\":\"workflow component 'dapr' does not exist\"}","status":400}```

I am not sure that I have configured it correctly though .

sce9sc commented 6 months ago

I managed to call the workflow using Post

POST http://localhost:50080/v1.0-beta1/workflows/dapr/sequence/start HTTP/1.1
content-type: application/json
apr-app-id: "activity-sequence-workflow"
shubham1172 commented 6 months ago

That should translate to the same call being made here https://github.com/dapr/js-sdk/blob/5c2b40ac94b50f6a5bdb32008f6a47da69946d95/src/implementation/Client/HTTPClient/workflow.ts#L99

sce9sc commented 6 months ago

Yes you are correct . Calling directly the dapr instance is working using the above Post request . Spiining app a new instance with only the client and sending the same request using :

  const instanceId = await client.workflow.start("sequence");

does not . and I get

  "errorCode": "ERR_WORKFLOW_COMPONENT_NOT_FOUND",
  "message": "workflow component 'dapr' does not exist"

I 've even started the dapr sidecar with no client and send the same POST request to the new DAps instance and it did not work. Should it ?? I think I am missing something but I cant figure it out yet.

Should the 2 dapr instance be able to communicate with each other ? And by making a post to one it will call ther other that has the workflow?

shubham1172 commented 6 months ago

Both the applications (1) where you register the workflow and (2) where you manage the workflow with commands like start, purge, terminate, etc., should be talking to the same Dapr sidecar. This is an example where it is happening in the same application with .NET https://github.com/dapr/quickstarts/blob/master/workflows/csharp/sdk/order-processor/Program.cs#L54, you can also do it with multiple applications with a single Dapr instance.

sce9sc commented 6 months ago

From what you mentioned, in order to run a workflow we need to: (1) have a Pod (or multi) with a dapr instance + app for registering a workflow together with the invocation capability that will trigger the workflow. 2) In order to run a workflow a different Pod will receive a request and make an invocation to the other Pod.

This means that Pod (1) will have an application that will have DaprServer instantiated together with DaprWorkflowClient and WorkflowRuntime and DaprClient if you want to have management also. Or on the same pod run One Dapr instance with 2 Apps -> 1) with invocation( DaprServer, DaprWorkflowClient ) + workflow registration (WorkflowRuntime) 2) with invocation( DaprServer, DaprClient ) for management

The examples are showing how a single Dapr instance together with an application that registers the flows and at the same time the same app runs the flows.

The net example is also showing that is using a single client to start and wait for the flow to finish, whereas the js-sdk there are 2 options .

    const id = await workflowClient.scheduleNewWorkflow(sequence);
  OR
    const id = await client.workflow.start("sequence");

Also as it shown the scheduleNewWorkflow needs TWorkflow and workflow.start needs only the name of the workflow.

DeepanshuA commented 6 months ago

Can you also explain to me why I cannot call the sequence workflow by changing the name like so

What error message do you get?

What is the diffenece between DaprWorkflowClient and client.workflow ?

In management code client.workflow, points to the IClientWorkflow in DaprClient. This can be used for management purpose, as defined by https://github.com/dapr/js-sdk/blob/main/src/interfaces/Client/IClientWorkflow.ts#L16. If you look at the implementation, it does so by making HTTP calls to the Dapr sidecar https://github.com/dapr/js-sdk/blob/main/src/implementation/Client/HTTPClient/workflow.ts.

DaprWorkflowClient does something similar, using gRPC https://github.com/dapr/js-sdk/blob/main/src/workflow/client/DaprWorkflowClient.ts#L27, by talking to the underlying TaskHub client.

Now that I think more about it, I think we should converge these to avoid confusion. What are your thoughts @DeepanshuA?

We can keep the components folderinsideworkflow, parallel toauthoringandmanagement`. Yeah, we can think to converge the two as well. Or may be create a better documentation, where-in we explicitly specify what is needed for what and which one to use in which scenario.

dapr-bot commented 4 months ago

This issue has been automatically marked as stale because it has not had activity in the last 60 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue, help wanted or triaged/resolved) or other activity occurs. Thank you for your contributions.

dapr-bot commented 3 months ago

This issue has been automatically closed because it has not had activity in the last 67 days. If this issue is still valid, please ping a maintainer and ask them to label it as pinned, good first issue, help wanted or triaged/resolved. Thank you for your contributions.