nestjs-temporal-core 3.0.10 → 3.0.12
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/CHANGELOG.md +80 -0
- package/README.md +1755 -693
- package/dist/constants.d.ts +49 -151
- package/dist/constants.js +38 -141
- package/dist/constants.js.map +1 -1
- package/dist/decorators/activity.decorator.js +75 -15
- package/dist/decorators/activity.decorator.js.map +1 -1
- package/dist/decorators/index.d.ts +1 -3
- package/dist/decorators/index.js +4 -13
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/workflow.decorator.d.ts +7 -3
- package/dist/decorators/workflow.decorator.js +161 -48
- package/dist/decorators/workflow.decorator.js.map +1 -1
- package/dist/health/temporal-health.controller.d.ts +7 -0
- package/dist/health/temporal-health.controller.js +77 -0
- package/dist/health/temporal-health.controller.js.map +1 -0
- package/dist/health/temporal-health.module.d.ts +2 -0
- package/dist/health/temporal-health.module.js +20 -0
- package/dist/health/temporal-health.module.js.map +1 -0
- package/dist/index.d.ts +10 -20
- package/dist/index.js +15 -30
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +773 -160
- package/dist/interfaces.js +1 -2
- package/dist/interfaces.js.map +1 -1
- package/dist/providers/temporal-connection.factory.d.ts +28 -0
- package/dist/providers/temporal-connection.factory.js +194 -0
- package/dist/providers/temporal-connection.factory.js.map +1 -0
- package/dist/services/temporal-client.service.d.ts +33 -0
- package/dist/services/temporal-client.service.js +285 -0
- package/dist/services/temporal-client.service.js.map +1 -0
- package/dist/services/temporal-discovery.service.d.ts +34 -0
- package/dist/services/temporal-discovery.service.js +348 -0
- package/dist/services/temporal-discovery.service.js.map +1 -0
- package/dist/services/temporal-metadata.service.d.ts +37 -0
- package/dist/services/temporal-metadata.service.js +512 -0
- package/dist/services/temporal-metadata.service.js.map +1 -0
- package/dist/services/temporal-schedule.service.d.ts +35 -0
- package/dist/services/temporal-schedule.service.js +380 -0
- package/dist/services/temporal-schedule.service.js.map +1 -0
- package/dist/services/temporal-worker.service.d.ts +67 -0
- package/dist/services/temporal-worker.service.js +845 -0
- package/dist/services/temporal-worker.service.js.map +1 -0
- package/dist/services/temporal.service.d.ts +92 -0
- package/dist/services/temporal.service.js +621 -0
- package/dist/services/temporal.service.js.map +1 -0
- package/dist/temporal.module.d.ts +6 -9
- package/dist/temporal.module.js +160 -109
- package/dist/temporal.module.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +5 -8
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/logger.d.ts +10 -4
- package/dist/utils/logger.js +77 -106
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/metadata.d.ts +1 -3
- package/dist/utils/metadata.js +8 -18
- package/dist/utils/metadata.js.map +1 -1
- package/dist/utils/validation.d.ts +16 -2
- package/dist/utils/validation.js +103 -9
- package/dist/utils/validation.js.map +1 -1
- package/package.json +37 -26
- package/dist/activity/index.d.ts +0 -2
- package/dist/activity/index.js +0 -19
- package/dist/activity/index.js.map +0 -1
- package/dist/activity/temporal-activity.module.d.ts +0 -11
- package/dist/activity/temporal-activity.module.js +0 -52
- package/dist/activity/temporal-activity.module.js.map +0 -1
- package/dist/activity/temporal-activity.service.d.ts +0 -46
- package/dist/activity/temporal-activity.service.js +0 -192
- package/dist/activity/temporal-activity.service.js.map +0 -1
- package/dist/client/index.d.ts +0 -3
- package/dist/client/index.js +0 -20
- package/dist/client/index.js.map +0 -1
- package/dist/client/temporal-client.module.d.ts +0 -18
- package/dist/client/temporal-client.module.js +0 -198
- package/dist/client/temporal-client.module.js.map +0 -1
- package/dist/client/temporal-client.service.d.ts +0 -35
- package/dist/client/temporal-client.service.js +0 -187
- package/dist/client/temporal-client.service.js.map +0 -1
- package/dist/client/temporal-schedule.service.d.ts +0 -41
- package/dist/client/temporal-schedule.service.js +0 -204
- package/dist/client/temporal-schedule.service.js.map +0 -1
- package/dist/decorators/parameter.decorator.d.ts +0 -5
- package/dist/decorators/parameter.decorator.js +0 -57
- package/dist/decorators/parameter.decorator.js.map +0 -1
- package/dist/decorators/scheduling.decorator.d.ts +0 -4
- package/dist/decorators/scheduling.decorator.js +0 -44
- package/dist/decorators/scheduling.decorator.js.map +0 -1
- package/dist/discovery/index.d.ts +0 -2
- package/dist/discovery/index.js +0 -19
- package/dist/discovery/index.js.map +0 -1
- package/dist/discovery/temporal-discovery.service.d.ts +0 -39
- package/dist/discovery/temporal-discovery.service.js +0 -191
- package/dist/discovery/temporal-discovery.service.js.map +0 -1
- package/dist/discovery/temporal-schedule-manager.service.d.ts +0 -41
- package/dist/discovery/temporal-schedule-manager.service.js +0 -238
- package/dist/discovery/temporal-schedule-manager.service.js.map +0 -1
- package/dist/schedules/index.d.ts +0 -2
- package/dist/schedules/index.js +0 -19
- package/dist/schedules/index.js.map +0 -1
- package/dist/schedules/temporal-schedules.module.d.ts +0 -11
- package/dist/schedules/temporal-schedules.module.js +0 -55
- package/dist/schedules/temporal-schedules.module.js.map +0 -1
- package/dist/schedules/temporal-schedules.service.d.ts +0 -52
- package/dist/schedules/temporal-schedules.service.js +0 -221
- package/dist/schedules/temporal-schedules.service.js.map +0 -1
- package/dist/temporal.service.d.ts +0 -77
- package/dist/temporal.service.js +0 -243
- package/dist/temporal.service.js.map +0 -1
- package/dist/worker/index.d.ts +0 -3
- package/dist/worker/index.js +0 -20
- package/dist/worker/index.js.map +0 -1
- package/dist/worker/temporal-metadata.accessor.d.ts +0 -32
- package/dist/worker/temporal-metadata.accessor.js +0 -208
- package/dist/worker/temporal-metadata.accessor.js.map +0 -1
- package/dist/worker/temporal-worker-manager.service.d.ts +0 -49
- package/dist/worker/temporal-worker-manager.service.js +0 -389
- package/dist/worker/temporal-worker-manager.service.js.map +0 -1
- package/dist/worker/temporal-worker.module.d.ts +0 -18
- package/dist/worker/temporal-worker.module.js +0 -156
- package/dist/worker/temporal-worker.module.js.map +0 -1
package/dist/interfaces.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Worker = exports.Client =
|
|
3
|
+
exports.Worker = exports.Client = void 0;
|
|
4
4
|
var client_1 = require("@temporalio/client");
|
|
5
|
-
Object.defineProperty(exports, "ScheduleOverlapPolicy", { enumerable: true, get: function () { return client_1.ScheduleOverlapPolicy; } });
|
|
6
5
|
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
|
|
7
6
|
var worker_1 = require("@temporalio/worker");
|
|
8
7
|
Object.defineProperty(exports, "Worker", { enumerable: true, get: function () { return worker_1.Worker; } });
|
package/dist/interfaces.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;;AACA,6CAI4B;AAFxB,gGAAA,MAAM,OAAA;AAGV,6CAA4C;AAAnC,gGAAA,MAAM,OAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { OnModuleDestroy } from '@nestjs/common';
|
|
2
|
+
import { Client } from '@temporalio/client';
|
|
3
|
+
import { NativeConnection } from '@temporalio/worker';
|
|
4
|
+
import { TemporalOptions } from '../interfaces';
|
|
5
|
+
export declare class TemporalConnectionFactory implements OnModuleDestroy {
|
|
6
|
+
private readonly logger;
|
|
7
|
+
private clientConnectionCache;
|
|
8
|
+
private workerConnectionCache;
|
|
9
|
+
private connectionAttempts;
|
|
10
|
+
private readonly MAX_RETRY_ATTEMPTS;
|
|
11
|
+
private readonly RETRY_DELAY_MS;
|
|
12
|
+
constructor();
|
|
13
|
+
createClient(options: TemporalOptions): Promise<Client | null>;
|
|
14
|
+
createWorkerConnection(options: TemporalOptions): Promise<NativeConnection | null>;
|
|
15
|
+
onModuleDestroy(): Promise<void>;
|
|
16
|
+
cleanup(): Promise<void>;
|
|
17
|
+
getConnectionHealth(): {
|
|
18
|
+
clientConnections: number;
|
|
19
|
+
workerConnections: number;
|
|
20
|
+
totalAttempts: number;
|
|
21
|
+
};
|
|
22
|
+
private createNewClient;
|
|
23
|
+
private createNewWorkerConnection;
|
|
24
|
+
private getConnectionKey;
|
|
25
|
+
private isClientHealthy;
|
|
26
|
+
private isWorkerConnectionHealthy;
|
|
27
|
+
private delay;
|
|
28
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var TemporalConnectionFactory_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.TemporalConnectionFactory = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const client_1 = require("@temporalio/client");
|
|
16
|
+
const logger_1 = require("../utils/logger");
|
|
17
|
+
let TemporalConnectionFactory = TemporalConnectionFactory_1 = class TemporalConnectionFactory {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.clientConnectionCache = new Map();
|
|
20
|
+
this.workerConnectionCache = new Map();
|
|
21
|
+
this.connectionAttempts = new Map();
|
|
22
|
+
this.MAX_RETRY_ATTEMPTS = 3;
|
|
23
|
+
this.RETRY_DELAY_MS = 1000;
|
|
24
|
+
this.logger = (0, logger_1.createLogger)(TemporalConnectionFactory_1.name);
|
|
25
|
+
}
|
|
26
|
+
async createClient(options) {
|
|
27
|
+
if (!options.connection) {
|
|
28
|
+
this.logger.info('No connection configuration provided - running without client');
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const connectionKey = this.getConnectionKey(options.connection);
|
|
32
|
+
const cachedClient = this.clientConnectionCache.get(connectionKey);
|
|
33
|
+
if (cachedClient && this.isClientHealthy(cachedClient)) {
|
|
34
|
+
this.logger.debug('Reusing cached client connection');
|
|
35
|
+
return cachedClient;
|
|
36
|
+
}
|
|
37
|
+
if (cachedClient) {
|
|
38
|
+
this.clientConnectionCache.delete(connectionKey);
|
|
39
|
+
}
|
|
40
|
+
return this.createNewClient(options, connectionKey);
|
|
41
|
+
}
|
|
42
|
+
async createWorkerConnection(options) {
|
|
43
|
+
if (!options.connection) {
|
|
44
|
+
this.logger.debug('No connection configuration provided for worker');
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const connectionKey = this.getConnectionKey(options.connection);
|
|
48
|
+
const cachedConnection = this.workerConnectionCache.get(connectionKey);
|
|
49
|
+
if (cachedConnection && this.isWorkerConnectionHealthy(cachedConnection)) {
|
|
50
|
+
this.logger.debug('Reusing cached worker connection');
|
|
51
|
+
return cachedConnection;
|
|
52
|
+
}
|
|
53
|
+
if (cachedConnection) {
|
|
54
|
+
try {
|
|
55
|
+
await cachedConnection.close();
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
this.logger.warn('Failed to close unhealthy worker connection', error);
|
|
59
|
+
}
|
|
60
|
+
this.workerConnectionCache.delete(connectionKey);
|
|
61
|
+
}
|
|
62
|
+
return this.createNewWorkerConnection(options, connectionKey);
|
|
63
|
+
}
|
|
64
|
+
async onModuleDestroy() {
|
|
65
|
+
await this.cleanup();
|
|
66
|
+
}
|
|
67
|
+
async cleanup() {
|
|
68
|
+
this.logger.info('Cleaning up all connections...');
|
|
69
|
+
const workerCleanupPromises = Array.from(this.workerConnectionCache.values()).map(async (connection) => {
|
|
70
|
+
try {
|
|
71
|
+
await connection.close();
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
this.logger.warn('Failed to close worker connection during cleanup', error);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
await Promise.allSettled(workerCleanupPromises);
|
|
78
|
+
this.clientConnectionCache.clear();
|
|
79
|
+
this.workerConnectionCache.clear();
|
|
80
|
+
this.connectionAttempts.clear();
|
|
81
|
+
this.logger.info('Connection cleanup completed');
|
|
82
|
+
}
|
|
83
|
+
getConnectionHealth() {
|
|
84
|
+
return {
|
|
85
|
+
clientConnections: this.clientConnectionCache.size,
|
|
86
|
+
workerConnections: this.workerConnectionCache.size,
|
|
87
|
+
totalAttempts: Array.from(this.connectionAttempts.values()).reduce((sum, attempts) => sum + attempts, 0),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async createNewClient(options, connectionKey) {
|
|
91
|
+
const attempts = this.connectionAttempts.get(connectionKey) || 0;
|
|
92
|
+
if (attempts >= this.MAX_RETRY_ATTEMPTS) {
|
|
93
|
+
if (options.allowConnectionFailure !== false) {
|
|
94
|
+
this.logger.warn(`Max retry attempts exceeded for ${options.connection.address} - running without client`);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
throw new Error(`Failed to connect to ${options.connection.address} after ${this.MAX_RETRY_ATTEMPTS} attempts`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
this.logger.info(`Creating new client connection to ${options.connection.address} (attempt ${attempts + 1})`);
|
|
103
|
+
const connection = await client_1.Connection.lazy({
|
|
104
|
+
address: options.connection.address,
|
|
105
|
+
tls: options.connection.tls,
|
|
106
|
+
metadata: options.connection.metadata,
|
|
107
|
+
...(options.connection.apiKey && {
|
|
108
|
+
metadata: {
|
|
109
|
+
...(options.connection.metadata || {}),
|
|
110
|
+
authorization: `Bearer ${options.connection.apiKey}`,
|
|
111
|
+
},
|
|
112
|
+
}),
|
|
113
|
+
});
|
|
114
|
+
const client = new client_1.Client({
|
|
115
|
+
connection,
|
|
116
|
+
namespace: options.connection.namespace || 'default',
|
|
117
|
+
});
|
|
118
|
+
this.clientConnectionCache.set(connectionKey, client);
|
|
119
|
+
this.connectionAttempts.delete(connectionKey);
|
|
120
|
+
logger_1.LoggerUtils.logConnection(this.logger, options.connection.address, true);
|
|
121
|
+
return client;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
this.connectionAttempts.set(connectionKey, attempts + 1);
|
|
125
|
+
logger_1.LoggerUtils.logConnection(this.logger, options.connection.address, false, error);
|
|
126
|
+
if (attempts + 1 < this.MAX_RETRY_ATTEMPTS) {
|
|
127
|
+
this.logger.info(`Retrying connection in ${this.RETRY_DELAY_MS}ms...`);
|
|
128
|
+
await this.delay(this.RETRY_DELAY_MS);
|
|
129
|
+
return this.createNewClient(options, connectionKey);
|
|
130
|
+
}
|
|
131
|
+
if (options.allowConnectionFailure !== false) {
|
|
132
|
+
this.logger.warn('Client connection failed - continuing without client');
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async createNewWorkerConnection(options, connectionKey) {
|
|
139
|
+
try {
|
|
140
|
+
this.logger.debug(`Creating new worker connection to ${options.connection.address}`);
|
|
141
|
+
const { NativeConnection } = await Promise.resolve().then(() => require('@temporalio/worker'));
|
|
142
|
+
const address = options.connection.address;
|
|
143
|
+
const connectOptions = {
|
|
144
|
+
address,
|
|
145
|
+
tls: options.connection.tls,
|
|
146
|
+
};
|
|
147
|
+
if (options.connection.apiKey) {
|
|
148
|
+
connectOptions.metadata = {
|
|
149
|
+
...(options.connection.metadata || {}),
|
|
150
|
+
authorization: `Bearer ${options.connection.apiKey}`,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const connection = await NativeConnection.connect(connectOptions);
|
|
154
|
+
this.workerConnectionCache.set(connectionKey, connection);
|
|
155
|
+
this.logger.info(`Worker connection established to ${address}`);
|
|
156
|
+
return connection;
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
this.logger.warn('Failed to create worker connection, returning null', error);
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
getConnectionKey(connection) {
|
|
164
|
+
return `${connection.address}:${connection.namespace || 'default'}:${connection.apiKey ? 'auth' : 'noauth'}`;
|
|
165
|
+
}
|
|
166
|
+
isClientHealthy(client) {
|
|
167
|
+
try {
|
|
168
|
+
return Boolean(client.workflow);
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
isWorkerConnectionHealthy(connection) {
|
|
175
|
+
try {
|
|
176
|
+
return (connection !== null &&
|
|
177
|
+
connection !== undefined &&
|
|
178
|
+
typeof connection === 'object' &&
|
|
179
|
+
connection.constructor !== undefined);
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
delay(ms) {
|
|
186
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
exports.TemporalConnectionFactory = TemporalConnectionFactory;
|
|
190
|
+
exports.TemporalConnectionFactory = TemporalConnectionFactory = TemporalConnectionFactory_1 = __decorate([
|
|
191
|
+
(0, common_1.Injectable)(),
|
|
192
|
+
__metadata("design:paramtypes", [])
|
|
193
|
+
], TemporalConnectionFactory);
|
|
194
|
+
//# sourceMappingURL=temporal-connection.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporal-connection.factory.js","sourceRoot":"","sources":["../../src/providers/temporal-connection.factory.ts"],"names":[],"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rC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { Client, WorkflowHandle } from '@temporalio/client';
|
|
3
|
+
import { TemporalOptions, WorkflowStartOptions, WorkflowHandleWithMetadata, ClientServiceStatus, ClientHealthStatus } from '../interfaces';
|
|
4
|
+
export declare class TemporalClientService implements OnModuleInit {
|
|
5
|
+
private readonly temporalClient;
|
|
6
|
+
private readonly options;
|
|
7
|
+
private readonly logger;
|
|
8
|
+
private client;
|
|
9
|
+
private isInitialized;
|
|
10
|
+
private lastHealthCheck;
|
|
11
|
+
private healthCheckInterval;
|
|
12
|
+
constructor(temporalClient: Client | null, options: TemporalOptions);
|
|
13
|
+
onModuleInit(): Promise<void>;
|
|
14
|
+
startWorkflow(workflowType: string, args?: unknown[], options?: WorkflowStartOptions): Promise<WorkflowHandleWithMetadata>;
|
|
15
|
+
getWorkflowHandle(workflowId: string, runId?: string): Promise<WorkflowHandle>;
|
|
16
|
+
terminateWorkflow(workflowId: string, reason?: string, runId?: string): Promise<void>;
|
|
17
|
+
cancelWorkflow(workflowId: string, runId?: string): Promise<void>;
|
|
18
|
+
signalWorkflow(workflowId: string, signalName: string, args?: unknown[], runId?: string): Promise<void>;
|
|
19
|
+
signalWorkflowHandle(handle: WorkflowHandle, signalName: string, args?: unknown[]): Promise<void>;
|
|
20
|
+
queryWorkflow<T = unknown>(workflowId: string, queryName: string, args?: unknown[], runId?: string): Promise<T>;
|
|
21
|
+
queryWorkflowHandle<T = unknown>(handle: WorkflowHandle, queryName: string, args?: unknown[]): Promise<T>;
|
|
22
|
+
getWorkflowResult<T = unknown>(workflowId: string, runId?: string): Promise<T>;
|
|
23
|
+
isHealthy(): boolean;
|
|
24
|
+
getHealth(): ClientHealthStatus;
|
|
25
|
+
getStatus(): ClientServiceStatus;
|
|
26
|
+
getRawClient(): Client | null;
|
|
27
|
+
private performHealthCheck;
|
|
28
|
+
private ensureClientAvailable;
|
|
29
|
+
private generateWorkflowId;
|
|
30
|
+
private extractErrorMessage;
|
|
31
|
+
private isRetryableError;
|
|
32
|
+
private sleep;
|
|
33
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var TemporalClientService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.TemporalClientService = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const constants_1 = require("../constants");
|
|
19
|
+
const logger_1 = require("../utils/logger");
|
|
20
|
+
let TemporalClientService = TemporalClientService_1 = class TemporalClientService {
|
|
21
|
+
constructor(temporalClient, options) {
|
|
22
|
+
this.temporalClient = temporalClient;
|
|
23
|
+
this.options = options;
|
|
24
|
+
this.client = null;
|
|
25
|
+
this.isInitialized = false;
|
|
26
|
+
this.lastHealthCheck = null;
|
|
27
|
+
this.healthCheckInterval = 30000;
|
|
28
|
+
this.logger = (0, logger_1.createLogger)(TemporalClientService_1.name, {
|
|
29
|
+
enableLogger: options.enableLogger,
|
|
30
|
+
logLevel: options.logLevel,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async onModuleInit() {
|
|
34
|
+
try {
|
|
35
|
+
this.client = this.temporalClient;
|
|
36
|
+
if (this.client) {
|
|
37
|
+
this.isInitialized = true;
|
|
38
|
+
this.logger.info('Temporal client service initialized successfully');
|
|
39
|
+
this.logger.debug(`Client namespace: ${this.options?.connection?.namespace || 'default'}`);
|
|
40
|
+
await this.performHealthCheck();
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.logger.warn('No Temporal client available - running in client-less mode');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
this.logger.error('Failed to initialize Temporal client service', error);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async startWorkflow(workflowType, args = [], options) {
|
|
52
|
+
this.ensureClientAvailable();
|
|
53
|
+
const workflowId = options?.workflowId || this.generateWorkflowId(workflowType);
|
|
54
|
+
const taskQueue = options?.taskQueue || this.options.taskQueue || 'default';
|
|
55
|
+
const maxRetries = 3;
|
|
56
|
+
const baseRetryDelay = 1000;
|
|
57
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
58
|
+
try {
|
|
59
|
+
if (attempt > 1) {
|
|
60
|
+
this.logger.debug(`Performing health check before retry attempt ${attempt}`);
|
|
61
|
+
await this.performHealthCheck();
|
|
62
|
+
}
|
|
63
|
+
this.logger.debug(`Starting workflow '${workflowType}' with ID: ${workflowId}`);
|
|
64
|
+
const handle = await this.client.workflow.start(workflowType, {
|
|
65
|
+
workflowId,
|
|
66
|
+
taskQueue,
|
|
67
|
+
args,
|
|
68
|
+
});
|
|
69
|
+
this.logger.info(`Started workflow: ${workflowType} [${workflowId}] on queue: ${taskQueue}`);
|
|
70
|
+
return { ...handle, handle };
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
const message = this.extractErrorMessage(error);
|
|
74
|
+
const isRetryableError = this.isRetryableError(error, message);
|
|
75
|
+
if (isRetryableError && attempt < maxRetries) {
|
|
76
|
+
const retryDelay = baseRetryDelay * Math.pow(2, attempt - 1);
|
|
77
|
+
this.logger.warn(`Attempt ${attempt}/${maxRetries} failed for workflow '${workflowType}': ${message}. Retrying in ${retryDelay}ms...`);
|
|
78
|
+
this.logger.debug(`Error details for retry decision:`, error);
|
|
79
|
+
await this.sleep(retryDelay);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
this.logger.error(`Failed to start workflow '${workflowType}': ${message}`);
|
|
83
|
+
this.logger.error('Full error object:', error);
|
|
84
|
+
this.logger.debug(`Error details - Workflow: ${workflowType}, ID: ${workflowId}, Queue: ${taskQueue}, Retryable: ${isRetryableError}, Attempt: ${attempt}`);
|
|
85
|
+
throw new Error(`Failed to start workflow '${workflowType}': ${message}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
throw new Error(`Failed to start workflow '${workflowType}' after ${maxRetries} attempts`);
|
|
89
|
+
}
|
|
90
|
+
async getWorkflowHandle(workflowId, runId) {
|
|
91
|
+
this.ensureClientAvailable();
|
|
92
|
+
try {
|
|
93
|
+
const handle = await this.client.workflow.getHandle(workflowId, runId);
|
|
94
|
+
this.logger.debug(`Retrieved workflow handle: ${workflowId}${runId ? ` (run: ${runId})` : ''}`);
|
|
95
|
+
return handle;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
const message = this.extractErrorMessage(error);
|
|
99
|
+
this.logger.error(`Failed to get workflow handle for ${workflowId}: ${message}`, error);
|
|
100
|
+
throw new Error(`Failed to get workflow handle for ${workflowId}: ${message}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async terminateWorkflow(workflowId, reason, runId) {
|
|
104
|
+
try {
|
|
105
|
+
const handle = await this.getWorkflowHandle(workflowId, runId);
|
|
106
|
+
await handle.terminate(reason);
|
|
107
|
+
this.logger.info(`Terminated workflow: ${workflowId}${reason ? ` (${reason})` : ''}`);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
const message = this.extractErrorMessage(error);
|
|
111
|
+
this.logger.error(`Failed to terminate workflow ${workflowId}: ${message}`, error);
|
|
112
|
+
throw new Error(`Failed to terminate workflow ${workflowId}: ${message}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async cancelWorkflow(workflowId, runId) {
|
|
116
|
+
try {
|
|
117
|
+
const handle = await this.getWorkflowHandle(workflowId, runId);
|
|
118
|
+
await handle.cancel();
|
|
119
|
+
this.logger.info(`Cancelled workflow: ${workflowId}`);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
const message = this.extractErrorMessage(error);
|
|
123
|
+
this.logger.error(`Failed to cancel workflow ${workflowId}: ${message}`, error);
|
|
124
|
+
throw new Error(`Failed to cancel workflow ${workflowId}: ${message}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async signalWorkflow(workflowId, signalName, args, runId) {
|
|
128
|
+
try {
|
|
129
|
+
const handle = await this.getWorkflowHandle(workflowId, runId);
|
|
130
|
+
await handle.signal(signalName, ...(args || []));
|
|
131
|
+
this.logger.debug(`Sent signal '${signalName}' to workflow: ${workflowId}`);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
const message = this.extractErrorMessage(error);
|
|
135
|
+
this.logger.error(`Failed to send signal '${signalName}' to workflow ${workflowId}: ${message}`, error);
|
|
136
|
+
throw new Error(`Failed to send signal '${signalName}' to workflow ${workflowId}: ${message}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async signalWorkflowHandle(handle, signalName, args) {
|
|
140
|
+
try {
|
|
141
|
+
await handle.signal(signalName, ...(args || []));
|
|
142
|
+
this.logger.debug(`Sent signal '${signalName}' to workflow handle`);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
this.logger.error(`Failed to send signal '${signalName}': ${this.extractErrorMessage(error)}`, error);
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async queryWorkflow(workflowId, queryName, args, runId) {
|
|
150
|
+
try {
|
|
151
|
+
const handle = await this.getWorkflowHandle(workflowId, runId);
|
|
152
|
+
const result = await handle.query(queryName, ...(args || []));
|
|
153
|
+
this.logger.debug(`Queried '${queryName}' from workflow: ${workflowId}`);
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
const message = this.extractErrorMessage(error);
|
|
158
|
+
this.logger.error(`Failed to query '${queryName}' on workflow ${workflowId}: ${message}`, error);
|
|
159
|
+
throw new Error(`Failed to query '${queryName}' on workflow ${workflowId}: ${message}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async queryWorkflowHandle(handle, queryName, args) {
|
|
163
|
+
try {
|
|
164
|
+
const result = await handle.query(queryName, ...(args || []));
|
|
165
|
+
this.logger.debug(`Queried '${queryName}' from workflow handle`);
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
this.logger.error(`Failed to query '${queryName}': ${this.extractErrorMessage(error)}`, error);
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async getWorkflowResult(workflowId, runId) {
|
|
174
|
+
try {
|
|
175
|
+
const handle = await this.getWorkflowHandle(workflowId, runId);
|
|
176
|
+
const result = await handle.result();
|
|
177
|
+
this.logger.debug(`Retrieved result from workflow: ${workflowId}`);
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
this.logger.error(`Failed to get result from ${workflowId}: ${this.extractErrorMessage(error)}`, error);
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
isHealthy() {
|
|
186
|
+
if (!this.isInitialized || !this.client) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
const now = new Date();
|
|
190
|
+
if (!this.lastHealthCheck ||
|
|
191
|
+
now.getTime() - this.lastHealthCheck.getTime() > this.healthCheckInterval) {
|
|
192
|
+
this.performHealthCheck().catch((error) => {
|
|
193
|
+
this.logger.warn('Health check failed', error);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return Boolean(this.client.workflow);
|
|
197
|
+
}
|
|
198
|
+
getHealth() {
|
|
199
|
+
return { status: this.isHealthy() ? 'healthy' : 'unhealthy' };
|
|
200
|
+
}
|
|
201
|
+
getStatus() {
|
|
202
|
+
return {
|
|
203
|
+
available: this.client !== null,
|
|
204
|
+
healthy: this.isHealthy(),
|
|
205
|
+
initialized: this.isInitialized,
|
|
206
|
+
lastHealthCheck: this.lastHealthCheck,
|
|
207
|
+
namespace: this.options.connection?.namespace || 'default',
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
getRawClient() {
|
|
211
|
+
return this.client;
|
|
212
|
+
}
|
|
213
|
+
async performHealthCheck() {
|
|
214
|
+
if (!this.client) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
if (!this.client) {
|
|
219
|
+
throw new Error('Client is not initialized');
|
|
220
|
+
}
|
|
221
|
+
this.lastHealthCheck = new Date();
|
|
222
|
+
this.logger.debug('Client health check passed');
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
this.logger.warn('Client health check failed', error);
|
|
226
|
+
throw error;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
ensureClientAvailable() {
|
|
230
|
+
if (!this.client) {
|
|
231
|
+
throw new Error('Temporal client not initialized');
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
generateWorkflowId(workflowType) {
|
|
235
|
+
const timestamp = Date.now();
|
|
236
|
+
const random = Math.random().toString(36).substring(2, 8);
|
|
237
|
+
return `${workflowType}-${timestamp}-${random}`;
|
|
238
|
+
}
|
|
239
|
+
extractErrorMessage(error) {
|
|
240
|
+
if (error instanceof Error) {
|
|
241
|
+
return error.message;
|
|
242
|
+
}
|
|
243
|
+
if (typeof error === 'string') {
|
|
244
|
+
return error;
|
|
245
|
+
}
|
|
246
|
+
return 'Unknown error';
|
|
247
|
+
}
|
|
248
|
+
isRetryableError(error, message) {
|
|
249
|
+
const gRpcErrorPatterns = [
|
|
250
|
+
'Unexpected error while making gRPC request',
|
|
251
|
+
'connection error',
|
|
252
|
+
'UNAVAILABLE',
|
|
253
|
+
'DEADLINE_EXCEEDED',
|
|
254
|
+
'RESOURCE_EXHAUSTED',
|
|
255
|
+
'INTERNAL',
|
|
256
|
+
'Service unavailable',
|
|
257
|
+
'Connection refused',
|
|
258
|
+
'Network error',
|
|
259
|
+
'timeout',
|
|
260
|
+
'ECONNRESET',
|
|
261
|
+
'ECONNREFUSED',
|
|
262
|
+
'ETIMEDOUT',
|
|
263
|
+
];
|
|
264
|
+
const messageMatch = gRpcErrorPatterns.some((pattern) => message.toLowerCase().includes(pattern.toLowerCase()));
|
|
265
|
+
if (error && typeof error === 'object' && 'code' in error) {
|
|
266
|
+
const grpcCode = error.code;
|
|
267
|
+
const retryableGrpcCodes = [1, 2, 4, 8, 10, 13, 14];
|
|
268
|
+
if (typeof grpcCode === 'number' && retryableGrpcCodes.includes(grpcCode)) {
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return messageMatch;
|
|
273
|
+
}
|
|
274
|
+
async sleep(ms) {
|
|
275
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
exports.TemporalClientService = TemporalClientService;
|
|
279
|
+
exports.TemporalClientService = TemporalClientService = TemporalClientService_1 = __decorate([
|
|
280
|
+
(0, common_1.Injectable)(),
|
|
281
|
+
__param(0, (0, common_1.Inject)(constants_1.TEMPORAL_CLIENT)),
|
|
282
|
+
__param(1, (0, common_1.Inject)(constants_1.TEMPORAL_MODULE_OPTIONS)),
|
|
283
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
284
|
+
], TemporalClientService);
|
|
285
|
+
//# sourceMappingURL=temporal-client.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporal-client.service.js","sourceRoot":"","sources":["../../src/services/temporal-client.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAkE;AAElE,4CAAwE;AAQxE,4CAA+D;AAwBxD,IAAM,qBAAqB,6BAA3B,MAAM,qBAAqB;IAO9B,YAEI,cAA8C,EAE9C,OAAyC;QAFxB,mBAAc,GAAd,cAAc,CAAe;QAE7B,YAAO,GAAP,OAAO,CAAiB;QATrC,WAAM,GAAkB,IAAI,CAAC;QAC7B,kBAAa,GAAG,KAAK,CAAC;QACtB,oBAAe,GAAgB,IAAI,CAAC;QACpC,wBAAmB,GAAW,KAAK,CAAC;QAQxC,IAAI,CAAC,MAAM,GAAG,IAAA,qBAAY,EAAC,uBAAqB,CAAC,IAAI,EAAE;YACnD,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,QAAQ,EAAE,OAAO,CAAC,QAAQ;SAC7B,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,YAAY;QACd,IAAI,CAAC;YACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC;YAElC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBACd,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;gBAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;gBACrE,IAAI,CAAC,MAAM,CAAC,KAAK,CACb,qBAAqB,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,SAAS,IAAI,SAAS,EAAE,CAC1E,CAAC;gBAGF,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACpC,CAAC;iBAAM,CAAC;gBACJ,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,4DAA4D,CAAC,CAAC;YACnF,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,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K,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;YACxD,MAAM,QAAQ,GAAI,KAA2B,CAAC,IAAI,CAAC;YAEnD,MAAM,kBAAkB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YACpD,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,kBAAkB,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACxE,OAAO,IAAI,CAAC;YAChB,CAAC;QACL,CAAC;QAED,OAAO,YAAY,CAAC;IACxB,CAAC;IAEO,KAAK,CAAC,KAAK,CAAC,EAAU;QAC1B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC;CACJ,CAAA;AArZY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;IASJ,WAAA,IAAA,eAAM,EAAC,2BAAe,CAAC,CAAA;IAEvB,WAAA,IAAA,eAAM,EAAC,mCAAuB,CAAC,CAAA;;GAV3B,qBAAqB,CAqZjC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { DiscoveryService } from '@nestjs/core';
|
|
3
|
+
import { TemporalOptions, ActivityModuleOptions, ActivityMethodHandler, DiscoveredActivity, DiscoveryServiceStats, DiscoveryHealthStatus, ActivityExecutionResult, ComponentDiscoveryResult } from '../interfaces';
|
|
4
|
+
import { TemporalMetadataAccessor } from './temporal-metadata.service';
|
|
5
|
+
export declare class TemporalDiscoveryService implements OnModuleInit {
|
|
6
|
+
private readonly discoveryService;
|
|
7
|
+
private readonly metadataAccessor;
|
|
8
|
+
private readonly options;
|
|
9
|
+
private readonly activityModuleOptions;
|
|
10
|
+
private readonly logger;
|
|
11
|
+
private readonly discoveredActivities;
|
|
12
|
+
private isDiscoveryComplete;
|
|
13
|
+
private discoveryStartTime;
|
|
14
|
+
private lastDiscoveryTime;
|
|
15
|
+
constructor(discoveryService: DiscoveryService, metadataAccessor: TemporalMetadataAccessor | undefined, options: TemporalOptions, activityModuleOptions?: ActivityModuleOptions);
|
|
16
|
+
onModuleInit(): Promise<void>;
|
|
17
|
+
getDiscoveredActivities(): Map<string, DiscoveredActivity>;
|
|
18
|
+
getActivity(name: string): ActivityMethodHandler | undefined;
|
|
19
|
+
getAllActivities(): Record<string, ActivityMethodHandler>;
|
|
20
|
+
hasActivity(name: string): boolean;
|
|
21
|
+
getActivityNames(): string[];
|
|
22
|
+
executeActivity(name: string, ...args: unknown[]): Promise<ActivityExecutionResult>;
|
|
23
|
+
rediscover(): Promise<ComponentDiscoveryResult>;
|
|
24
|
+
getStats(): DiscoveryServiceStats;
|
|
25
|
+
getHealthStatus(): DiscoveryHealthStatus;
|
|
26
|
+
private discoverComponents;
|
|
27
|
+
private processWrapper;
|
|
28
|
+
private discoverActivitiesInClass;
|
|
29
|
+
private clearDiscoveredComponents;
|
|
30
|
+
private getTotalDiscovered;
|
|
31
|
+
private getWrapperName;
|
|
32
|
+
private logDiscoveryResults;
|
|
33
|
+
private logDiscoveredComponents;
|
|
34
|
+
}
|