nestjs-temporal-core 2.0.3 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +308 -234
  2. package/dist/client/index.js.map +1 -1
  3. package/dist/client/temporal-client.module.js +5 -5
  4. package/dist/client/temporal-client.module.js.map +1 -1
  5. package/dist/client/temporal-client.service.d.ts +4 -1
  6. package/dist/client/temporal-client.service.js +34 -1
  7. package/dist/client/temporal-client.service.js.map +1 -1
  8. package/dist/constants.d.ts +2 -8
  9. package/dist/constants.js +3 -9
  10. package/dist/constants.js.map +1 -1
  11. package/dist/decorators/activity-method.decorator.d.ts +1 -7
  12. package/dist/decorators/activity-method.decorator.js +2 -2
  13. package/dist/decorators/activity-method.decorator.js.map +1 -1
  14. package/dist/decorators/activity.decorator.d.ts +1 -4
  15. package/dist/decorators/activity.decorator.js.map +1 -1
  16. package/dist/decorators/index.d.ts +4 -0
  17. package/dist/decorators/index.js +4 -0
  18. package/dist/decorators/index.js.map +1 -1
  19. package/dist/decorators/query.decorator.d.ts +2 -0
  20. package/dist/decorators/query.decorator.js +26 -0
  21. package/dist/decorators/query.decorator.js.map +1 -0
  22. package/dist/decorators/scheduled-workflow.decorator.d.ts +13 -0
  23. package/dist/decorators/scheduled-workflow.decorator.js +28 -0
  24. package/dist/decorators/scheduled-workflow.decorator.js.map +1 -0
  25. package/dist/decorators/signal.decorator.d.ts +2 -0
  26. package/dist/decorators/signal.decorator.js +26 -0
  27. package/dist/decorators/signal.decorator.js.map +1 -0
  28. package/dist/decorators/workflow-method.decorator.d.ts +2 -0
  29. package/dist/decorators/workflow-method.decorator.js +29 -0
  30. package/dist/decorators/workflow-method.decorator.js.map +1 -0
  31. package/dist/decorators/workflow.decorator.d.ts +2 -16
  32. package/dist/decorators/workflow.decorator.js +1 -0
  33. package/dist/decorators/workflow.decorator.js.map +1 -1
  34. package/dist/index.d.ts +1 -0
  35. package/dist/index.js +1 -0
  36. package/dist/index.js.map +1 -1
  37. package/dist/interfaces/activity.interface.d.ts +20 -0
  38. package/dist/interfaces/activity.interface.js +3 -0
  39. package/dist/interfaces/activity.interface.js.map +1 -0
  40. package/dist/interfaces/client.interface.d.ts +2 -2
  41. package/dist/interfaces/index.d.ts +3 -0
  42. package/dist/interfaces/index.js +3 -0
  43. package/dist/interfaces/index.js.map +1 -1
  44. package/dist/interfaces/schedule.interface.d.ts +17 -0
  45. package/dist/interfaces/schedule.interface.js +3 -0
  46. package/dist/interfaces/schedule.interface.js.map +1 -0
  47. package/dist/interfaces/worker.interface.d.ts +4 -4
  48. package/dist/interfaces/workflow.interface.d.ts +19 -0
  49. package/dist/interfaces/workflow.interface.js +3 -0
  50. package/dist/interfaces/workflow.interface.js.map +1 -0
  51. package/dist/schedule/index.d.ts +2 -0
  52. package/dist/schedule/index.js +19 -0
  53. package/dist/schedule/index.js.map +1 -0
  54. package/dist/schedule/temporal-schedule.module.d.ts +7 -0
  55. package/dist/schedule/temporal-schedule.module.js +94 -0
  56. package/dist/schedule/temporal-schedule.module.js.map +1 -0
  57. package/dist/schedule/temporal-schedule.service.d.ts +28 -0
  58. package/dist/schedule/temporal-schedule.service.js +230 -0
  59. package/dist/schedule/temporal-schedule.service.js.map +1 -0
  60. package/dist/tsconfig.tsbuildinfo +1 -1
  61. package/package.json +1 -1
package/README.md CHANGED
@@ -2,22 +2,22 @@
2
2
 
