nestjs-temporal-core 2.0.2 → 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.
- package/README.md +322 -134
- package/dist/client/index.js.map +1 -1
- package/dist/client/temporal-client.module.js +46 -19
- package/dist/client/temporal-client.module.js.map +1 -1
- package/dist/client/temporal-client.service.d.ts +7 -7
- package/dist/client/temporal-client.service.js +48 -6
- package/dist/client/temporal-client.service.js.map +1 -1
- package/dist/constants.d.ts +28 -1
- package/dist/constants.js +29 -2
- package/dist/constants.js.map +1 -1
- package/dist/decorators/activity-method.decorator.d.ts +2 -1
- package/dist/decorators/activity-method.decorator.js +21 -3
- package/dist/decorators/activity-method.decorator.js.map +1 -1
- package/dist/decorators/activity.decorator.d.ts +2 -1
- package/dist/decorators/activity.decorator.js +3 -3
- package/dist/decorators/activity.decorator.js.map +1 -1
- package/dist/decorators/index.d.ts +4 -0
- package/dist/decorators/index.js +4 -0
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/query.decorator.d.ts +2 -0
- package/dist/decorators/query.decorator.js +26 -0
- package/dist/decorators/query.decorator.js.map +1 -0
- package/dist/decorators/scheduled-workflow.decorator.d.ts +13 -0
- package/dist/decorators/scheduled-workflow.decorator.js +28 -0
- package/dist/decorators/scheduled-workflow.decorator.js.map +1 -0
- package/dist/decorators/signal.decorator.d.ts +2 -0
- package/dist/decorators/signal.decorator.js +26 -0
- package/dist/decorators/signal.decorator.js.map +1 -0
- package/dist/decorators/workflow-method.decorator.d.ts +2 -0
- package/dist/decorators/workflow-method.decorator.js +29 -0
- package/dist/decorators/workflow-method.decorator.js.map +1 -0
- package/dist/decorators/workflow.decorator.d.ts +2 -2
- package/dist/decorators/workflow.decorator.js +12 -4
- package/dist/decorators/workflow.decorator.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/activity.interface.d.ts +20 -0
- package/dist/interfaces/activity.interface.js +3 -0
- package/dist/interfaces/activity.interface.js.map +1 -0
- package/dist/interfaces/base.interface.d.ts +4 -2
- package/dist/interfaces/client.interface.d.ts +27 -1
- package/dist/interfaces/index.d.ts +3 -0
- package/dist/interfaces/index.js +3 -0
- package/dist/interfaces/index.js.map +1 -1
- package/dist/interfaces/schedule.interface.d.ts +17 -0
- package/dist/interfaces/schedule.interface.js +3 -0
- package/dist/interfaces/schedule.interface.js.map +1 -0
- package/dist/interfaces/worker.interface.d.ts +18 -3
- package/dist/interfaces/workflow.interface.d.ts +19 -0
- package/dist/interfaces/workflow.interface.js +3 -0
- package/dist/interfaces/workflow.interface.js.map +1 -0
- package/dist/schedule/index.d.ts +2 -0
- package/dist/schedule/index.js +19 -0
- package/dist/schedule/index.js.map +1 -0
- package/dist/schedule/temporal-schedule.module.d.ts +7 -0
- package/dist/schedule/temporal-schedule.module.js +94 -0
- package/dist/schedule/temporal-schedule.module.js.map +1 -0
- package/dist/schedule/temporal-schedule.service.d.ts +28 -0
- package/dist/schedule/temporal-schedule.service.js +230 -0
- package/dist/schedule/temporal-schedule.service.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/worker/temporal-metadata.accessor.d.ts +11 -0
- package/dist/worker/temporal-metadata.accessor.js +78 -1
- package/dist/worker/temporal-metadata.accessor.js.map +1 -1
- package/dist/worker/temporal-worker.module.d.ts +2 -1
- package/dist/worker/temporal-worker.module.js +17 -10
- package/dist/worker/temporal-worker.module.js.map +1 -1
- package/dist/worker/worker-manager.service.d.ts +8 -7
- package/dist/worker/worker-manager.service.js +116 -54
- package/dist/worker/worker-manager.service.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
# NestJS Temporal Core
|
|
2
2
|
|
|
3
|
-
A NestJS integration for [Temporal.io](https://temporal.io/) that provides seamless worker and client support for building reliable distributed applications.
|
|
3
|
+
A robust NestJS integration for [Temporal.io](https://temporal.io/) that provides seamless worker and client support for building reliable distributed applications.
|
|
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.
|
|
4
8
|
|
|
5
9
|
## Features
|
|
6
10
|
|
|
7
|
-
- 🚀 Easy
|
|
8
|
-
- 🔄 Automatic worker initialization and shutdown
|
|
9
|
-
- 🎯 Declarative
|
|
10
|
-
- 🔌 Built-in connection
|
|
11
|
-
-
|
|
12
|
-
- 📡
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
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
|
|
17
21
|
|
|
18
22
|
## Installation
|
|
19
23
|
|
|
@@ -29,45 +33,41 @@ First, make sure to enable shutdown hooks in your `main.ts` file:
|
|
|
29
33
|
|
|
30
34
|
```typescript
|
|
31
35
|
async function bootstrap() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
const app = await NestFactory.create(AppModule);
|
|
37
|
+
app.enableShutdownHooks();
|
|
38
|
+
await app.listen(3000);
|
|
35
39
|
}
|
|
36
40
|
bootstrap();
|
|
37
41
|
```
|
|
38
42
|
|
|
39
|
-
### 2. Register the
|
|
43
|
+
### 2. Register the Modules
|
|
40
44
|
|
|
41
45
|
```typescript
|
|
42
46
|
import { Module } from '@nestjs/common';
|
|
43
47
|
import { TemporalWorkerModule, TemporalClientModule } from 'nestjs-temporal-core';
|
|
44
48
|
|
|
45
49
|
@Module({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
namespace: 'default',
|
|
69
|
-
}),
|
|
70
|
-
],
|
|
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
|
+
],
|
|
71
71
|
})
|
|
72
72
|
export class AppModule {}
|
|
73
73
|
```
|
|
@@ -77,13 +77,27 @@ export class AppModule {}
|
|
|
77
77
|
```typescript
|
|
78
78
|
import { Activity, ActivityMethod } from 'nestjs-temporal-core';
|
|
79
79
|
|
|
80
|
-
@Activity(
|
|
80
|
+
@Activity({
|
|
81
|
+
name: 'PaymentActivities', // Optional custom name
|
|
82
|
+
description: 'Activities for payment processing',
|
|
83
|
+
})
|
|
81
84
|
export class PaymentActivity {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
+
}
|
|
87
101
|
}
|
|
88
102
|
```
|
|
89
103
|
|
|
@@ -93,12 +107,17 @@ export class PaymentActivity {
|
|
|
93
107
|
import { proxyActivities } from '@temporalio/workflow';
|
|
94
108
|
import type { PaymentActivity } from './payment.activity';
|
|
95
109
|
|
|
96
|
-
|
|
97
|
-
|
|
110
|
+
// Reference activities in your workflow
|
|
111
|
+
const { processPayment, refundPayment } = proxyActivities<PaymentActivity>({
|
|
112
|
+
startToCloseTimeout: '30 seconds',
|
|
98
113
|
});
|
|
99
114
|
|
|
100
115
|
export async function paymentWorkflow(amount: number): Promise<string> {
|
|
101
|
-
|
|
116
|
+
return await processPayment(amount);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export async function refundWorkflow(paymentId: string): Promise<boolean> {
|
|
120
|
+
return await refundPayment(paymentId);
|
|
102
121
|
}
|
|
103
122
|
```
|
|
104
123
|
|
|
@@ -110,18 +129,137 @@ import { TemporalClientService } from 'nestjs-temporal-core';
|
|
|
110
129
|
|
|
111
130
|
@Injectable()
|
|
112
131
|
export class PaymentService {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
+
```
|
|
165
|
+
|
|
166
|
+
## Advanced Features
|
|
167
|
+
|
|
168
|
+
### Class-Based Workflows with Queries and Signals
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import { Workflow, WorkflowMethod, Query, Signal } from 'nestjs-temporal-core';
|
|
172
|
+
|
|
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
|
+
}
|
|
125
263
|
}
|
|
126
264
|
```
|
|
127
265
|
|
|
@@ -129,114 +267,164 @@ export class PaymentService {
|
|
|
129
267
|
|
|
130
268
|
### Async Configuration
|
|
131
269
|
|
|
270
|
+
Use factory patterns for dynamic configuration:
|
|
271
|
+
|
|
132
272
|
```typescript
|
|
133
273
|
TemporalWorkerModule.registerAsync({
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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],
|
|
151
291
|
});
|
|
152
292
|
```
|
|
153
293
|
|
|
154
294
|
### TLS Configuration
|
|
155
295
|
|
|
296
|
+
Set up secure communications with TLS:
|
|
297
|
+
|
|
156
298
|
```typescript
|
|
157
299
|
TemporalClientModule.register({
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
|
165
312
|
},
|
|
166
|
-
|
|
167
|
-
|
|
313
|
+
namespace: 'production',
|
|
314
|
+
allowConnectionFailure: true, // Allow application to start if Temporal connection fails
|
|
168
315
|
});
|
|
169
316
|
```
|
|
170
317
|
|
|
171
|
-
|
|
318
|
+
### Worker Monitoring
|
|
172
319
|
|
|
173
|
-
|
|
320
|
+
Enable worker monitoring and metrics:
|
|
174
321
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
+
},
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
```
|
|
178
337
|
|
|
179
|
-
|
|
338
|
+
## API Reference
|
|
180
339
|
|
|
181
|
-
|
|
340
|
+
### Core Modules
|
|
182
341
|
|
|
183
|
-
- `
|
|
184
|
-
- `
|
|
185
|
-
- `
|
|
186
|
-
- `getWorkflowHandle()`: Get a handle to manage a workflow
|
|
187
|
-
- `getWorkflowClient()`: Get the underlying workflow client instance
|
|
342
|
+
- `TemporalClientModule` - Client connectivity for workflow operations
|
|
343
|
+
- `TemporalWorkerModule` - Worker process for running activities
|
|
344
|
+
- `TemporalScheduleModule` - Scheduling for recurring workflows
|
|
188
345
|
|
|
189
|
-
|
|
346
|
+
### Decorators
|
|
190
347
|
|
|
191
|
-
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
|
195
355
|
|
|
196
|
-
###
|
|
356
|
+
### Services
|
|
197
357
|
|
|
198
|
-
####
|
|
358
|
+
#### TemporalClientService
|
|
199
359
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
|
211
380
|
|
|
212
|
-
####
|
|
381
|
+
#### WorkerManager
|
|
213
382
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
namespace?: string;
|
|
218
|
-
}
|
|
219
|
-
```
|
|
383
|
+
- `startWorker()` - Manually start the worker
|
|
384
|
+
- `shutdown()` - Gracefully shutdown the worker
|
|
385
|
+
- `getWorker()` - Get the underlying worker instance
|
|
220
386
|
|
|
221
387
|
## Error Handling
|
|
222
388
|
|
|
223
389
|
The module includes comprehensive error handling:
|
|
224
390
|
|
|
225
|
-
- Worker initialization errors are logged and
|
|
391
|
+
- Worker initialization errors are logged and handled based on configuration
|
|
226
392
|
- Client operations include detailed error messages and proper error propagation
|
|
227
|
-
-
|
|
393
|
+
- Activities and workflow errors are properly captured and logged
|
|
228
394
|
- Connection errors are handled gracefully with automatic cleanup
|
|
395
|
+
- Configurable failure modes for both client and worker connections
|
|
229
396
|
|
|
230
397
|
## Best Practices
|
|
231
398
|
|
|
232
|
-
1.
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
399
|
+
1. **Activity Design**
|
|
400
|
+
|
|
401
|
+
- Define activity interfaces for type safety
|
|
402
|
+
- Keep activities focused on single responsibilities
|
|
403
|
+
- Set appropriate timeouts for expected durations
|
|
404
|
+
|
|
405
|
+
2. **Workflow Design**
|
|
406
|
+
|
|
407
|
+
- Make workflows deterministic
|
|
408
|
+
- Use signals for external events
|
|
409
|
+
- Use queries for retrieving workflow state
|
|
410
|
+
- Avoid side effects in workflow code
|
|
411
|
+
|
|
412
|
+
3. **Configuration**
|
|
413
|
+
|
|
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
|
|
418
|
+
|
|
419
|
+
4. **Lifecycle Management**
|
|
420
|
+
|
|
421
|
+
- Enable NestJS shutdown hooks
|
|
422
|
+
- Configure proper worker shutdown grace periods
|
|
423
|
+
- Use the WorkerManager service for controlling worker lifecycle
|
|
424
|
+
|
|
425
|
+
5. **Security**
|
|
426
|
+
- Implement proper TLS security for production environments
|
|
427
|
+
- Use namespaces to isolate different environments
|
|
240
428
|
|
|
241
429
|
## Contributing
|
|
242
430
|
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGA,2DAAyC;AACzC,4DAA0C"}
|