Skip to content

Commit f07d8ab

Browse files
Add EventClient (#90)
Add EventClient Add related tests Update docs with related info
1 parent 0fe7d3f commit f07d8ab

8 files changed

Lines changed: 2209 additions & 55 deletions

File tree

README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ Show support for the Conductor OSS. Please help spread the awareness by starrin
6262
- [Step 1: Create a MetadataClient](#step-1-create-a-metadataclient)
6363
- [Step 2: Define and Register a Task](#step-2-define-and-register-a-task)
6464
- [Step 3: Define and Register a Workflow](#step-3-define-and-register-a-workflow)
65+
- [Events](#events)
66+
- [The EventClient](#the-eventclient)
67+
- [Quick Start: Using Event Handlers](#quick-start-using-event-handlers)
68+
- [Step 1: Create an EventClient](#step-1-create-an-eventclient)
69+
- [Step 2: Register an Event Handler](#step-2-register-an-event-handler)
70+
- [Step 3: Publish Events](#step-3-publish-events)
71+
- [Step 4: Monitor Event Processing](#step-4-monitor-event-processing)
72+
- [Step 5: Manage Event Handlers](#step-5-manage-event-handlers)
6573
- [Human Tasks](#human-tasks)
6674
- [The HumanExecutor and TemplateClient](#the-humanexecutor-and-templateclient)
6775
- [Quick Start: Creating and Managing a Human Task](#quick-start-creating-and-managing-a-human-task)
@@ -716,6 +724,110 @@ await metadataClient.registerWorkflowDef(wf);
716724

717725
For a complete method reference, see the [MetadataClient API Reference](docs/api-reference/metadata-client.md).
718726

727+
## Events
728+
729+
Event handlers in Conductor allow you to automatically trigger actions (like starting workflows) when events are received. This enables event-driven workflows and integrations with external systems.
730+
731+
### The EventClient
732+
733+
The `EventClient` manages event handlers and event processing. For a complete method reference, see the [EventClient API Reference](docs/api-reference/event-client.md).
734+
735+
### Quick Start: Using Event Handlers
736+
737+
Here's how to set up event-driven workflows:
738+
739+
#### Step 1: Create an EventClient
740+
741+
First, create an instance of the `EventClient`:
742+
743+
```typescript
744+
import { EventClient } from "@io-orkes/conductor-javascript";
745+
746+
const eventClient = new EventClient(client);
747+
```
748+
749+
#### Step 2: Register an Event Handler
750+
751+
Create an event handler that defines what action to take when an event is received. In this example, we'll start a workflow when an order is created:
752+
753+
```typescript
754+
await eventClient.addEventHandler({
755+
name: "order_created_handler",
756+
event: "order.created",
757+
active: true,
758+
description: "Starts fulfillment workflow when order is created",
759+
actions: [
760+
{
761+
action: "start_workflow",
762+
start_workflow: {
763+
name: "fulfill_order",
764+
version: 1,
765+
input: {
766+
orderId: "${event.orderId}",
767+
customerId: "${event.customerId}",
768+
},
769+
},
770+
},
771+
],
772+
});
773+
```
774+
775+
#### Step 3: Publish Events
776+
777+
When an event occurs, publish it to Conductor. All active handlers registered for that event will be triggered:
778+
779+
```typescript
780+
await eventClient.handleIncomingEvent({
781+
event: "order.created",
782+
orderId: "ORDER-123",
783+
customerId: "CUST-456",
784+
amount: "99.99",
785+
timestamp: Date.now().toString(),
786+
});
787+
```
788+
789+
#### Step 4: Monitor Event Processing
790+
791+
You can monitor event handlers and their execution history:
792+
793+
```typescript
794+
// Get all handlers for a specific event
795+
const handlers = await eventClient.getEventHandlersForEvent("order.created");
796+
797+
// Get execution history for a handler
798+
const executions = await eventClient.getEventExecutions("order_created_handler");
799+
800+
// Get event messages
801+
const messages = await eventClient.getEventMessages("order.created");
802+
```
803+
804+
#### Step 5: Manage Event Handlers
805+
806+
Update, deactivate, or remove event handlers as needed:
807+
808+
```typescript
809+
// Update a handler
810+
await eventClient.updateEventHandler({
811+
name: "order_created_handler",
812+
active: false, // Deactivate
813+
// ... other fields
814+
});
815+
816+
// Remove a handler
817+
await eventClient.removeEventHandler("order_created_handler");
818+
```
819+
820+
**Event Handler Actions:**
821+
822+
Event handlers support various actions:
823+
- `start_workflow` - Start a workflow execution
824+
- `complete_task` - Complete a specific task
825+
- `fail_task` - Fail a specific task
826+
- `terminate_workflow` - Terminate a workflow
827+
- `update_workflow_variables` - Update workflow variables
828+
829+
For a complete method reference, see the [EventClient API Reference](docs/api-reference/event-client.md).
830+
719831
## Human Tasks
720832

721833
Human tasks integrate human interaction into your automated workflows. They pause a workflow until a person provides input, such as an approval, a correction, or additional information.

0 commit comments

Comments
 (0)