nestjs-temporal-core 2.0.1 → 2.0.3
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 +159 -27
- package/dist/client/temporal-client.module.js +39 -13
- package/dist/client/temporal-client.module.js.map +1 -1
- package/dist/client/temporal-client.service.d.ts +4 -7
- package/dist/client/temporal-client.service.js +12 -4
- package/dist/client/temporal-client.service.js.map +1 -1
- package/dist/constants.d.ts +42 -6
- package/dist/constants.js +43 -7
- package/dist/constants.js.map +1 -1
- package/dist/decorators/activity-method.decorator.d.ts +5 -1
- package/dist/decorators/activity-method.decorator.js +27 -6
- 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 +6 -7
- package/dist/decorators/activity.decorator.js.map +1 -1
- package/dist/decorators/index.d.ts +0 -1
- package/dist/decorators/index.js +0 -1
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/workflow.decorator.d.ts +16 -2
- package/dist/decorators/workflow.decorator.js +10 -2
- package/dist/decorators/workflow.decorator.js.map +1 -1
- package/dist/interfaces/base.interface.d.ts +4 -0
- package/dist/interfaces/client.interface.d.ts +27 -1
- package/dist/interfaces/worker.interface.d.ts +17 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/worker/temporal-metadata.accessor.d.ts +14 -3
- package/dist/worker/temporal-metadata.accessor.js +76 -0
- 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 +35 -35
- package/dist/worker/temporal-worker.module.js.map +1 -1
- package/dist/worker/worker-manager.service.d.ts +17 -24
- package/dist/worker/worker-manager.service.js +124 -140
- package/dist/worker/worker-manager.service.js.map +1 -1
- package/package.json +1 -1
- package/dist/decorators/inject-temporal-client.decorator.d.ts +0 -1
- package/dist/decorators/inject-temporal-client.decorator.js +0 -8
- package/dist/decorators/inject-temporal-client.decorator.js.map +0 -1
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
export declare class TemporalMetadataAccessor {
|
|
2
|
-
isActivity(target:
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
isActivity(target: Function): boolean;
|
|
3
|
+
getActivityOptions(target: Function): Record<string, any> | undefined;
|
|
4
|
+
isActivityMethod(target: Function): boolean;
|
|
5
|
+
getActivityMethodName(target: Function): string | undefined;
|
|
6
|
+
getActivityMethodOptions(target: Function): Record<string, any> | undefined;
|
|
7
|
+
isWorkflow(target: Function): boolean;
|
|
8
|
+
getWorkflowOptions(target: Function): Record<string, any> | undefined;
|
|
9
|
+
isWorkflowMethod(target: Function): boolean;
|
|
10
|
+
getWorkflowMethodName(target: Function): string | undefined;
|
|
11
|
+
isQueryMethod(target: Function): boolean;
|
|
12
|
+
getQueryMethodName(target: Function): string | undefined;
|
|
13
|
+
isSignalMethod(target: Function): boolean;
|
|
14
|
+
getSignalMethodName(target: Function): string | undefined;
|
|
15
|
+
extractActivityMethods(instance: any): Map<string, Function>;
|
|
5
16
|
}
|
|
@@ -16,6 +16,12 @@ let TemporalMetadataAccessor = class TemporalMetadataAccessor {
|
|
|
16
16
|
}
|
|
17
17
|
return !!Reflect.getMetadata(constants_1.TEMPORAL_ACTIVITY, target);
|
|
18
18
|
}
|
|
19
|
+
getActivityOptions(target) {
|
|
20
|
+
if (!target) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return Reflect.getMetadata(constants_1.TEMPORAL_ACTIVITY, target);
|
|
24
|
+
}
|
|
19
25
|
isActivityMethod(target) {
|
|
20
26
|
if (!target) {
|
|
21
27
|
return false;
|
|
@@ -28,6 +34,76 @@ let TemporalMetadataAccessor = class TemporalMetadataAccessor {
|
|
|
28
34
|
}
|
|
29
35
|
return Reflect.getMetadata(constants_1.TEMPORAL_ACTIVITY_METHOD_NAME, target);
|
|
30
36
|
}
|
|
37
|
+
getActivityMethodOptions(target) {
|
|
38
|
+
if (!target) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
return Reflect.getMetadata(constants_1.TEMPORAL_ACTIVITY_METHOD_OPTIONS, target);
|
|
42
|
+
}
|
|
43
|
+
isWorkflow(target) {
|
|
44
|
+
if (!target) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return !!Reflect.getMetadata(constants_1.TEMPORAL_WORKFLOW, target);
|
|
48
|
+
}
|
|
49
|
+
getWorkflowOptions(target) {
|
|
50
|
+
if (!target) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
return Reflect.getMetadata(constants_1.TEMPORAL_WORKFLOW_OPTIONS, target);
|
|
54
|
+
}
|
|
55
|
+
isWorkflowMethod(target) {
|
|
56
|
+
if (!target) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return !!Reflect.getMetadata(constants_1.TEMPORAL_WORKFLOW_METHOD, target);
|
|
60
|
+
}
|
|
61
|
+
getWorkflowMethodName(target) {
|
|
62
|
+
if (!target) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
return Reflect.getMetadata(constants_1.TEMPORAL_WORKFLOW_METHOD_NAME, target);
|
|
66
|
+
}
|
|
67
|
+
isQueryMethod(target) {
|
|
68
|
+
if (!target) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return !!Reflect.getMetadata(constants_1.TEMPORAL_QUERY_METHOD, target);
|
|
72
|
+
}
|
|
73
|
+
getQueryMethodName(target) {
|
|
74
|
+
if (!target) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
return Reflect.getMetadata(constants_1.TEMPORAL_QUERY_NAME, target);
|
|
78
|
+
}
|
|
79
|
+
isSignalMethod(target) {
|
|
80
|
+
if (!target) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return !!Reflect.getMetadata(constants_1.TEMPORAL_SIGNAL_METHOD, target);
|
|
84
|
+
}
|
|
85
|
+
getSignalMethodName(target) {
|
|
86
|
+
if (!target) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
return Reflect.getMetadata(constants_1.TEMPORAL_SIGNAL_NAME, target);
|
|
90
|
+
}
|
|
91
|
+
extractActivityMethods(instance) {
|
|
92
|
+
if (!instance) {
|
|
93
|
+
return new Map();
|
|
94
|
+
}
|
|
95
|
+
const methods = new Map();
|
|
96
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
97
|
+
const methodNames = Object.getOwnPropertyNames(prototype).filter((prop) => prop !== 'constructor');
|
|
98
|
+
for (const methodName of methodNames) {
|
|
99
|
+
const method = prototype[methodName];
|
|
100
|
+
if (this.isActivityMethod(method)) {
|
|
101
|
+
const activityName = this.getActivityMethodName(method) || methodName;
|
|
102
|
+
methods.set(activityName, method.bind(instance));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return methods;
|
|
106
|
+
}
|
|
31
107
|
};
|
|
32
108
|
exports.TemporalMetadataAccessor = TemporalMetadataAccessor;
|
|
33
109
|
exports.TemporalMetadataAccessor = TemporalMetadataAccessor = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temporal-metadata.accessor.js","sourceRoot":"","sources":["../../src/worker/temporal-metadata.accessor.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"temporal-metadata.accessor.js","sourceRoot":"","sources":["../../src/worker/temporal-metadata.accessor.ts"],"names":[],"mappings":";;;;;;;;;AACA,2CAA4C;AAC5C,4CAasB;AAOf,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAKjC,UAAU,CAAC,MAAgB;QACvB,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,OAAO,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,6BAAiB,EAAE,MAAM,CAAC,CAAC;IAC5D,CAAC;IAMD,kBAAkB,CAAC,MAAgB;QAC/B,IAAI,CAAC,M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,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,aAAa,CACnC,CAAC;QAEF,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;YACnC,MAAM,MAAM,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;YACrC,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;gBAChC,MAAM,YAAY,GAAG,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC;gBACtE,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YACrD,CAAC;QACL,CAAC;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ,CAAA;AA1KY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;GACA,wBAAwB,CA0KpC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { DynamicModule } from '@nestjs/common';
|
|
2
|
-
import {
|
|
2
|
+
import { TemporalWorkerAsyncOptions, TemporalWorkerOptions } from '../interfaces';
|
|
3
3
|
export declare class TemporalWorkerModule {
|
|
4
4
|
static register(options: TemporalWorkerOptions): DynamicModule;
|
|
5
5
|
static registerAsync(options: TemporalWorkerAsyncOptions): DynamicModule;
|
|
6
|
+
private static createActivityProviders;
|
|
6
7
|
private static createAsyncProviders;
|
|
7
8
|
}
|
|
@@ -15,59 +15,59 @@ const temporal_metadata_accessor_1 = require("./temporal-metadata.accessor");
|
|
|
15
15
|
const worker_manager_service_1 = require("./worker-manager.service");
|
|
16
16
|
let TemporalWorkerModule = TemporalWorkerModule_1 = class TemporalWorkerModule {
|
|
17
17
|
static register(options) {
|
|
18
|
-
const
|
|
19
|
-
{
|
|
20
|
-
provide: constants_1.TEMPORAL_MODULE_OPTIONS,
|
|
21
|
-
useValue: options,
|
|
22
|
-
},
|
|
23
|
-
...(options.activityClasses || []).map((activity) => ({
|
|
24
|
-
provide: activity,
|
|
25
|
-
useClass: activity,
|
|
26
|
-
})),
|
|
27
|
-
temporal_metadata_accessor_1.TemporalMetadataAccessor,
|
|
28
|
-
core_1.MetadataScanner,
|
|
29
|
-
core_1.ModulesContainer,
|
|
30
|
-
core_1.DiscoveryService,
|
|
31
|
-
worker_manager_service_1.WorkerManager,
|
|
32
|
-
];
|
|
18
|
+
const activityProviders = this.createActivityProviders(options.activityClasses || []);
|
|
33
19
|
return {
|
|
34
|
-
global: true,
|
|
35
20
|
module: TemporalWorkerModule_1,
|
|
36
|
-
|
|
37
|
-
|
|
21
|
+
global: true,
|
|
22
|
+
providers: [
|
|
23
|
+
{
|
|
24
|
+
provide: constants_1.TEMPORAL_WORKER_MODULE_OPTIONS,
|
|
25
|
+
useValue: options,
|
|
26
|
+
},
|
|
27
|
+
...activityProviders,
|
|
28
|
+
temporal_metadata_accessor_1.TemporalMetadataAccessor,
|
|
29
|
+
core_1.DiscoveryService,
|
|
30
|
+
worker_manager_service_1.WorkerManager,
|
|
31
|
+
],
|
|
32
|
+
exports: [worker_manager_service_1.WorkerManager, constants_1.TEMPORAL_WORKER_MODULE_OPTIONS],
|
|
38
33
|
};
|
|
39
34
|
}
|
|
40
35
|
static registerAsync(options) {
|
|
41
|
-
const providers = [
|
|
42
|
-
...this.createAsyncProviders(options),
|
|
43
|
-
temporal_metadata_accessor_1.TemporalMetadataAccessor,
|
|
44
|
-
core_1.MetadataScanner,
|
|
45
|
-
core_1.ModulesContainer,
|
|
46
|
-
core_1.DiscoveryService,
|
|
47
|
-
worker_manager_service_1.WorkerManager,
|
|
48
|
-
];
|
|
49
36
|
return {
|
|
50
|
-
global: true,
|
|
51
37
|
module: TemporalWorkerModule_1,
|
|
38
|
+
global: true,
|
|
52
39
|
imports: options.imports || [],
|
|
53
|
-
providers
|
|
54
|
-
|
|
40
|
+
providers: [
|
|
41
|
+
...this.createAsyncProviders(options),
|
|
42
|
+
temporal_metadata_accessor_1.TemporalMetadataAccessor,
|
|
43
|
+
core_1.DiscoveryService,
|
|
44
|
+
worker_manager_service_1.WorkerManager,
|
|
45
|
+
],
|
|
46
|
+
exports: [worker_manager_service_1.WorkerManager, constants_1.TEMPORAL_WORKER_MODULE_OPTIONS],
|
|
55
47
|
};
|
|
56
48
|
}
|
|
49
|
+
static createActivityProviders(activityClasses) {
|
|
50
|
+
return activityClasses.map((activity) => ({
|
|
51
|
+
provide: activity,
|
|
52
|
+
useClass: activity,
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
57
55
|
static createAsyncProviders(options) {
|
|
58
56
|
if (options.useFactory) {
|
|
57
|
+
const factory = options.useFactory;
|
|
58
|
+
const inject = options.inject || [];
|
|
59
59
|
return [
|
|
60
60
|
{
|
|
61
|
-
provide: constants_1.
|
|
62
|
-
useFactory:
|
|
63
|
-
inject
|
|
61
|
+
provide: constants_1.TEMPORAL_WORKER_MODULE_OPTIONS,
|
|
62
|
+
useFactory: factory,
|
|
63
|
+
inject,
|
|
64
64
|
},
|
|
65
65
|
];
|
|
66
66
|
}
|
|
67
67
|
if (options.useClass) {
|
|
68
68
|
return [
|
|
69
69
|
{
|
|
70
|
-
provide: constants_1.
|
|
70
|
+
provide: constants_1.TEMPORAL_WORKER_MODULE_OPTIONS,
|
|
71
71
|
useFactory: async (optionsFactory) => await optionsFactory.createWorkerOptions(),
|
|
72
72
|
inject: [options.useClass],
|
|
73
73
|
},
|
|
@@ -80,13 +80,13 @@ let TemporalWorkerModule = TemporalWorkerModule_1 = class TemporalWorkerModule {
|
|
|
80
80
|
if (options.useExisting) {
|
|
81
81
|
return [
|
|
82
82
|
{
|
|
83
|
-
provide: constants_1.
|
|
83
|
+
provide: constants_1.TEMPORAL_WORKER_MODULE_OPTIONS,
|
|
84
84
|
useFactory: async (optionsFactory) => await optionsFactory.createWorkerOptions(),
|
|
85
85
|
inject: [options.useExisting],
|
|
86
86
|
},
|
|
87
87
|
];
|
|
88
88
|
}
|
|
89
|
-
throw new Error(
|
|
89
|
+
throw new Error(constants_1.ERRORS.INVALID_OPTIONS);
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
92
|
exports.TemporalWorkerModule = TemporalWorkerModule;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temporal-worker.module.js","sourceRoot":"","sources":["../../src/worker/temporal-worker.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"temporal-worker.module.js","sourceRoot":"","sources":["../../src/worker/temporal-worker.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuE;AACvE,uCAAgD;AAChD,4CAAsE;AAMtE,6EAAwE;AACxE,qEAAyD;AAOlD,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAuB7B,MAAM,CAAC,QAAQ,CAAC,OAA8B;QAC1C,MAAM,iBAAiB,GAAG,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC;QAEtF,OAAO;YACH,MAAM,EAAE,sBAAoB;YAC5B,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE;gBACP;oBACI,OAAO,EAAE,0CAA8B;oBACvC,QAAQ,EAAE,OAAO;iBACpB;gBACD,GAAG,iBAAiB;gBACpB,qDAAwB;gBACxB,uBAAgB;gBAChB,sCAAa;aAChB;YACD,OAAO,EAAE,CAAC,sCAAa,EAAE,0CAA8B,CAAC;SAC3D,CAAC;IACN,CAAC;IA+BD,MAAM,CAAC,aAAa,CAAC,OAAmC;QACpD,OAAO;YACH,MAAM,EAAE,sBAAoB;YAC5B,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;YAC9B,SAAS,EAAE;gBACP,GAAG,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC;gBACrC,qDAAwB;gBACxB,uBAAgB;gBAChB,sCAAa;aAChB;YACD,OAAO,EAAE,CAAC,sCAAa,EAAE,0CAA8B,CAAC;SAC3D,CAAC;IACN,CAAC;IAMO,MAAM,CAA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AC,EAAE,CAAC;GACE,oBAAoB,CAgJhC"}
|
|
@@ -1,32 +1,25 @@
|
|
|
1
|
-
import { OnModuleInit } from '@nestjs/common';
|
|
2
|
-
import {
|
|
1
|
+
import { OnApplicationBootstrap, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { DiscoveryService } from '@nestjs/core';
|
|
3
|
+
import { Worker } from '@temporalio/worker';
|
|
3
4
|
import { TemporalWorkerOptions } from '../interfaces';
|
|
4
|
-
|
|
5
|
+
import { TemporalMetadataAccessor } from './temporal-metadata.accessor';
|
|
6
|
+
export declare class WorkerManager implements OnModuleInit, OnModuleDestroy, OnApplicationBootstrap {
|
|
5
7
|
private readonly options;
|
|
6
|
-
private readonly
|
|
8
|
+
private readonly discoveryService;
|
|
9
|
+
private readonly metadataAccessor;
|
|
10
|
+
private readonly logger;
|
|
7
11
|
private worker;
|
|
8
12
|
private connection;
|
|
9
|
-
private
|
|
13
|
+
private timerId;
|
|
10
14
|
private isRunning;
|
|
11
|
-
|
|
12
|
-
private initializationError;
|
|
13
|
-
private shutdownPromise;
|
|
14
|
-
private workerRunPromise;
|
|
15
|
-
private isShuttingDown;
|
|
16
|
-
constructor(options: TemporalWorkerOptions, modulesContainer: ModulesContainer);
|
|
17
|
-
private registerProcessShutdownHandlers;
|
|
15
|
+
constructor(options: TemporalWorkerOptions, discoveryService: DiscoveryService, metadataAccessor: TemporalMetadataAccessor);
|
|
18
16
|
onModuleInit(): Promise<void>;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
onModuleDestroy(): Promise<void>;
|
|
18
|
+
onApplicationBootstrap(): void;
|
|
19
|
+
startWorker(): Promise<void>;
|
|
20
|
+
shutdown(): Promise<void>;
|
|
21
|
+
private clearTimeout;
|
|
22
|
+
private explore;
|
|
22
23
|
private handleActivities;
|
|
23
|
-
|
|
24
|
-
getStatus(): Promise<{
|
|
25
|
-
isRunning: boolean;
|
|
26
|
-
isInitializing: boolean;
|
|
27
|
-
isShuttingDown: boolean;
|
|
28
|
-
error: Error | null;
|
|
29
|
-
taskQueue?: string;
|
|
30
|
-
namespace?: string;
|
|
31
|
-
}>;
|
|
24
|
+
getWorker(): Worker | null;
|
|
32
25
|
}
|
|
@@ -15,186 +15,170 @@ var WorkerManager_1;
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.WorkerManager = void 0;
|
|
17
17
|
const common_1 = require("@nestjs/common");
|
|
18
|
-
const worker_1 = require("@temporalio/worker");
|
|
19
18
|
const core_1 = require("@nestjs/core");
|
|
19
|
+
const worker_1 = require("@temporalio/worker");
|
|
20
20
|
const constants_1 = require("../constants");
|
|
21
|
+
const temporal_metadata_accessor_1 = require("./temporal-metadata.accessor");
|
|
21
22
|
let WorkerManager = WorkerManager_1 = class WorkerManager {
|
|
22
|
-
constructor(options,
|
|
23
|
+
constructor(options, discoveryService, metadataAccessor) {
|
|
23
24
|
this.options = options;
|
|
24
|
-
this.
|
|
25
|
+
this.discoveryService = discoveryService;
|
|
26
|
+
this.metadataAccessor = metadataAccessor;
|
|
27
|
+
this.logger = new common_1.Logger(WorkerManager_1.name);
|
|
25
28
|
this.worker = null;
|
|
26
29
|
this.connection = null;
|
|
27
|
-
this.
|
|
30
|
+
this.timerId = null;
|
|
28
31
|
this.isRunning = false;
|
|
29
|
-
this.isInitializing = false;
|
|
30
|
-
this.initializationError = null;
|
|
31
|
-
this.shutdownPromise = null;
|
|
32
|
-
this.workerRunPromise = null;
|
|
33
|
-
this.isShuttingDown = false;
|
|
34
|
-
this.registerProcessShutdownHandlers();
|
|
35
|
-
}
|
|
36
|
-
registerProcessShutdownHandlers() {
|
|
37
|
-
['SIGTERM', 'SIGINT'].forEach((signal) => {
|
|
38
|
-
process.once(signal, async () => {
|
|
39
|
-
this.logger.log(`Received ${signal} signal. Starting worker shutdown...`);
|
|
40
|
-
await this.shutdown();
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
process.once('beforeExit', async () => {
|
|
44
|
-
await this.shutdown();
|
|
45
|
-
});
|
|
46
32
|
}
|
|
47
33
|
async onModuleInit() {
|
|
48
34
|
try {
|
|
49
|
-
|
|
35
|
+
this.logger.log('Initializing Temporal worker...');
|
|
36
|
+
await this.explore();
|
|
50
37
|
}
|
|
51
38
|
catch (error) {
|
|
52
|
-
this.logger.error('
|
|
53
|
-
this.
|
|
39
|
+
this.logger.error('Error during worker initialization', error);
|
|
40
|
+
if (this.options.allowWorkerFailure !== false) {
|
|
41
|
+
this.logger.warn('Continuing application startup without Temporal worker');
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
54
46
|
}
|
|
55
47
|
}
|
|
56
|
-
async
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
async onModuleDestroy() {
|
|
49
|
+
await this.shutdown();
|
|
50
|
+
}
|
|
51
|
+
onApplicationBootstrap() {
|
|
52
|
+
if (this.options.autoStart?.enabled === false || !this.worker) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const delayMs = this.options.autoStart?.delayMs || 0;
|
|
56
|
+
if (delayMs > 0) {
|
|
57
|
+
this.logger.log(`Worker will start in ${delayMs}ms`);
|
|
58
|
+
}
|
|
59
|
+
this.timerId = setTimeout(() => {
|
|
60
|
+
this.startWorker();
|
|
61
|
+
}, delayMs);
|
|
62
|
+
}
|
|
63
|
+
async startWorker() {
|
|
64
|
+
if (!this.worker) {
|
|
65
|
+
this.logger.warn('Cannot start worker: Worker not initialized');
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (this.isRunning) {
|
|
69
|
+
this.logger.warn('Worker is already running');
|
|
70
|
+
return;
|
|
59
71
|
}
|
|
60
|
-
this.isShuttingDown = true;
|
|
61
|
-
this.shutdownPromise = this.doShutdown();
|
|
62
72
|
try {
|
|
63
|
-
|
|
73
|
+
this.logger.log(`Starting worker for task queue: ${this.options.taskQueue}`);
|
|
74
|
+
this.isRunning = true;
|
|
75
|
+
await this.worker.run();
|
|
64
76
|
}
|
|
65
|
-
|
|
66
|
-
this.
|
|
67
|
-
this.
|
|
77
|
+
catch (error) {
|
|
78
|
+
this.isRunning = false;
|
|
79
|
+
this.logger.error('Error running worker', error);
|
|
80
|
+
throw error;
|
|
68
81
|
}
|
|
69
82
|
}
|
|
70
|
-
async
|
|
71
|
-
this.
|
|
72
|
-
this.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
this.logger.log('Shutting down worker...');
|
|
83
|
+
async shutdown() {
|
|
84
|
+
this.clearTimeout();
|
|
85
|
+
if (this.worker) {
|
|
86
|
+
try {
|
|
87
|
+
this.logger.log('Shutting down Temporal worker...');
|
|
76
88
|
await this.worker.shutdown();
|
|
77
|
-
|
|
89
|
+
this.isRunning = false;
|
|
90
|
+
this.logger.log('Temporal worker shut down successfully');
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
this.logger.error('Error during worker shutdown', error);
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
78
96
|
this.worker = null;
|
|
79
97
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
98
|
+
}
|
|
99
|
+
if (this.connection) {
|
|
100
|
+
try {
|
|
101
|
+
this.logger.log('Closing Temporal worker connection...');
|
|
102
|
+
await this.connection.close();
|
|
103
|
+
this.logger.log('Temporal worker connection closed successfully');
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
this.logger.error('Error during connection close', error);
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
88
109
|
this.connection = null;
|
|
89
110
|
}
|
|
90
|
-
this.logger.log('Shutdown sequence completed');
|
|
91
111
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
this.
|
|
96
|
-
|
|
112
|
+
}
|
|
113
|
+
clearTimeout() {
|
|
114
|
+
if (this.timerId) {
|
|
115
|
+
clearTimeout(this.timerId);
|
|
116
|
+
this.timerId = null;
|
|
97
117
|
}
|
|
98
118
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
119
|
+
async explore() {
|
|
120
|
+
if (!this.options.taskQueue) {
|
|
121
|
+
throw new Error(constants_1.ERRORS.MISSING_TASK_QUEUE);
|
|
122
|
+
}
|
|
123
|
+
const activities = await this.handleActivities();
|
|
124
|
+
if (this.options.runtimeOptions) {
|
|
125
|
+
this.logger.debug('Installing custom runtime options');
|
|
126
|
+
worker_1.Runtime.install(this.options.runtimeOptions);
|
|
104
127
|
}
|
|
105
|
-
|
|
128
|
+
const workerOptions = {
|
|
129
|
+
taskQueue: this.options.taskQueue,
|
|
130
|
+
workflowsPath: this.options.workflowsPath,
|
|
131
|
+
activities,
|
|
132
|
+
...this.options.workerOptions,
|
|
133
|
+
};
|
|
134
|
+
this.logger.debug(`Connecting to Temporal server at ${this.options.connection.address}`);
|
|
135
|
+
this.connection = await worker_1.NativeConnection.connect(this.options.connection);
|
|
136
|
+
this.worker = await worker_1.Worker.create({
|
|
137
|
+
connection: this.connection,
|
|
138
|
+
namespace: this.options.namespace || 'default',
|
|
139
|
+
...workerOptions,
|
|
140
|
+
});
|
|
141
|
+
this.logger.log(`Worker created for queue: ${this.options.taskQueue} in namespace: ${this.options.namespace || 'default'}`);
|
|
106
142
|
}
|
|
107
143
|
async handleActivities() {
|
|
108
144
|
const activities = {};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const instance = provider?.instance || new activityClass();
|
|
116
|
-
if (!instance) {
|
|
117
|
-
this.logger.warn(`Activity instance not found for class: ${activityClass.name}`);
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
121
|
-
const methodNames = Object.getOwnPropertyNames(prototype).filter((methodName) => methodName !== 'constructor' && typeof instance[methodName] === 'function');
|
|
122
|
-
for (const methodName of methodNames) {
|
|
123
|
-
activities[methodName] = instance[methodName].bind(instance);
|
|
124
|
-
}
|
|
125
|
-
this.logger.log(`Registered activities for ${activityClass.name}`);
|
|
145
|
+
const providers = this.discoveryService.getProviders();
|
|
146
|
+
const activityProviders = providers.filter((wrapper) => {
|
|
147
|
+
const { instance, metatype } = wrapper;
|
|
148
|
+
const targetClass = instance?.constructor || metatype;
|
|
149
|
+
if (!this.options.activityClasses?.length) {
|
|
150
|
+
return targetClass && this.metadataAccessor.isActivity(targetClass);
|
|
126
151
|
}
|
|
127
|
-
|
|
128
|
-
this.
|
|
129
|
-
|
|
130
|
-
|
|
152
|
+
return (targetClass &&
|
|
153
|
+
this.options.activityClasses.includes(targetClass) &&
|
|
154
|
+
this.metadataAccessor.isActivity(targetClass));
|
|
155
|
+
});
|
|
156
|
+
this.logger.log(`Found ${activityProviders.length} activity providers`);
|
|
157
|
+
for (const wrapper of activityProviders) {
|
|
158
|
+
const { instance } = wrapper;
|
|
159
|
+
if (!instance)
|
|
160
|
+
continue;
|
|
161
|
+
const className = instance.constructor.name;
|
|
162
|
+
this.logger.debug(`Processing activity class: ${className}`);
|
|
163
|
+
const activityMethods = this.metadataAccessor.extractActivityMethods(instance);
|
|
164
|
+
for (const [activityName, method] of activityMethods.entries()) {
|
|
165
|
+
activities[activityName] = method;
|
|
166
|
+
this.logger.debug(`Registered activity method: ${className}.${activityName}`);
|
|
131
167
|
}
|
|
132
168
|
}
|
|
169
|
+
const activityCount = Object.keys(activities).length;
|
|
170
|
+
this.logger.log(`Registered ${activityCount} activity methods in total`);
|
|
133
171
|
return activities;
|
|
134
172
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
this.isInitializing = true;
|
|
140
|
-
let tempConnection = null;
|
|
141
|
-
try {
|
|
142
|
-
if (this.options.runtimeOptions) {
|
|
143
|
-
worker_1.Runtime.install(this.options.runtimeOptions);
|
|
144
|
-
}
|
|
145
|
-
tempConnection = await worker_1.NativeConnection.connect({
|
|
146
|
-
address: this.options.connection.address,
|
|
147
|
-
tls: this.options.connection.tls,
|
|
148
|
-
});
|
|
149
|
-
const activities = await this.handleActivities();
|
|
150
|
-
const worker = await worker_1.Worker.create({
|
|
151
|
-
connection: tempConnection,
|
|
152
|
-
namespace: this.options.namespace,
|
|
153
|
-
taskQueue: this.options.taskQueue,
|
|
154
|
-
workflowsPath: this.options.workflowsPath,
|
|
155
|
-
activities,
|
|
156
|
-
shutdownGraceTime: '10 seconds',
|
|
157
|
-
...(this.options.workerOptions || {}),
|
|
158
|
-
});
|
|
159
|
-
this.workerRunPromise = worker.run().catch((error) => {
|
|
160
|
-
this.logger.error('Worker runtime error', { error: error.message });
|
|
161
|
-
this.initializationError = error;
|
|
162
|
-
this.isRunning = false;
|
|
163
|
-
});
|
|
164
|
-
this.connection = tempConnection;
|
|
165
|
-
this.worker = worker;
|
|
166
|
-
this.isRunning = true;
|
|
167
|
-
this.logger.log('Worker initialized successfully');
|
|
168
|
-
}
|
|
169
|
-
catch (error) {
|
|
170
|
-
if (tempConnection) {
|
|
171
|
-
await tempConnection.close().catch((closeError) => {
|
|
172
|
-
this.logger.error('Error closing temporary connection during initialization failure', {
|
|
173
|
-
error: closeError.message,
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
throw error;
|
|
178
|
-
}
|
|
179
|
-
finally {
|
|
180
|
-
this.isInitializing = false;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
async getStatus() {
|
|
184
|
-
return {
|
|
185
|
-
isRunning: this.isRunning,
|
|
186
|
-
isInitializing: this.isInitializing,
|
|
187
|
-
isShuttingDown: this.isShuttingDown,
|
|
188
|
-
error: this.initializationError,
|
|
189
|
-
taskQueue: this.options.taskQueue,
|
|
190
|
-
namespace: this.options.namespace,
|
|
191
|
-
};
|
|
173
|
+
getWorker() {
|
|
174
|
+
return this.worker;
|
|
192
175
|
}
|
|
193
176
|
};
|
|
194
177
|
exports.WorkerManager = WorkerManager;
|
|
195
178
|
exports.WorkerManager = WorkerManager = WorkerManager_1 = __decorate([
|
|
196
179
|
(0, common_1.Injectable)(),
|
|
197
|
-
__param(0, (0, common_1.Inject)(constants_1.
|
|
198
|
-
__metadata("design:paramtypes", [Object, core_1.
|
|
180
|
+
__param(0, (0, common_1.Inject)(constants_1.TEMPORAL_WORKER_MODULE_OPTIONS)),
|
|
181
|
+
__metadata("design:paramtypes", [Object, core_1.DiscoveryService,
|
|
182
|
+
temporal_metadata_accessor_1.TemporalMetadataAccessor])
|
|
199
183
|
], WorkerManager);
|
|
200
184
|
//# sourceMappingURL=worker-manager.service.js.map
|