nestjs-temporal-core 2.0.0
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/LICENSE +21 -0
- package/README.md +213 -0
- package/dist/constants.d.ts +5 -0
- package/dist/constants.js +9 -0
- package/dist/constants.js.map +1 -0
- package/dist/decorators/activity-method.decorator.d.ts +4 -0
- package/dist/decorators/activity-method.decorator.js +15 -0
- package/dist/decorators/activity-method.decorator.js.map +1 -0
- package/dist/decorators/activity.decorator.d.ts +4 -0
- package/dist/decorators/activity.decorator.js +16 -0
- package/dist/decorators/activity.decorator.js.map +1 -0
- package/dist/decorators/index.d.ts +4 -0
- package/dist/decorators/index.js +21 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/inject-temporal-client.decorator.d.ts +1 -0
- package/dist/decorators/inject-temporal-client.decorator.js +8 -0
- package/dist/decorators/inject-temporal-client.decorator.js.map +1 -0
- package/dist/decorators/workflow.decorator.d.ts +2 -0
- package/dist/decorators/workflow.decorator.js +13 -0
- package/dist/decorators/workflow.decorator.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/base.interface.d.ts +13 -0
- package/dist/interfaces/base.interface.js +3 -0
- package/dist/interfaces/base.interface.js.map +1 -0
- package/dist/interfaces/client.interface.d.ts +15 -0
- package/dist/interfaces/client.interface.js +3 -0
- package/dist/interfaces/client.interface.js.map +1 -0
- package/dist/interfaces/index.d.ts +3 -0
- package/dist/interfaces/index.js +20 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/worker.interface.d.ts +19 -0
- package/dist/interfaces/worker.interface.js +3 -0
- package/dist/interfaces/worker.interface.js.map +1 -0
- package/dist/temporal-client.module.d.ts +10 -0
- package/dist/temporal-client.module.js +138 -0
- package/dist/temporal-client.module.js.map +1 -0
- package/dist/temporal-client.service.d.ts +22 -0
- package/dist/temporal-client.service.js +118 -0
- package/dist/temporal-client.service.js.map +1 -0
- package/dist/temporal-metadata.accessor.d.ts +5 -0
- package/dist/temporal-metadata.accessor.js +35 -0
- package/dist/temporal-metadata.accessor.js.map +1 -0
- package/dist/temporal-worker.module.d.ts +8 -0
- package/dist/temporal-worker.module.js +270 -0
- package/dist/temporal-worker.module.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +86 -0
|
@@ -0,0 +1,138 @@
|
|
|
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 TemporalClientModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.TemporalClientModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const client_1 = require("@temporalio/client");
|
|
13
|
+
const constants_1 = require("./constants");
|
|
14
|
+
const temporal_client_service_1 = require("./temporal-client.service");
|
|
15
|
+
let TemporalClientModule = exports.TemporalClientModule = TemporalClientModule_1 = class TemporalClientModule {
|
|
16
|
+
static async createClient(options) {
|
|
17
|
+
this.logger.log('Initializing Temporal client', {
|
|
18
|
+
address: options.connection.address,
|
|
19
|
+
namespace: options.namespace || 'default',
|
|
20
|
+
});
|
|
21
|
+
try {
|
|
22
|
+
const connection = await client_1.Connection.connect({
|
|
23
|
+
address: options.connection.address,
|
|
24
|
+
tls: options.connection.tls,
|
|
25
|
+
});
|
|
26
|
+
const client = new client_1.Client({
|
|
27
|
+
connection,
|
|
28
|
+
namespace: options.namespace || 'default',
|
|
29
|
+
});
|
|
30
|
+
this.logger.log('Temporal client initialized successfully');
|
|
31
|
+
return client;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
this.logger.error('Failed to initialize Temporal client', {
|
|
35
|
+
error: error.message,
|
|
36
|
+
stack: error.stack,
|
|
37
|
+
address: options.connection.address,
|
|
38
|
+
});
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
static register(options) {
|
|
43
|
+
const clientProvider = {
|
|
44
|
+
provide: constants_1.TEMPORAL_CLIENT,
|
|
45
|
+
useFactory: async () => {
|
|
46
|
+
const client = await this.createClient(options);
|
|
47
|
+
return this.addShutdownHook(client);
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
module: TemporalClientModule_1,
|
|
52
|
+
providers: [
|
|
53
|
+
{
|
|
54
|
+
provide: constants_1.TEMPORAL_MODULE_OPTIONS,
|
|
55
|
+
useValue: options,
|
|
56
|
+
},
|
|
57
|
+
clientProvider,
|
|
58
|
+
temporal_client_service_1.TemporalClientService,
|
|
59
|
+
],
|
|
60
|
+
exports: [temporal_client_service_1.TemporalClientService],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
static registerAsync(options) {
|
|
64
|
+
const clientProvider = {
|
|
65
|
+
provide: constants_1.TEMPORAL_CLIENT,
|
|
66
|
+
useFactory: async (clientOptions) => {
|
|
67
|
+
const client = await this.createClient(clientOptions);
|
|
68
|
+
return this.addShutdownHook(client);
|
|
69
|
+
},
|
|
70
|
+
inject: [constants_1.TEMPORAL_MODULE_OPTIONS],
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
module: TemporalClientModule_1,
|
|
74
|
+
imports: options.imports || [],
|
|
75
|
+
providers: [...this.createAsyncProviders(options), clientProvider, temporal_client_service_1.TemporalClientService],
|
|
76
|
+
exports: [temporal_client_service_1.TemporalClientService],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
static createAsyncProviders(options) {
|
|
80
|
+
if (options.useFactory) {
|
|
81
|
+
return [
|
|
82
|
+
{
|
|
83
|
+
provide: constants_1.TEMPORAL_MODULE_OPTIONS,
|
|
84
|
+
useFactory: options.useFactory,
|
|
85
|
+
inject: options.inject || [],
|
|
86
|
+
},
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
if (options.useClass) {
|
|
90
|
+
return [
|
|
91
|
+
{
|
|
92
|
+
provide: constants_1.TEMPORAL_MODULE_OPTIONS,
|
|
93
|
+
useFactory: async (optionsFactory) => await optionsFactory.createClientOptions(),
|
|
94
|
+
inject: [options.useClass],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
provide: options.useClass,
|
|
98
|
+
useClass: options.useClass,
|
|
99
|
+
},
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
if (options.useExisting) {
|
|
103
|
+
return [
|
|
104
|
+
{
|
|
105
|
+
provide: constants_1.TEMPORAL_MODULE_OPTIONS,
|
|
106
|
+
useFactory: async (optionsFactory) => await optionsFactory.createClientOptions(),
|
|
107
|
+
inject: [options.useExisting],
|
|
108
|
+
},
|
|
109
|
+
];
|
|
110
|
+
}
|
|
111
|
+
const error = new Error('Invalid TemporalClientAsyncOptions configuration');
|
|
112
|
+
this.logger.error(error.message);
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
static addShutdownHook(client) {
|
|
116
|
+
const enhancedClient = client;
|
|
117
|
+
enhancedClient.onApplicationShutdown = async () => {
|
|
118
|
+
try {
|
|
119
|
+
this.logger.log('Closing Temporal client connection');
|
|
120
|
+
await client.connection?.close();
|
|
121
|
+
this.logger.log('Temporal client connection closed successfully');
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
this.logger.error('Failed to close Temporal client connection', {
|
|
125
|
+
error: error.message,
|
|
126
|
+
stack: error.stack,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
return enhancedClient;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
TemporalClientModule.logger = new common_1.Logger(TemporalClientModule_1.name);
|
|
134
|
+
exports.TemporalClientModule = TemporalClientModule = TemporalClientModule_1 = __decorate([
|
|
135
|
+
(0, common_1.Global)(),
|
|
136
|
+
(0, common_1.Module)({})
|
|
137
|
+
], TemporalClientModule);
|
|
138
|
+
//# sourceMappingURL=temporal-client.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporal-client.module.js","sourceRoot":"","sources":["../src/temporal-client.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAOwB;AACxB,+CAAwD;AAMxD,2CAAuE;AACvE,uEAAkE;AAI3D,IAAM,oBAAoB,2DAA1B,MAAM,oBAAoB;IAGvB,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,OAA8B;QAC9D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,8BAA8B,EAAE;YAC9C,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO;YACnC,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,SAAS;SAC1C,CAAC,CAAC;QAEH,IAAI;YACF,MAAM,UAAU,GAAG,MAAM,mBAAU,CAAC,OAAO,CAAC;gBAC1C,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO;gBACnC,GAAG,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG;aAC5B,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC;gBACxB,UAAU;gBACV,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,SAAS;aAC1C,CAAC,CAAC;YAEH,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;YAC5D,OAAO,MAAM,CAAC;SACf;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sCAAsC,EAAE;gBACxD,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K,EAAE,CAAC;gBACjC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;aACnE;YAAC,OAAO,KAAK,EAAE;gBACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,4CAA4C,EAAE;oBAC9D,KAAK,EAAE,KAAK,CAAC,OAAO;oBACpB,KAAK,EAAE,KAAK,CAAC,KAAK;iBACnB,CAAC,CAAC;aACJ;QACH,CAAC,CAAC;QACF,OAAO,cAAc,CAAC;IACxB,CAAC;;AAjIuB,2BAAM,GAAG,IAAI,eAAM,CAAC,sBAAoB,CAAC,IAAI,CAAC,AAAxC,CAAyC;+BAD5D,oBAAoB;IAFhC,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,oBAAoB,CAmIhC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Client, WorkflowClient, WorkflowHandle } from '@temporalio/client';
|
|
2
|
+
export declare class TemporalClientService {
|
|
3
|
+
private readonly client;
|
|
4
|
+
private readonly logger;
|
|
5
|
+
private workflowClient;
|
|
6
|
+
constructor(client: Client);
|
|
7
|
+
onModuleInit(): Promise<void>;
|
|
8
|
+
getWorkflowClient(): WorkflowClient;
|
|
9
|
+
startWorkflow<T, A extends any[]>(workflowType: string, args: A, options: {
|
|
10
|
+
taskQueue: string;
|
|
11
|
+
workflowId?: string;
|
|
12
|
+
signal?: string;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
result: Promise<T>;
|
|
15
|
+
workflowId: string;
|
|
16
|
+
firstExecutionRunId: string;
|
|
17
|
+
handle: WorkflowHandle;
|
|
18
|
+
}>;
|
|
19
|
+
signalWorkflow(workflowId: string, signalName: string, args: any[]): Promise<void>;
|
|
20
|
+
terminateWorkflow(workflowId: string, reason?: string): Promise<void>;
|
|
21
|
+
getWorkflowHandle(workflowId: string): Promise<WorkflowHandle>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
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 client_1 = require("@temporalio/client");
|
|
19
|
+
const constants_1 = require("./constants");
|
|
20
|
+
let TemporalClientService = exports.TemporalClientService = TemporalClientService_1 = class TemporalClientService {
|
|
21
|
+
constructor(client) {
|
|
22
|
+
this.client = client;
|
|
23
|
+
this.logger = new common_1.Logger(TemporalClientService_1.name);
|
|
24
|
+
this.workflowClient = this.client.workflow;
|
|
25
|
+
}
|
|
26
|
+
async onModuleInit() {
|
|
27
|
+
this.logger.log('Temporal client service initialized');
|
|
28
|
+
}
|
|
29
|
+
getWorkflowClient() {
|
|
30
|
+
return this.workflowClient;
|
|
31
|
+
}
|
|
32
|
+
async startWorkflow(workflowType, args, options) {
|
|
33
|
+
const { taskQueue, workflowId = `${workflowType}-${Date.now()}-${Math.random().toString(36).slice(2)}`, } = options;
|
|
34
|
+
try {
|
|
35
|
+
this.logger.log(`Starting workflow "${workflowType}" on task queue "${taskQueue}"`, {
|
|
36
|
+
workflowId,
|
|
37
|
+
taskQueue,
|
|
38
|
+
});
|
|
39
|
+
const handle = await this.workflowClient.start(workflowType, {
|
|
40
|
+
args,
|
|
41
|
+
taskQueue,
|
|
42
|
+
workflowId,
|
|
43
|
+
});
|
|
44
|
+
this.logger.debug(`Workflow "${workflowType}" started successfully`, {
|
|
45
|
+
workflowId: handle.workflowId,
|
|
46
|
+
runId: handle.firstExecutionRunId,
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
result: handle.result(),
|
|
50
|
+
workflowId: handle.workflowId,
|
|
51
|
+
firstExecutionRunId: handle.firstExecutionRunId,
|
|
52
|
+
handle,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
this.logger.error(`Failed to start workflow "${workflowType}"`, {
|
|
57
|
+
error: error.message,
|
|
58
|
+
stack: error.stack,
|
|
59
|
+
workflowId,
|
|
60
|
+
taskQueue,
|
|
61
|
+
});
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async signalWorkflow(workflowId, signalName, args) {
|
|
66
|
+
try {
|
|
67
|
+
this.logger.debug(`Sending signal "${signalName}" to workflow`, { workflowId });
|
|
68
|
+
const handle = await this.workflowClient.getHandle(workflowId);
|
|
69
|
+
await handle.signal(signalName, ...args);
|
|
70
|
+
this.logger.debug(`Signal "${signalName}" sent successfully`, { workflowId });
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
this.logger.error(`Failed to send signal "${signalName}" to workflow`, {
|
|
74
|
+
error: error.message,
|
|
75
|
+
stack: error.stack,
|
|
76
|
+
workflowId,
|
|
77
|
+
args,
|
|
78
|
+
});
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async terminateWorkflow(workflowId, reason) {
|
|
83
|
+
try {
|
|
84
|
+
this.logger.log(`Terminating workflow`, { workflowId, reason });
|
|
85
|
+
const handle = await this.workflowClient.getHandle(workflowId);
|
|
86
|
+
await handle.terminate(reason);
|
|
87
|
+
this.logger.debug(`Workflow terminated successfully`, { workflowId, reason });
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
this.logger.error(`Failed to terminate workflow`, {
|
|
91
|
+
error: error.message,
|
|
92
|
+
stack: error.stack,
|
|
93
|
+
workflowId,
|
|
94
|
+
reason,
|
|
95
|
+
});
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async getWorkflowHandle(workflowId) {
|
|
100
|
+
try {
|
|
101
|
+
return await this.workflowClient.getHandle(workflowId);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
this.logger.error(`Failed to get workflow handle`, {
|
|
105
|
+
error: error.message,
|
|
106
|
+
stack: error.stack,
|
|
107
|
+
workflowId,
|
|
108
|
+
});
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
exports.TemporalClientService = TemporalClientService = TemporalClientService_1 = __decorate([
|
|
114
|
+
(0, common_1.Injectable)(),
|
|
115
|
+
__param(0, (0, common_1.Inject)(constants_1.TEMPORAL_CLIENT)),
|
|
116
|
+
__metadata("design:paramtypes", [client_1.Client])
|
|
117
|
+
], TemporalClientService);
|
|
118
|
+
//# sourceMappingURL=temporal-client.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporal-client.service.js","sourceRoot":"","sources":["../src/temporal-client.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA4D;AAC5D,+CAA4E;AAC5E,2CAA8C;AAGvC,IAAM,qBAAqB,6DAA3B,MAAM,qBAAqB;IAIhC,YAEE,MAA+B;QAAd,WAAM,GAAN,MAAM,CAAQ;QALhB,WAAM,GAAG,IAAI,eAAM,CAAC,uBAAqB,CAAC,IAAI,C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AAO,KAAK,EAAE;YACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA8B,EAAE;gBAChD,KAAK,EAAE,KAAK,CAAC,OAAO;gBACpB,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,UAAU;gBACV,MAAM;aACP,CAAC,CAAC;YACH,MAAM,KAAK,CAAC;SACb;IACH,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,UAAkB;QACxC,IAAI;YACF,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;SACxD;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE;gBACjD,KAAK,EAAE,KAAK,CAAC,OAAO;gBACpB,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,UAAU;aACX,CAAC,CAAC;YACH,MAAM,KAAK,CAAC;SACb;IACH,CAAC;CACF,CAAA;gCA1HY,qBAAqB;IADjC,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,eAAM,EAAC,2BAAe,CAAC,CAAA;qCACC,eAAM;GANtB,qBAAqB,CA0HjC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TemporalMetadataAccessor = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const constants_1 = require("./constants");
|
|
12
|
+
let TemporalMetadataAccessor = exports.TemporalMetadataAccessor = class TemporalMetadataAccessor {
|
|
13
|
+
isActivity(target) {
|
|
14
|
+
if (!target) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return !!Reflect.getMetadata(constants_1.TEMPORAL_ACTIVITY, target);
|
|
18
|
+
}
|
|
19
|
+
isActivityMethod(target) {
|
|
20
|
+
if (!target) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return !!Reflect.getMetadata(constants_1.TEMPORAL_ACTIVITY_METHOD, target);
|
|
24
|
+
}
|
|
25
|
+
getActivityMethodName(target) {
|
|
26
|
+
if (!target) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
return Reflect.getMetadata('activityMethodName', target);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.TemporalMetadataAccessor = TemporalMetadataAccessor = __decorate([
|
|
33
|
+
(0, common_1.Injectable)()
|
|
34
|
+
], TemporalMetadataAccessor);
|
|
35
|
+
//# sourceMappingURL=temporal-metadata.accessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporal-metadata.accessor.js","sourceRoot":"","sources":["../src/temporal-metadata.accessor.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA0E;AAGnE,IAAM,wBAAwB,sCAA9B,MAAM,wBAAwB;IACnC,UAAU,CAAC,MAAW;QACpB,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,KAAK,CAAC;SACd;QACD,OAAO,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,6BAAiB,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;IAED,gBAAgB,CAAC,MAAW;QAC1B,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,KAAK,CAAC;SACd;QACD,OAAO,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,oCAAwB,EAAE,MAAM,CAAC,CAAC;IACjE,CAAC;IAED,qBAAqB,CAAC,MAAW;QAC/B,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,SAAS,CAAC;SAClB;QACD,OAAO,OAAO,CAAC,WAAW,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;IAC3D,CAAC;CACF,CAAA;mCArBY,wBAAwB;IADpC,IAAA,mBAAU,GAAE;GACA,wBAAwB,CAqBpC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { TemporalWorkerOptions, TemporalWorkerAsyncOptions } from './interfaces';
|
|
3
|
+
export declare class TemporalWorkerModule {
|
|
4
|
+
private static readonly logger;
|
|
5
|
+
static register(options: TemporalWorkerOptions): DynamicModule;
|
|
6
|
+
static registerAsync(options: TemporalWorkerAsyncOptions): DynamicModule;
|
|
7
|
+
private static createAsyncProviders;
|
|
8
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
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 TemporalWorkerModule_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.TemporalWorkerModule = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const worker_1 = require("@temporalio/worker");
|
|
19
|
+
const core_1 = require("@nestjs/core");
|
|
20
|
+
const constants_1 = require("./constants");
|
|
21
|
+
const temporal_metadata_accessor_1 = require("./temporal-metadata.accessor");
|
|
22
|
+
let WorkerManager = class WorkerManager {
|
|
23
|
+
constructor(options, modulesContainer) {
|
|
24
|
+
this.options = options;
|
|
25
|
+
this.modulesContainer = modulesContainer;
|
|
26
|
+
this.logger = new common_1.Logger('TemporalWorker');
|
|
27
|
+
this.isRunning = false;
|
|
28
|
+
this.isInitializing = false;
|
|
29
|
+
this.initializationError = null;
|
|
30
|
+
}
|
|
31
|
+
async onModuleInit() {
|
|
32
|
+
this.initializeWorker().catch((error) => {
|
|
33
|
+
this.logger.error('Failed to initialize worker:', error);
|
|
34
|
+
this.initializationError = error;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async onApplicationShutdown() {
|
|
38
|
+
await this.shutdown();
|
|
39
|
+
}
|
|
40
|
+
async shutdown() {
|
|
41
|
+
try {
|
|
42
|
+
if (this.isRunning) {
|
|
43
|
+
this.isRunning = false;
|
|
44
|
+
if (this.worker) {
|
|
45
|
+
this.logger.log('Shutting down worker...');
|
|
46
|
+
await this.worker.shutdown();
|
|
47
|
+
this.logger.log('Worker shutdown complete');
|
|
48
|
+
}
|
|
49
|
+
if (this.connection) {
|
|
50
|
+
this.logger.log('Closing connection...');
|
|
51
|
+
await this.connection.close();
|
|
52
|
+
this.logger.log('Connection closed');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
this.logger.error('Error during worker shutdown', {
|
|
58
|
+
error: error.message,
|
|
59
|
+
stack: error.stack,
|
|
60
|
+
});
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
findProviderByType(type) {
|
|
65
|
+
for (const [, module] of this.modulesContainer.entries()) {
|
|
66
|
+
const provider = module.providers.get(type);
|
|
67
|
+
if (provider) {
|
|
68
|
+
return provider;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
async handleActivities() {
|
|
74
|
+
const activitiesMethod = {};
|
|
75
|
+
if (this.options.activityClasses?.length) {
|
|
76
|
+
this.logger.log(`Processing ${this.options.activityClasses.length} activity classes`);
|
|
77
|
+
for (const activityClass of this.options.activityClasses) {
|
|
78
|
+
const provider = this.findProviderByType(activityClass);
|
|
79
|
+
if (!provider) {
|
|
80
|
+
const instance = new activityClass();
|
|
81
|
+
this.logger.debug(`Created new instance of activity class: ${activityClass.name}`);
|
|
82
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
83
|
+
for (const methodName of Object.getOwnPropertyNames(prototype)) {
|
|
84
|
+
if (methodName !== 'constructor') {
|
|
85
|
+
const method = instance[methodName];
|
|
86
|
+
if (typeof method === 'function') {
|
|
87
|
+
const name = methodName;
|
|
88
|
+
this.logger.debug(`Registering activity method: ${name} from ${activityClass.name}`);
|
|
89
|
+
activitiesMethod[name] = method.bind(instance);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const { instance } = provider;
|
|
96
|
+
if (!instance) {
|
|
97
|
+
this.logger.warn(`No instance found for activity class: ${activityClass.name}`);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
this.logger.debug(`Found provider instance for activity class: ${activityClass.name}`);
|
|
101
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
102
|
+
for (const methodName of Object.getOwnPropertyNames(prototype)) {
|
|
103
|
+
if (methodName !== 'constructor') {
|
|
104
|
+
const method = instance[methodName];
|
|
105
|
+
if (typeof method === 'function') {
|
|
106
|
+
const name = methodName;
|
|
107
|
+
this.logger.debug(`Registering activity method: ${name} from ${activityClass.name}`);
|
|
108
|
+
activitiesMethod[name] = method.bind(instance);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const registeredMethods = Object.keys(activitiesMethod);
|
|
116
|
+
if (registeredMethods.length === 0) {
|
|
117
|
+
this.logger.warn('No activity methods were registered');
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
this.logger.log(`Successfully registered ${registeredMethods.length} activities: ${registeredMethods.join(', ')}`);
|
|
121
|
+
}
|
|
122
|
+
return activitiesMethod;
|
|
123
|
+
}
|
|
124
|
+
async initializeWorker() {
|
|
125
|
+
if (this.isRunning || this.isInitializing) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this.isInitializing = true;
|
|
129
|
+
try {
|
|
130
|
+
this.logger.log('Initializing Temporal worker', {
|
|
131
|
+
namespace: this.options.namespace,
|
|
132
|
+
taskQueue: this.options.taskQueue,
|
|
133
|
+
});
|
|
134
|
+
if (this.options.runtimeOptions) {
|
|
135
|
+
this.logger.verbose('Configuring Temporal runtime');
|
|
136
|
+
worker_1.Runtime.install(this.options.runtimeOptions);
|
|
137
|
+
}
|
|
138
|
+
this.logger.debug('Establishing connection', { address: this.options.connection.address });
|
|
139
|
+
this.connection = await worker_1.NativeConnection.connect({
|
|
140
|
+
address: this.options.connection.address,
|
|
141
|
+
tls: this.options.connection.tls,
|
|
142
|
+
});
|
|
143
|
+
const activities = await this.handleActivities();
|
|
144
|
+
this.worker = await worker_1.Worker.create({
|
|
145
|
+
connection: this.connection,
|
|
146
|
+
namespace: this.options.namespace,
|
|
147
|
+
taskQueue: this.options.taskQueue,
|
|
148
|
+
workflowsPath: this.options.workflowsPath,
|
|
149
|
+
activities,
|
|
150
|
+
});
|
|
151
|
+
this.worker.run().catch((error) => {
|
|
152
|
+
this.logger.error('Worker runtime error', { error: error.message, stack: error.stack });
|
|
153
|
+
this.initializationError = error;
|
|
154
|
+
this.isRunning = false;
|
|
155
|
+
});
|
|
156
|
+
this.isRunning = true;
|
|
157
|
+
this.logger.log('Temporal worker initialized successfully', {
|
|
158
|
+
taskQueue: this.options.taskQueue,
|
|
159
|
+
namespace: this.options.namespace,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
this.logger.error('Worker initialization failed', {
|
|
164
|
+
error: error.message,
|
|
165
|
+
stack: error.stack,
|
|
166
|
+
});
|
|
167
|
+
this.initializationError = error;
|
|
168
|
+
await this.shutdown();
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
this.isInitializing = false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
async getStatus() {
|
|
176
|
+
return {
|
|
177
|
+
isRunning: this.isRunning,
|
|
178
|
+
isInitializing: this.isInitializing,
|
|
179
|
+
error: this.initializationError,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
WorkerManager = __decorate([
|
|
184
|
+
(0, common_1.Injectable)(),
|
|
185
|
+
__param(0, (0, common_1.Inject)(constants_1.TEMPORAL_MODULE_OPTIONS)),
|
|
186
|
+
__metadata("design:paramtypes", [Object, core_1.ModulesContainer])
|
|
187
|
+
], WorkerManager);
|
|
188
|
+
let TemporalWorkerModule = exports.TemporalWorkerModule = TemporalWorkerModule_1 = class TemporalWorkerModule {
|
|
189
|
+
static register(options) {
|
|
190
|
+
this.logger.log('Registering Temporal Worker Module');
|
|
191
|
+
return {
|
|
192
|
+
global: true,
|
|
193
|
+
module: TemporalWorkerModule_1,
|
|
194
|
+
providers: [
|
|
195
|
+
{
|
|
196
|
+
provide: constants_1.TEMPORAL_MODULE_OPTIONS,
|
|
197
|
+
useValue: options,
|
|
198
|
+
},
|
|
199
|
+
...(options.activityClasses || []).map((activity) => ({
|
|
200
|
+
provide: activity,
|
|
201
|
+
useClass: activity,
|
|
202
|
+
})),
|
|
203
|
+
temporal_metadata_accessor_1.TemporalMetadataAccessor,
|
|
204
|
+
core_1.MetadataScanner,
|
|
205
|
+
core_1.ModulesContainer,
|
|
206
|
+
core_1.DiscoveryService,
|
|
207
|
+
WorkerManager,
|
|
208
|
+
],
|
|
209
|
+
exports: [WorkerManager],
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
static registerAsync(options) {
|
|
213
|
+
this.logger.log('Registering Temporal Worker Module Asynchronously');
|
|
214
|
+
return {
|
|
215
|
+
global: true,
|
|
216
|
+
module: TemporalWorkerModule_1,
|
|
217
|
+
imports: [...(options.imports || [])],
|
|
218
|
+
providers: [
|
|
219
|
+
...this.createAsyncProviders(options),
|
|
220
|
+
temporal_metadata_accessor_1.TemporalMetadataAccessor,
|
|
221
|
+
core_1.MetadataScanner,
|
|
222
|
+
core_1.ModulesContainer,
|
|
223
|
+
core_1.DiscoveryService,
|
|
224
|
+
WorkerManager,
|
|
225
|
+
],
|
|
226
|
+
exports: [WorkerManager],
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
static createAsyncProviders(options) {
|
|
230
|
+
if (options.useFactory) {
|
|
231
|
+
return [
|
|
232
|
+
{
|
|
233
|
+
provide: constants_1.TEMPORAL_MODULE_OPTIONS,
|
|
234
|
+
useFactory: options.useFactory,
|
|
235
|
+
inject: options.inject || [],
|
|
236
|
+
},
|
|
237
|
+
];
|
|
238
|
+
}
|
|
239
|
+
if (options.useClass) {
|
|
240
|
+
return [
|
|
241
|
+
{
|
|
242
|
+
provide: constants_1.TEMPORAL_MODULE_OPTIONS,
|
|
243
|
+
useFactory: async (optionsFactory) => await optionsFactory.createWorkerOptions(),
|
|
244
|
+
inject: [options.useClass],
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
provide: options.useClass,
|
|
248
|
+
useClass: options.useClass,
|
|
249
|
+
},
|
|
250
|
+
];
|
|
251
|
+
}
|
|
252
|
+
if (options.useExisting) {
|
|
253
|
+
return [
|
|
254
|
+
{
|
|
255
|
+
provide: constants_1.TEMPORAL_MODULE_OPTIONS,
|
|
256
|
+
useFactory: async (optionsFactory) => await optionsFactory.createWorkerOptions(),
|
|
257
|
+
inject: [options.useExisting],
|
|
258
|
+
},
|
|
259
|
+
];
|
|
260
|
+
}
|
|
261
|
+
const error = new Error('Invalid TemporalWorkerAsyncOptions configuration');
|
|
262
|
+
this.logger.error(error.message);
|
|
263
|
+
throw error;
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
TemporalWorkerModule.logger = new common_1.Logger(TemporalWorkerModule_1.name);
|
|
267
|
+
exports.TemporalWorkerModule = TemporalWorkerModule = TemporalWorkerModule_1 = __decorate([
|
|
268
|
+
(0, common_1.Module)({})
|
|
269
|
+
], TemporalWorkerModule);
|
|
270
|
+
//# sourceMappingURL=temporal-worker.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporal-worker.module.js","sourceRoot":"","sources":["../src/temporal-worker.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAUwB;AACxB,+CAAuE;AACvE,uCAAmF;AAOnF,2CAAsD;AACtD,6EAAwE;AAExE,IACM,aAAa,GADnB,MACM,aAAa;IAQjB,YAEE,OAA+C,EAC9B,gBAAkC;QADlC,YAAO,GAAP,OAAO,CAAuB;QAC9B,qBAAgB,GAAhB,gBAAgB,CAAkB;QARpC,WAAM,GAAG,IAAI,eAAM,CAAC,gBAAgB,CAAC,CAAC;QAC/C,cAAS,GAAG,KAAK,CAAC;QAClB,mBAAc,GAAG,KAAK,CAAC;QACvB,wBAAmB,GAAiB,IAAI,CAAC;IAM9C,CAAC;IAEJ,KAAK,CAAC,YAAY;QAEhB,IAAI,CAAC,gBAAgB,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACtC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;YACzD,IAAI,CAA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