You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat: add decorator-based worker registration (@worker, TaskHandler)
Introduce SDK-style worker API with auto-discovery, event listeners,
and environment configuration. Reorganize docs to prioritize new API.
Fully backward compatible with legacy TaskManager.
* Fix types and lint
* Fix mocks in tests
* Remove .test files from code coverage
* More exclusions for code coverage
* Type fixes and rename type file
* Remove exceptions file from code coverage
* Add path aliasing and more tests
* Update TaskHandler test
* Add test
* Ensure concurrency is a valid number
* Fix tests
* Fix tests
* Update test to execute worker with retry
A comprehensive TypeScript/JavaScript client for [Conductor OSS](https://github.com/conductor-oss/conductor), enabling developers to build, orchestrate, and monitor distributed workflows with ease.
5
+
A comprehensive TypeScript/JavaScript SDK for [Conductor OSS](https://github.com/conductor-oss/conductor), enabling developers to build, orchestrate, and monitor distributed workflows with ease.
6
6
7
7
[Conductor](https://www.conductor-oss.org/) is the leading open-source orchestration platform allowing developers to build highly scalable distributed applications.
8
8
@@ -40,11 +40,16 @@ Show support for the Conductor OSS. Please help spread the awareness by starrin
40
40
-[Step 4: Manage and Monitor Execution](#step-4-manage-and-monitor-execution)
41
41
-[Use TaskClient to Monitor and Debug Tasks](#use-taskclient-to-monitor-and-debug-tasks)
42
42
-[Workers](#workers)
43
-
-[The TaskManager](#the-taskmanager)
44
-
-[Quick Start: Building a Worker](#quick-start-building-a-worker)
45
-
-[Step 1: Define the Worker's Logic](#step-1-define-the-workers-logic)
46
-
-[Step 2: Handle Task Outcomes and Errors](#step-2-handle-task-outcomes-and-errors)
47
-
-[Step 3: Run the Worker with TaskManager](#step-3-run-the-worker-with-taskmanager)
The `TaskManager` class in this SDK simplifies the process of creating and managing workers.
454
+
### SDK-Style Worker Registration (Recommended)
451
455
452
-
### The TaskManager
456
+
The SDK supports decorator-based worker registration. This provides a modern, declarative approach to defining workers with auto-discovery, type safety, and less boilerplate.
453
457
454
-
The `TaskManager` is the primary tool for managing workers. It handles polling, task execution, and result reporting, allowing you to run multiple workers concurrently. For a complete method reference, see the [TaskManager API Reference](docs/api-reference/task-manager.md).
458
+
**Key Benefits:**
459
+
-**Auto-discovery**: No need to manually register workers
460
+
-**Declarative**: Configuration is co-located with worker logic
461
+
-**Type-safe**: Full TypeScript support
462
+
-**Cleaner code**: Less boilerplate than the legacy API
455
463
456
-
### Quick Start: Building a Worker
464
+
> 💡 **New to Conductor?**Start here! The decorator-based approach is simpler and more maintainable than the legacy `TaskManager` API.
457
465
458
-
Building a robust worker involves defining its logic, handling outcomes, and managing its execution.
466
+
#### Using the @workerDecorator
459
467
460
-
#### Step 1: Define the Worker's Logic
468
+
Define workers using the `@worker` decorator for cleaner, more maintainable code:
// Use TaskHandler.create() for async module imports
658
+
const handler =awaitTaskHandler.create({
659
+
client,
660
+
importModules: [
661
+
"./workers/orderWorkers",
662
+
"./workers/paymentWorkers",
663
+
],
664
+
});
665
+
666
+
handler.startWorkers(); // Auto-discovers all workers from imported modules
667
+
```
668
+
669
+
### Legacy TaskManager API
670
+
671
+
The legacy `TaskManager` API continues to work with full backward compatibility. However, **new projects should use the decorator-based approach above** for better maintainability and cleaner code.
672
+
673
+
Both APIs can coexist in the same application, allowing gradual migration from legacy to decorator-based workers.
674
+
675
+
#### The TaskManager
676
+
677
+
The `TaskManager` is the legacy tool for managing workers. It handles polling, task execution, and result reporting, allowing you to run multiple workers concurrently. For a complete method reference, see the [TaskManager API Reference](docs/api-reference/task-manager.md).
678
+
679
+
#### Quick Start: Building a Worker
680
+
681
+
Building a worker with the legacy API involves defining its logic, handling outcomes, and managing its execution.
682
+
683
+
##### Step 1: Define the Worker's Logic
461
684
462
685
A worker is an object that defines a `taskDefName` (which must match the task name in your workflow) and an `execute` function containing your business logic.
The `execute` function must return an object indicating the task's outcome.
490
713
@@ -512,7 +735,7 @@ try {
512
735
}
513
736
```
514
737
515
-
#### Step 3: Run the Worker with TaskManager
738
+
#####Step 3: Run the Worker with TaskManager
516
739
517
740
The `TaskManager` is responsible for polling Conductor, managing task execution, and reporting back results. You can run a single worker or multiple workers with one manager.
518
741
@@ -539,7 +762,7 @@ For a complete method reference, see the [TaskManager API Reference](docs/api-re
539
762
540
763
### Worker Design Principles
541
764
542
-
When designing workers, it's best to follow these principles:
765
+
When designing workers (with either API), it's best to follow these principles:
543
766
544
767
-**Stateless**: Workers should not rely on local state.
545
768
-**Idempotent**: The same task input should always produce the same result.
0 commit comments