3
3
  A robust NestJS integration for [Temporal.io](https://temporal.io/) that provides seamless worker and client support for building reliable distributed applications.
4
4
 
5
+ ## Overview
6
+
7
+ NestJS Temporal Core simplifies building fault-tolerant, long-running processes in your NestJS applications by integrating with Temporal.io - a durable execution system for reliable microservices and workflow orchestration.
8
+
5
9
  ## Features
6
10
 
7
- - 🚀 Easy integration with NestJS modules
8
- - 🔄 Automatic worker initialization and shutdown
9
- - 🎯 Declarative activity and workflow decorators
10
- - 🔌 Built-in connection management
11
- - 🛡️ Type-safe workflow execution
12
- - 📡 Simplified client operations
13
- - 🔒 TLS support for secure connections
14
- - 🎛️ Configurable runtime options
15
- - 🔄 Enhanced worker options customization
16
- - 📊 Worker status monitoring
17
- - 📅 Cron workflow scheduling
18
- - 🔍 Query handling support
19
- - 📣 Signal handling
20
- - 🚦 Workflow retry policies
11
+ - 🚀 **Easy NestJS Integration** - Register modules with sync/async configuration
12
+ - 🔄 **Complete Lifecycle Management** - Automatic worker initialization and graceful shutdown
13
+ - 🎯 **Declarative Decorators** - Type-safe `@Activity()`, `@Workflow()`, `@Signal()`, and `@Query()` decorators
14
+ - 🔌 **Connection Management** - Built-in connection handling with TLS support
15
+ - 🔒 **Type Safety** - Strongly typed interfaces for all Temporal concepts
16
+ - 📡 **Client Operation Utilities** - Methods for starting, signaling, querying and managing workflows
17
+ - 📊 **Monitoring Support** - Worker status tracking and metrics
18
+ - 📅 **Scheduling** - Native support for cron and interval-based workflow scheduling
19
+ - 🔍 **Queries and Signals** - First-class support for Temporal's query and signal patterns
20
+ - 🚦 **Advanced Policies** - Built-in retry, timeout, and workflow management policies
21
21
 
22
22
  ## Installation
23
23
 
@@ -33,54 +33,41 @@ First, make sure to enable shutdown hooks in your `main.ts` file:
33
33
 
34
34
  ```typescript
35
35
  async function bootstrap() {
36
- const app = await NestFactory.create(AppModule);
37
- app.enableShutdownHooks();
38
- await app.listen(3000);
36
+ const app = await NestFactory.create(AppModule);
37
+ app.enableShutdownHooks();
38
+ await app.listen(3000);
39
39
  }
40
40
  bootstrap();
41
41
  ```
42
42
 
43
- ### 2. Register the Module
43
+ ### 2. Register the Modules
44
44
 
45
45
  ```typescript
46
46
  import { Module } from '@nestjs/common';
47
47
  import { TemporalWorkerModule, TemporalClientModule } from 'nestjs-temporal-core';
48
48
 
49
49
  @Module({
50
- imports: [
51
- TemporalWorkerModule.register({
52
- connection: {
53
- address: 'localhost:7233',
54
- },
55
- namespace: 'default',
56
- taskQueue: 'my-task-queue',
57
- workflowsPath: require.resolve('./workflows'),
58
- activityClasses: [MyActivity],
59
- // Optional runtime configuration
60
- runtimeOptions: {
61
- // Add your runtime options here
62
- },
63
- // Optional worker configuration
64
- workerOptions: {
65
- // Add your worker options here
66
- },
67
- // Auto-start configuration
68
- autoStart: {
69
- enabled: true,
70
- delayMs: 1000, // Start worker after 1 second
71
- },
72
- // Optional monitoring configuration
73
- monitoring: {
74
- statsIntervalMs: 60000, // Log stats every minute
75
- },
76
- }),
77
- TemporalClientModule.register({
78
- connection: {
79
- address: 'localhost:7233',
80
- },
81
- namespace: 'default',
82
- }),
83
- ],
50
+ imports: [
51
+ TemporalWorkerModule.register({
52
+ connection: {
53
+ address: 'localhost:7233',
54
+ },
55
+ namespace: 'default',
56
+ taskQueue: 'my-task-queue',
57
+ workflowsPath: require.resolve('./workflows'),
58
+ activityClasses: [MyActivity],
59
+ autoStart: {
60
+ enabled: true,
61
+ delayMs: 1000, // Start worker after 1 second
62
+ },
63
+ }),
64
+ TemporalClientModule.register({
65
+ connection: {
66
+ address: 'localhost:7233',
67
+ },
68
+ namespace: 'default',
69
+ }),
70
+ ],
84
71
  })
85
72
  export class AppModule {}
86
73
  ```
@@ -91,26 +78,26 @@ export class AppModule {}
91
78
  import { Activity, ActivityMethod } from 'nestjs-temporal-core';
92
79
 
93
80
  @Activity({
94
- name: 'PaymentActivities', // Optional custom name
95
- description: 'Activities for payment processing',
81
+ name: 'PaymentActivities', // Optional custom name
82
+ description: 'Activities for payment processing',
96
83
  })
97
84
  export class PaymentActivity {
98
- @ActivityMethod({
99
- name: 'processPayment', // Optional custom name
100
- timeout: {
101
- startToClose: '30s',
102
- },
103
- })
104
- async processPayment(amount: number): Promise<string> {
105
- // Implementation
106
- return 'payment-id';
107
- }
108
-
109
- @ActivityMethod()
110
- async refundPayment(paymentId: string): Promise<boolean> {
111
- // Implementation
112
- return true;
113
- }
85
+ @ActivityMethod({
86
+ name: 'processPayment', // Optional custom name
87
+ timeout: {
88
+ startToClose: '30s',
89
+ },
90
+ })
91
+ async processPayment(amount: number): Promise<string> {
92
+ // Implementation
93
+ return 'payment-id';
94
+ }
95
+
96
+ @ActivityMethod()
97
+ async refundPayment(paymentId: string): Promise<boolean> {
98
+ // Implementation
99
+ return true;
100
+ }
114
101
  }
115
102
  ```
116
103
 
@@ -120,16 +107,17 @@ export class PaymentActivity {
120
107
  import { proxyActivities } from '@temporalio/workflow';
121
108
  import type { PaymentActivity } from './payment.activity';
122
109
 
110
+ // Reference activities in your workflow
123
111
  const { processPayment, refundPayment } = proxyActivities<PaymentActivity>({
124
- startToCloseTimeout: '30 seconds',
112
+ startToCloseTimeout: '30 seconds',
125
113
  });
126
114
 
127
115
  export async function paymentWorkflow(amount: number): Promise<string> {
128
- return await processPayment(amount);
116
+ return await processPayment(amount);
129
117
  }
130
118
 
131
119
  export async function refundWorkflow(paymentId: string): Promise<boolean> {
132
- return await refundPayment(paymentId);
120
+ return await refundPayment(paymentId);
133
121
  }
134
122
  ```
135
123
 
@@ -141,37 +129,137 @@ import { TemporalClientService } from 'nestjs-temporal-core';
141
129
 
142
130
  @Injectable()
143
131
  export class PaymentService {
144
- constructor(private readonly temporalClient: TemporalClientService) {}
145
-
146
- async initiatePayment(amount: number) {
147
- const { result, workflowId } = await this.temporalClient.startWorkflow<string, [number]>(
148
- 'paymentWorkflow',
149
- [amount],
150
- {
151
- taskQueue: 'my-task-queue',
152
- workflowExecutionTimeout: '1h',
153
- workflowTaskTimeout: '10s',
154
- retry: {
155
- maximumAttempts: 3,
156
- },
157
- },
158
- );
132
+ constructor(private readonly temporalClient: TemporalClientService) {}
133
+
134
+ async initiatePayment(amount: number) {
135
+ const { result, workflowId } = await this.temporalClient.startWorkflow<string, [number]>(
136
+ 'paymentWorkflow',
137
+ [amount],
138
+ {
139
+ taskQueue: 'my-task-queue',
140
+ workflowExecutionTimeout: '1h',
141
+ workflowTaskTimeout: '10s',
142
+ retry: {
143
+ maximumAttempts: 3,
144
+ },
145
+ },
146
+ );
147
+
148
+ // Wait for the workflow to complete
149
+ const paymentId = await result;
150
+
151
+ return { paymentId, workflowId };
152
+ }
153
+
154
+ async checkPaymentStatus(workflowId: string) {
155
+ // Query a running workflow
156
+ return await this.temporalClient.queryWorkflow<string>(workflowId, 'getPaymentStatus');
157
+ }
158
+
159
+ async cancelPayment(workflowId: string, reason: string) {
160
+ // Signal a running workflow
161
+ await this.temporalClient.signalWorkflow(workflowId, 'cancelPayment', [reason]);
162
+ }
163
+ }
164
+ ```
159
165
 
160
- // Wait for the workflow to complete
161
- const paymentId = await result;
166
+ ## Advanced Features
162
167
 
163
- return { paymentId, workflowId };
164
- }
168
+ ### Class-Based Workflows with Queries and Signals
165
169
 
166
- async checkPaymentStatus(workflowId: string) {
167
- // Query a running workflow
168
- return await this.temporalClient.queryWorkflow<string>(workflowId, 'getPaymentStatus');
169
- }
170
+ ```typescript
171
+ import { Workflow, WorkflowMethod, Query, Signal } from 'nestjs-temporal-core';
170
172
 
171
- async cancelPayment(workflowId: string, reason: string) {
172
- // Signal a running workflow
173
- await this.temporalClient.signalWorkflow(workflowId, 'cancelPayment', [reason]);
174
- }
173
+ @Workflow({
174
+ taskQueue: 'order-queue',
175
+ workflowIdPrefix: 'order-',
176
+ workflowExecutionTimeout: '24h',
177
+ })
178
+ export class OrderWorkflow {
179
+ private orderStatus: string = 'PENDING';
180
+ private cancelReason: string | null = null;
181
+
182
+ @WorkflowMethod()
183
+ async execute(orderId: string): Promise<string> {
184
+ // Workflow implementation
185
+ return this.orderStatus;
186
+ }
187
+
188
+ @Query()
189
+ getStatus(): string {
190
+ return this.orderStatus;
191
+ }
192
+
193
+ @Signal()
194
+ cancel(reason: string): void {
195
+ this.orderStatus = 'CANCELLED';
196
+ this.cancelReason = reason;
197
+ }
198
+ }
199
+ ```
200
+
201
+ ### Scheduled Workflows
202
+
203
+ ```typescript
204
+ import { ScheduledWorkflow, WorkflowMethod } from 'nestjs-temporal-core';
205
+
206
+ @ScheduledWorkflow({
207
+ taskQueue: 'scheduled-tasks',
208
+ schedule: {
209
+ cron: '0 0 * * *', // Run daily at midnight
210
+ },
211
+ description: 'Daily reporting workflow',
212
+ })
213
+ export class DailyReportWorkflow {
214
+ @WorkflowMethod()
215
+ async execute(): Promise<void> {
216
+ // Generate and send reports
217
+ }
218
+ }
219
+ ```
220
+
221
+ ### Using the Schedule Service
222
+
223
+ ```typescript
224
+ import { Injectable } from '@nestjs/common';
225
+ import { TemporalScheduleService } from 'nestjs-temporal-core';
226
+
227
+ @Injectable()
228
+ export class ReportingService {
229
+ constructor(private readonly scheduleService: TemporalScheduleService) {}
230
+
231
+ async createDailyReportSchedule() {
232
+ return await this.scheduleService.createCronWorkflow(
233
+ 'daily-sales-report',
234
+ 'generateSalesReport',
235
+ '0 0 * * *', // Daily at midnight
236
+ 'reports-queue',
237
+ [], // No arguments
238
+ 'Daily sales report generation',
239
+ );
240
+ }
241
+
242
+ async createHourlyDataBackup() {
243
+ return await this.scheduleService.createIntervalWorkflow(
244
+ 'hourly-data-backup',
245
+ 'backupData',
246
+ { hours: 1 },
247
+ 'backup-queue',
248
+ [],
249
+ 'Hourly data backup process',
250
+ );
251
+ }
252
+
253
+ async pauseReports() {
254
+ await this.scheduleService.pauseSchedule(
255
+ 'daily-sales-report',
256
+ 'Paused for system maintenance',
257
+ );
258
+ }
259
+
260
+ async listAllSchedules() {
261
+ return await this.scheduleService.listSchedules();
262
+ }
175
263
  }
176
264
  ```
177
265
 
@@ -179,178 +267,164 @@ export class PaymentService {
179
267
 
180
268
  ### Async Configuration
181
269
 
270
+ Use factory patterns for dynamic configuration:
271
+
182
272
  ```typescript
183
273
  TemporalWorkerModule.registerAsync({
184
- imports: [ConfigModule],
185
- useFactory: async (configService: ConfigService) => ({
186
- connection: {
187
- address: configService.get('TEMPORAL_ADDRESS'),
188
- connectionTimeout: configService.get('TEMPORAL_CONNECTION_TIMEOUT', 5000),
189
- },
190
- namespace: configService.get('TEMPORAL_NAMESPACE'),
191
- taskQueue: configService.get('TEMPORAL_TASK_QUEUE'),
192
- workflowsPath: require.resolve('./workflows'),
193
- activityClasses: [MyActivity],
194
- autoStart: {
195
- enabled: configService.get('TEMPORAL_WORKER_AUTOSTART', true),
196
- delayMs: configService.get('TEMPORAL_WORKER_START_DELAY', 0),
197
- },
198
- allowWorkerFailure: configService.get('TEMPORAL_ALLOW_WORKER_FAILURE', true),
199
- }),
200
- inject: [ConfigService],
274
+ imports: [ConfigModule],
275
+ useFactory: async (configService: ConfigService) => ({
276
+ connection: {
277
+ address: configService.get('TEMPORAL_ADDRESS'),
278
+ connectionTimeout: configService.get('TEMPORAL_CONNECTION_TIMEOUT', 5000),
279
+ },
280
+ namespace: configService.get('TEMPORAL_NAMESPACE'),
281
+ taskQueue: configService.get('TEMPORAL_TASK_QUEUE'),
282
+ workflowsPath: require.resolve('./workflows'),
283
+ activityClasses: [MyActivity],
284
+ autoStart: {
285
+ enabled: configService.get('TEMPORAL_WORKER_AUTOSTART', true),
286
+ delayMs: configService.get('TEMPORAL_WORKER_START_DELAY', 0),
287
+ },
288
+ allowWorkerFailure: configService.get('TEMPORAL_ALLOW_WORKER_FAILURE', true),
289
+ }),
290
+ inject: [ConfigService],
201
291
  });
202
292
  ```
203
293
 
204
294
  ### TLS Configuration
205
295
 
296
+ Set up secure communications with TLS:
297
+
206
298
  ```typescript
207
299
  TemporalClientModule.register({
208
- connection: {
209
- address: 'temporal.example.com:7233',
210
- tls: {
211
- clientCertPair: {
212
- crt: Buffer.from('...'),
213
- key: Buffer.from('...'),
214
- ca: Buffer.from('...'), // Optional CA certificate
215
- },
216
- serverName: 'temporal.example.com', // Optional for SNI
217
- verifyServer: true, // Optional, defaults to true
300
+ connection: {
301
+ address: 'temporal.example.com:7233',
302
+ tls: {
303
+ clientCertPair: {
304
+ crt: Buffer.from('...'),
305
+ key: Buffer.from('...'),
306
+ ca: Buffer.from('...'), // Optional CA certificate
307
+ },
308
+ serverName: 'temporal.example.com', // Optional for SNI
309
+ verifyServer: true, // Optional, defaults to true
310
+ },
311
+ connectionTimeout: 10000, // 10 seconds
312
+ },
313
+ namespace: 'production',
314
+ allowConnectionFailure: true, // Allow application to start if Temporal connection fails
315
+ });
316
+ ```
317
+
318
+ ### Worker Monitoring
319
+
320
+ Enable worker monitoring and metrics:
321
+
322
+ ```typescript
323
+ TemporalWorkerModule.register({
324
+ // ... other options
325
+ monitoring: {
326
+ statsIntervalMs: 60000, // Log stats every minute
327
+ metrics: {
328
+ enabled: true,
329
+ prometheus: {
330
+ enabled: true,
331
+ port: 9464,
332
+ },
333
+ },
218
334
  },
219
- connectionTimeout: 10000, // 10 seconds
220
- },
221
- namespace: 'production',
222
- allowConnectionFailure: true, // Allow application to start if Temporal connection fails
223
335
  });
224
336
  ```
225
337
 
226
338
  ## API Reference
227
339
 
340
+ ### Core Modules
341
+
342
+ - `TemporalClientModule` - Client connectivity for workflow operations
343
+ - `TemporalWorkerModule` - Worker process for running activities
344
+ - `TemporalScheduleModule` - Scheduling for recurring workflows
345
+
228
346
  ### Decorators
229
347
 
230
- - `@Activity(options?)`: Marks a class as a Temporal activity with optional configuration
231
- - `@ActivityMethod(options?)`: Marks a method as a Temporal activity implementation with optional configuration
232
- - `@Workflow(options)`: Marks a class as a Temporal workflow with configuration
348
+ - `@Activity(options?)` - Marks a class as a Temporal activity
349
+ - `@ActivityMethod(options?)` - Marks a method as an activity implementation
350
+ - `@Workflow(options)` - Marks a class as a Temporal workflow
351
+ - `@WorkflowMethod(options?)` - Marks the primary workflow execution method
352
+ - `@Query(options?)` - Marks a method as a query handler
353
+ - `@Signal(options?)` - Marks a method as a signal handler
354
+ - `@ScheduledWorkflow(options)` - Defines a workflow with schedule configuration
233
355
 
234
356
  ### Services
235
357
 
236
358
  #### TemporalClientService
237
359
 
238
- - `startWorkflow<T, A>()`: Start a new workflow execution
239
- - `signalWorkflow()`: Send a signal to a running workflow
240
- - `queryWorkflow<T>()`: Query a running workflow
241
- - `terminateWorkflow()`: Terminate a running workflow
242
- - `cancelWorkflow()`: Request cancellation of a workflow
243
- - `getWorkflowHandle()`: Get a handle to manage a workflow
244
- - `getWorkflowClient()`: Get the underlying workflow client instance
360
+ - `startWorkflow<T, A>()` - Start a new workflow execution
361
+ - `signalWorkflow()` - Send a signal to a running workflow
362
+ - `queryWorkflow<T>()` - Query a running workflow
363
+ - `terminateWorkflow()` - Terminate a running workflow
364
+ - `cancelWorkflow()` - Request cancellation of a workflow
365
+ - `getWorkflowHandle()` - Get a handle to manage a workflow
366
+ - `describeWorkflow()` - Get workflow execution details
367
+ - `getWorkflowClient()` - Get the underlying workflow client
368
+
369
+ #### TemporalScheduleService
370
+
371
+ - `createCronWorkflow()` - Create a workflow scheduled by cron expression
372
+ - `createIntervalWorkflow()` - Create a workflow scheduled by time interval
373
+ - `pauseSchedule()` - Pause a schedule
374
+ - `resumeSchedule()` - Resume a paused schedule
375
+ - `deleteSchedule()` - Delete a schedule
376
+ - `triggerNow()` - Trigger an immediate execution
377
+ - `backfill()` - Run schedule actions for a past time range
378
+ - `listSchedules()` - List all schedules
379
+ - `describeSchedule()` - Get detailed schedule information
245
380
 
246
381
  #### WorkerManager
247
382
 
248
- - `startWorker()`: Manually start the worker if it's not running
249
- - `shutdown()`: Gracefully shutdown the worker
250
- - `getWorker()`: Get the underlying worker instance
251
-
252
- ### Module Options
383
+ - `startWorker()` - Manually start the worker
384
+ - `shutdown()` - Gracefully shutdown the worker
385
+ - `getWorker()` - Get the underlying worker instance
253
386
 
254
- #### TemporalWorkerOptions
387
+ ## Error Handling
255
388
 
256
- ```typescript
257
- interface TemporalWorkerOptions {
258
- connection: NativeConnectionOptions;
259
- namespace: string;
260
- taskQueue: string;
261
- workflowsPath: string;
262
- activityClasses?: Array<new (...args: any[]) => any>;
263
- runtimeOptions?: RuntimeOptions;
264
- workerOptions?: WorkerOptions;
265
- autoStart?: {
266
- enabled?: boolean;
267
- delayMs?: number;
268
- };
269
- allowWorkerFailure?: boolean;
270
- monitoring?: {
271
- statsIntervalMs?: number;
272
- metrics?: {
273
- enabled?: boolean;
274
- prometheus?: {
275
- enabled?: boolean;
276
- port?: number;
277
- };
278
- };
279
- };
280
- }
281
- ```
389
+ The module includes comprehensive error handling:
282
390
 
283
- #### TemporalClientOptions
391
+ - Worker initialization errors are logged and handled based on configuration
392
+ - Client operations include detailed error messages and proper error propagation
393
+ - Activities and workflow errors are properly captured and logged
394
+ - Connection errors are handled gracefully with automatic cleanup
395
+ - Configurable failure modes for both client and worker connections
284
396
 
285
- ```typescript
286
- interface TemporalClientOptions {
287
- connection: ConnectionOptions;
288
- namespace?: string;
289
- allowConnectionFailure?: boolean;
290
- reconnect?: {
291
- enabled?: boolean;
292
- maxAttempts?: number;
293
- initialDelayMs?: number;
294
- maxDelayMs?: number;
295
- backoffCoefficient?: number;
296
- };
297
- }
298
- ```
397
+ ## Best Practices
299
398
 
300
- ### Activity Method Options
399
+ 1. **Activity Design**
301
400
 
302
- ```typescript
303
- interface ActivityMethodOptions {
304
- name?: string;
305
- description?: string;
306
- timeout?: {
307
- startToClose?: string | number;
308
- scheduleToStart?: string | number;
309
- };
310
- }
311
- ```
401
+ - Define activity interfaces for type safety
402
+ - Keep activities focused on single responsibilities
403
+ - Set appropriate timeouts for expected durations
312
404
 
313
- ### Workflow Options
405
+ 2. **Workflow Design**
314
406
 
315
- ```typescript
316
- interface TemporalWorkflowDecoratorOptions {
317
- name?: string;
318
- description?: string;
319
- taskQueue: string;
320
- workflowIdPrefix?: string;
321
- executionTimeout?: string;
322
- workflowTaskTimeout?: string;
323
- retry?: {
324
- maximumAttempts?: number;
325
- initialInterval?: number;
326
- maximumInterval?: number;
327
- backoffCoefficient?: number;
328
- };
329
- }
330
- ```
407
+ - Make workflows deterministic
408
+ - Use signals for external events
409
+ - Use queries for retrieving workflow state
410
+ - Avoid side effects in workflow code
331
411
 
332
- ## Error Handling
412
+ 3. **Configuration**
333
413
 
334
- The module includes comprehensive error handling:
414
+ - Use meaningful workflow IDs for tracking
415
+ - Configure appropriate timeouts for activities and workflows
416
+ - Use retry policies for transient failures
417
+ - Set up monitoring for production deployments
335
418
 
336
- - Worker initialization errors are logged and can prevent application startup if critical
337
- - Client operations include detailed error messages and proper error propagation
338
- - Activity and workflow errors are properly captured and logged
339
- - Connection errors are handled gracefully with automatic cleanup
340
- - Configurable failure modes for both client and worker connections
419
+ 4. **Lifecycle Management**
341
420
 
342
- ## Best Practices
421
+ - Enable NestJS shutdown hooks
422
+ - Configure proper worker shutdown grace periods
423
+ - Use the WorkerManager service for controlling worker lifecycle
343
424
 
344
- 1. Always define activity interfaces for type safety
345
- 2. Use meaningful workflow IDs for tracking
346
- 3. Implement proper error handling in activities
347
- 4. Set appropriate timeouts for activities and workflows
348
- 5. Use signals for long-running workflow coordination
349
- 6. Monitor worker status using the WorkerManager service
350
- 7. Configure appropriate runtime and worker options for production deployments
351
- 8. Implement proper TLS security for production environments
352
- 9. Use workflow queries for reading workflow state without side effects
353
- 10. Configure graceful shutdown for workers to prevent activity interruptions
425
+ 5. **Security**
426
+ - Implement proper TLS security for production environments
427
+ - Use namespaces to isolate different environments
354
428
 
355
429
  ## Contributing
356
430
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,4DAA0C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGA,2DAAyC;AACzC,4DAA0C"}