Skip to content

Commit

Permalink
feat(workflow): Add workflow management HTTP APIs (#485)
Browse files Browse the repository at this point in the history
* WIP interface

Signed-off-by: Shubham Sharma <[email protected]>

* Add interfaces

Signed-off-by: Shubham Sharma <[email protected]>

* Add empty implementations

Signed-off-by: Shubham Sharma <[email protected]>

* Add HTTP get implementation

Signed-off-by: Shubham Sharma <[email protected]>

* Add example for get

Signed-off-by: Shubham Sharma <[email protected]>

* Complete HTTP get workflow

Signed-off-by: Shubham Sharma <[email protected]>

* Add other implementations

Signed-off-by: Shubham Sharma <[email protected]>

* Implement start

Signed-off-by: Shubham Sharma <[email protected]>

* More examples, start/raise implementation

Signed-off-by: Shubham Sharma <[email protected]>

* Fix lint;

Signed-off-by: Shubham Sharma <[email protected]>

* Add docs

Signed-off-by: Shubham Sharma <[email protected]>

* nits

Signed-off-by: Shubham Sharma <[email protected]>

---------

Signed-off-by: Shubham Sharma <[email protected]>
  • Loading branch information
shubham1172 authored Jun 8, 2023
1 parent af71496 commit 5e42a79
Show file tree
Hide file tree
Showing 13 changed files with 1,125 additions and 47 deletions.
50 changes: 50 additions & 0 deletions daprdocs/content/en/js-sdk-docs/js-client/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,56 @@ start().catch((e) => {

> For a full guide on distributed locks visit [How-To: Use Distributed Locks]({{< ref howto-use-distributed-lock.md >}}).
### Workflow API

#### Workflow management

```typescript
import { DaprClient } from "@dapr/dapr";

async function start() {
const client = new DaprClient();

// Start a new workflow instance
const instanceId = await client.workflow.start("OrderProcessingWorkflow", {
Name: "Paperclips",
TotalCost: 99.95,
Quantity: 4,
});
console.log(`Started workflow instance ${instanceId}`);

// Get a workflow instance
const workflow = await client.workflow.get(instanceId);
console.log(
`Workflow ${workflow.workflowName}, created at ${workflow.createdAt.toUTCString()}, has status ${
workflow.runtimeStatus
}`,
);
console.log(`Additional properties: ${JSON.stringify(workflow.properties)}`);

// Pause a workflow instance
await client.workflow.pause(instanceId);
console.log(`Paused workflow instance ${instanceId}`);

// Resume a workflow instance
await client.workflow.resume(instanceId);
console.log(`Resumed workflow instance ${instanceId}`);

// Terminate a workflow instance
await client.workflow.terminate(instanceId);
console.log(`Terminated workflow instance ${instanceId}`);

// Purge a workflow instance
await client.workflow.purge(instanceId);
console.log(`Purged workflow instance ${instanceId}`);
}

start().catch((e) => {
console.error(e);
process.exit(1);
});
```

## Related links

- [JavaScript SDK examples](https://github.com/dapr/js-sdk/tree/master/examples)
Loading

0 comments on commit 5e42a79

Please sign in to comment.