atomic-queues 1.0.16 → 1.1.1
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 +373 -71
- package/dist/decorators/decorators.d.ts +204 -19
- package/dist/decorators/decorators.d.ts.map +1 -1
- package/dist/decorators/decorators.js +245 -25
- package/dist/decorators/decorators.js.map +1 -1
- package/dist/module/atomic-queues.module.d.ts.map +1 -1
- package/dist/module/atomic-queues.module.js +13 -2
- package/dist/module/atomic-queues.module.js.map +1 -1
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +1 -0
- package/dist/services/index.js.map +1 -1
- package/dist/services/processor-discovery/index.d.ts +2 -0
- package/dist/services/processor-discovery/index.d.ts.map +1 -0
- package/dist/services/processor-discovery/index.js +18 -0
- package/dist/services/processor-discovery/index.js.map +1 -0
- package/dist/services/processor-discovery/processor-discovery.service.d.ts +141 -0
- package/dist/services/processor-discovery/processor-discovery.service.d.ts.map +1 -0
- package/dist/services/processor-discovery/processor-discovery.service.js +378 -0
- package/dist/services/processor-discovery/processor-discovery.service.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,15 +1,80 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
2
|
+
import { IWorkerConfig } from '../domain';
|
|
1
3
|
/**
|
|
2
4
|
* Metadata keys for decorators
|
|
3
5
|
*/
|
|
4
6
|
export declare const ATOMIC_PROCESSOR_METADATA = "atomic:processor";
|
|
5
7
|
export declare const ENTITY_TYPE_METADATA = "atomic:entity-type";
|
|
6
8
|
export declare const JOB_TYPE_METADATA = "atomic:job-type";
|
|
9
|
+
export declare const WORKER_PROCESSOR_METADATA = "atomic:worker-processor";
|
|
10
|
+
export declare const JOB_HANDLER_METADATA = "atomic:job-handler";
|
|
11
|
+
export declare const ENTITY_SCALER_METADATA = "atomic:entity-scaler";
|
|
12
|
+
export declare const GET_ACTIVE_ENTITIES_METADATA = "atomic:get-active-entities";
|
|
13
|
+
export declare const GET_DESIRED_WORKER_COUNT_METADATA = "atomic:get-desired-worker-count";
|
|
14
|
+
export declare const ON_SPAWN_WORKER_METADATA = "atomic:on-spawn-worker";
|
|
15
|
+
export declare const ON_TERMINATE_WORKER_METADATA = "atomic:on-terminate-worker";
|
|
7
16
|
/**
|
|
8
|
-
* @
|
|
17
|
+
* Options for @WorkerProcessor decorator
|
|
18
|
+
*/
|
|
19
|
+
export interface WorkerProcessorOptions {
|
|
20
|
+
/** Entity type this processor handles (e.g., 'table', 'user') */
|
|
21
|
+
entityType: string;
|
|
22
|
+
/** Function to generate queue name from entityId */
|
|
23
|
+
queueName?: string | ((entityId: string) => string);
|
|
24
|
+
/** Function to generate worker name from entityId */
|
|
25
|
+
workerName?: string | ((entityId: string) => string);
|
|
26
|
+
/** Worker configuration */
|
|
27
|
+
workerConfig?: IWorkerConfig;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Options for @EntityScaler decorator
|
|
31
|
+
*/
|
|
32
|
+
export interface EntityScalerOptions {
|
|
33
|
+
/** Entity type this scaler handles */
|
|
34
|
+
entityType: string;
|
|
35
|
+
/** Maximum workers per entity */
|
|
36
|
+
maxWorkersPerEntity?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Stored job handler metadata
|
|
40
|
+
*/
|
|
41
|
+
export interface JobHandlerMetadata {
|
|
42
|
+
jobName: string;
|
|
43
|
+
methodName: string;
|
|
44
|
+
isWildcard: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Stored worker processor metadata
|
|
48
|
+
*/
|
|
49
|
+
export interface WorkerProcessorMetadata {
|
|
50
|
+
entityType: string;
|
|
51
|
+
queueNameFn: (entityId: string) => string;
|
|
52
|
+
workerNameFn: (entityId: string) => string;
|
|
53
|
+
workerConfig: IWorkerConfig;
|
|
54
|
+
targetClass: Type<any>;
|
|
55
|
+
jobHandlers: Map<string, JobHandlerMetadata>;
|
|
56
|
+
wildcardHandler?: JobHandlerMetadata;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Stored entity scaler metadata
|
|
60
|
+
*/
|
|
61
|
+
export interface EntityScalerMetadata {
|
|
62
|
+
entityType: string;
|
|
63
|
+
maxWorkersPerEntity: number;
|
|
64
|
+
targetClass: Type<any>;
|
|
65
|
+
getActiveEntitiesMethod?: string;
|
|
66
|
+
getDesiredWorkerCountMethod?: string;
|
|
67
|
+
onSpawnWorkerMethod?: string;
|
|
68
|
+
onTerminateWorkerMethod?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* @AtomicProcessor decorator (LEGACY)
|
|
9
72
|
*
|
|
10
73
|
* Marks a method as an atomic job processor.
|
|
11
74
|
* Can be used on handler methods to auto-register them.
|
|
12
75
|
*
|
|
76
|
+
* @deprecated Use @WorkerProcessor class decorator with @JobHandler method decorators instead
|
|
77
|
+
*
|
|
13
78
|
* @example
|
|
14
79
|
* ```typescript
|
|
15
80
|
* @Injectable()
|
|
@@ -23,45 +88,165 @@ export declare const JOB_TYPE_METADATA = "atomic:job-type";
|
|
|
23
88
|
*/
|
|
24
89
|
export declare const AtomicProcessor: (jobType: string) => MethodDecorator;
|
|
25
90
|
/**
|
|
26
|
-
* @EntityType decorator
|
|
91
|
+
* @EntityType decorator (LEGACY)
|
|
27
92
|
*
|
|
28
93
|
* Marks a class or method with an entity type for automatic registration.
|
|
29
94
|
*
|
|
95
|
+
* @deprecated Use @WorkerProcessor or @EntityScaler class decorators instead
|
|
96
|
+
*/
|
|
97
|
+
export declare const EntityType: (entityType: string) => ClassDecorator & MethodDecorator;
|
|
98
|
+
/**
|
|
99
|
+
* @JobType decorator (LEGACY)
|
|
100
|
+
*
|
|
101
|
+
* Specifies the job type for a processor method.
|
|
102
|
+
*
|
|
103
|
+
* @deprecated Use @JobHandler method decorator instead
|
|
104
|
+
*/
|
|
105
|
+
export declare const JobType: (jobType: string) => MethodDecorator;
|
|
106
|
+
/**
|
|
107
|
+
* @InjectAtomicQueue decorator
|
|
108
|
+
*
|
|
109
|
+
* Custom parameter decorator for injecting a specific queue.
|
|
110
|
+
* Useful when you need direct access to a queue in a service.
|
|
111
|
+
*/
|
|
112
|
+
export declare const InjectAtomicQueue: (entityType: string, entityId?: string) => ParameterDecorator;
|
|
113
|
+
/**
|
|
114
|
+
* @WorkerProcessor class decorator
|
|
115
|
+
*
|
|
116
|
+
* Marks a class as a worker processor for a specific entity type.
|
|
117
|
+
* Combined with @JobHandler method decorators, this enables declarative
|
|
118
|
+
* job processing with automatic worker creation and management.
|
|
119
|
+
*
|
|
30
120
|
* @example
|
|
31
121
|
* ```typescript
|
|
122
|
+
* @WorkerProcessor({
|
|
123
|
+
* entityType: 'table',
|
|
124
|
+
* queueName: (tableId) => `${tableId}-queue`,
|
|
125
|
+
* workerName: (tableId) => `table-worker-${tableId}`,
|
|
126
|
+
* workerConfig: {
|
|
127
|
+
* concurrency: 1,
|
|
128
|
+
* heartbeatTTL: 3,
|
|
129
|
+
* }
|
|
130
|
+
* })
|
|
32
131
|
* @Injectable()
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
132
|
+
* export class TableWorkerProcessor {
|
|
133
|
+
* constructor(private readonly commandBus: CommandBus) {}
|
|
134
|
+
*
|
|
135
|
+
* @JobHandler('make-bet')
|
|
136
|
+
* async handleMakeBet(job: Job<MakeBetData>, entityId: string) {
|
|
137
|
+
* return this.commandBus.execute(new MakeBetCommand(entityId, job.data));
|
|
138
|
+
* }
|
|
139
|
+
*
|
|
140
|
+
* @JobHandler('*') // Wildcard handler for any unmatched job
|
|
141
|
+
* async handleDynamic(job: Job, entityId: string) {
|
|
142
|
+
* // Dynamic handling
|
|
143
|
+
* }
|
|
36
144
|
* }
|
|
37
145
|
* ```
|
|
38
146
|
*/
|
|
39
|
-
export declare
|
|
147
|
+
export declare function WorkerProcessor(options: WorkerProcessorOptions): ClassDecorator;
|
|
40
148
|
/**
|
|
41
|
-
* @
|
|
149
|
+
* @JobHandler method decorator
|
|
42
150
|
*
|
|
43
|
-
*
|
|
151
|
+
* Marks a method as a handler for a specific job name.
|
|
152
|
+
* Use '*' as jobName to create a wildcard handler that catches
|
|
153
|
+
* any jobs not matched by specific handlers.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* @JobHandler('make-bet')
|
|
158
|
+
* async handleMakeBet(job: Job<MakeBetData>, entityId: string) {
|
|
159
|
+
* // Handle make-bet jobs
|
|
160
|
+
* }
|
|
161
|
+
*
|
|
162
|
+
* @JobHandler('*')
|
|
163
|
+
* async handleOther(job: Job, entityId: string) {
|
|
164
|
+
* // Handle any other jobs
|
|
165
|
+
* }
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export declare function JobHandler(jobName: string): MethodDecorator;
|
|
169
|
+
/**
|
|
170
|
+
* @EntityScaler class decorator
|
|
171
|
+
*
|
|
172
|
+
* Marks a class as an entity scaler provider for a specific entity type.
|
|
173
|
+
* Methods decorated with @GetActiveEntities, @GetDesiredWorkerCount,
|
|
174
|
+
* @OnSpawnWorker, and @OnTerminateWorker define the scaling behavior.
|
|
44
175
|
*
|
|
45
176
|
* @example
|
|
46
177
|
* ```typescript
|
|
178
|
+
* @EntityScaler({
|
|
179
|
+
* entityType: 'table',
|
|
180
|
+
* maxWorkersPerEntity: 1,
|
|
181
|
+
* })
|
|
47
182
|
* @Injectable()
|
|
48
|
-
* export class
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
183
|
+
* export class TableEntityScaler {
|
|
184
|
+
* constructor(private readonly redis: Redis) {}
|
|
185
|
+
*
|
|
186
|
+
* @GetActiveEntities()
|
|
187
|
+
* async getAllTables(): Promise<string[]> {
|
|
188
|
+
* // Return all table IDs that need workers
|
|
189
|
+
* }
|
|
190
|
+
*
|
|
191
|
+
* @GetDesiredWorkerCount()
|
|
192
|
+
* async getWorkerCount(entityId: string): Promise<number> {
|
|
193
|
+
* return 1; // Each table gets 1 worker
|
|
194
|
+
* }
|
|
195
|
+
*
|
|
196
|
+
* @OnSpawnWorker()
|
|
197
|
+
* async spawnWorker(entityId: string): Promise<void> {
|
|
198
|
+
* // Called when a worker should be spawned
|
|
52
199
|
* }
|
|
53
200
|
* }
|
|
54
201
|
* ```
|
|
55
202
|
*/
|
|
56
|
-
export declare
|
|
203
|
+
export declare function EntityScaler(options: EntityScalerOptions): ClassDecorator;
|
|
57
204
|
/**
|
|
58
|
-
* @
|
|
205
|
+
* @GetActiveEntities method decorator
|
|
59
206
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
207
|
+
* Marks a method that returns all active entity IDs for scaling decisions.
|
|
208
|
+
* Used within an @EntityScaler class.
|
|
209
|
+
*/
|
|
210
|
+
export declare function GetActiveEntities(): MethodDecorator;
|
|
211
|
+
/**
|
|
212
|
+
* @GetDesiredWorkerCount method decorator
|
|
62
213
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
214
|
+
* Marks a method that returns the desired worker count for an entity.
|
|
215
|
+
* Used within an @EntityScaler class.
|
|
65
216
|
*/
|
|
66
|
-
export declare
|
|
217
|
+
export declare function GetDesiredWorkerCount(): MethodDecorator;
|
|
218
|
+
/**
|
|
219
|
+
* @OnSpawnWorker method decorator
|
|
220
|
+
*
|
|
221
|
+
* Marks a method that is called when a worker should be spawned.
|
|
222
|
+
* Used within an @EntityScaler class.
|
|
223
|
+
*/
|
|
224
|
+
export declare function OnSpawnWorker(): MethodDecorator;
|
|
225
|
+
/**
|
|
226
|
+
* @OnTerminateWorker method decorator
|
|
227
|
+
*
|
|
228
|
+
* Marks a method that is called when a worker should be terminated.
|
|
229
|
+
* Used within an @EntityScaler class.
|
|
230
|
+
*/
|
|
231
|
+
export declare function OnTerminateWorker(): MethodDecorator;
|
|
232
|
+
/**
|
|
233
|
+
* Get WorkerProcessor metadata from a class
|
|
234
|
+
*/
|
|
235
|
+
export declare function getWorkerProcessorMetadata(target: Type<any>): WorkerProcessorOptions | undefined;
|
|
236
|
+
/**
|
|
237
|
+
* Get all JobHandler metadata from a class
|
|
238
|
+
*/
|
|
239
|
+
export declare function getJobHandlerMetadata(target: Type<any>): JobHandlerMetadata[];
|
|
240
|
+
/**
|
|
241
|
+
* Get EntityScaler metadata from a class
|
|
242
|
+
*/
|
|
243
|
+
export declare function getEntityScalerMetadata(target: Type<any>): EntityScalerOptions | undefined;
|
|
244
|
+
/**
|
|
245
|
+
* Check if a class is a WorkerProcessor
|
|
246
|
+
*/
|
|
247
|
+
export declare function isWorkerProcessor(target: Type<any>): boolean;
|
|
248
|
+
/**
|
|
249
|
+
* Check if a class is an EntityScaler
|
|
250
|
+
*/
|
|
251
|
+
export declare function isEntityScaler(target: Type<any>): boolean;
|
|
67
252
|
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/decorators/decorators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/decorators/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAM1C;;GAEG;AACH,eAAO,MAAM,yBAAyB,qBAAqB,CAAC;AAC5D,eAAO,MAAM,oBAAoB,uBAAuB,CAAC;AACzD,eAAO,MAAM,iBAAiB,oBAAoB,CAAC;AACnD,eAAO,MAAM,yBAAyB,4BAA4B,CAAC;AACnE,eAAO,MAAM,oBAAoB,uBAAuB,CAAC;AACzD,eAAO,MAAM,sBAAsB,yBAAyB,CAAC;AAC7D,eAAO,MAAM,4BAA4B,+BAA+B,CAAC;AACzE,eAAO,MAAM,iCAAiC,oCAAoC,CAAC;AACnF,eAAO,MAAM,wBAAwB,2BAA2B,CAAC;AACjE,eAAO,MAAM,4BAA4B,+BAA+B,CAAC;AAMzE;;GAEG;AAC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uB,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,mBAAmB,GAAG,SAAS,CAE1F;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAE5D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAEzD"}
|
|
@@ -1,19 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InjectAtomicQueue = exports.JobType = exports.EntityType = exports.AtomicProcessor = exports.JOB_TYPE_METADATA = exports.ENTITY_TYPE_METADATA = exports.ATOMIC_PROCESSOR_METADATA = void 0;
|
|
3
|
+
exports.InjectAtomicQueue = exports.JobType = exports.EntityType = exports.AtomicProcessor = exports.ON_TERMINATE_WORKER_METADATA = exports.ON_SPAWN_WORKER_METADATA = exports.GET_DESIRED_WORKER_COUNT_METADATA = exports.GET_ACTIVE_ENTITIES_METADATA = exports.ENTITY_SCALER_METADATA = exports.JOB_HANDLER_METADATA = exports.WORKER_PROCESSOR_METADATA = exports.JOB_TYPE_METADATA = exports.ENTITY_TYPE_METADATA = exports.ATOMIC_PROCESSOR_METADATA = void 0;
|
|
4
|
+
exports.WorkerProcessor = WorkerProcessor;
|
|
5
|
+
exports.JobHandler = JobHandler;
|
|
6
|
+
exports.EntityScaler = EntityScaler;
|
|
7
|
+
exports.GetActiveEntities = GetActiveEntities;
|
|
8
|
+
exports.GetDesiredWorkerCount = GetDesiredWorkerCount;
|
|
9
|
+
exports.OnSpawnWorker = OnSpawnWorker;
|
|
10
|
+
exports.OnTerminateWorker = OnTerminateWorker;
|
|
11
|
+
exports.getWorkerProcessorMetadata = getWorkerProcessorMetadata;
|
|
12
|
+
exports.getJobHandlerMetadata = getJobHandlerMetadata;
|
|
13
|
+
exports.getEntityScalerMetadata = getEntityScalerMetadata;
|
|
14
|
+
exports.isWorkerProcessor = isWorkerProcessor;
|
|
15
|
+
exports.isEntityScaler = isEntityScaler;
|
|
4
16
|
const common_1 = require("@nestjs/common");
|
|
17
|
+
// =============================================================================
|
|
18
|
+
// METADATA KEYS
|
|
19
|
+
// =============================================================================
|
|
5
20
|
/**
|
|
6
21
|
* Metadata keys for decorators
|
|
7
22
|
*/
|
|
8
23
|
exports.ATOMIC_PROCESSOR_METADATA = 'atomic:processor';
|
|
9
24
|
exports.ENTITY_TYPE_METADATA = 'atomic:entity-type';
|
|
10
25
|
exports.JOB_TYPE_METADATA = 'atomic:job-type';
|
|
26
|
+
exports.WORKER_PROCESSOR_METADATA = 'atomic:worker-processor';
|
|
27
|
+
exports.JOB_HANDLER_METADATA = 'atomic:job-handler';
|
|
28
|
+
exports.ENTITY_SCALER_METADATA = 'atomic:entity-scaler';
|
|
29
|
+
exports.GET_ACTIVE_ENTITIES_METADATA = 'atomic:get-active-entities';
|
|
30
|
+
exports.GET_DESIRED_WORKER_COUNT_METADATA = 'atomic:get-desired-worker-count';
|
|
31
|
+
exports.ON_SPAWN_WORKER_METADATA = 'atomic:on-spawn-worker';
|
|
32
|
+
exports.ON_TERMINATE_WORKER_METADATA = 'atomic:on-terminate-worker';
|
|
33
|
+
// =============================================================================
|
|
34
|
+
// LEGACY DECORATORS (Preserved for backward compatibility)
|
|
35
|
+
// =============================================================================
|
|
11
36
|
/**
|
|
12
|
-
* @AtomicProcessor decorator
|
|
37
|
+
* @AtomicProcessor decorator (LEGACY)
|
|
13
38
|
*
|
|
14
39
|
* Marks a method as an atomic job processor.
|
|
15
40
|
* Can be used on handler methods to auto-register them.
|
|
16
41
|
*
|
|
42
|
+
* @deprecated Use @WorkerProcessor class decorator with @JobHandler method decorators instead
|
|
43
|
+
*
|
|
17
44
|
* @example
|
|
18
45
|
* ```typescript
|
|
19
46
|
* @Injectable()
|
|
@@ -30,38 +57,22 @@ const AtomicProcessor = (jobType) => {
|
|
|
30
57
|
};
|
|
31
58
|
exports.AtomicProcessor = AtomicProcessor;
|
|
32
59
|
/**
|
|
33
|
-
* @EntityType decorator
|
|
60
|
+
* @EntityType decorator (LEGACY)
|
|
34
61
|
*
|
|
35
62
|
* Marks a class or method with an entity type for automatic registration.
|
|
36
63
|
*
|
|
37
|
-
* @
|
|
38
|
-
* ```typescript
|
|
39
|
-
* @Injectable()
|
|
40
|
-
* @EntityType('user')
|
|
41
|
-
* export class UserWorkerService {
|
|
42
|
-
* // All methods in this service are associated with 'user' entity type
|
|
43
|
-
* }
|
|
44
|
-
* ```
|
|
64
|
+
* @deprecated Use @WorkerProcessor or @EntityScaler class decorators instead
|
|
45
65
|
*/
|
|
46
66
|
const EntityType = (entityType) => {
|
|
47
67
|
return (0, common_1.SetMetadata)(exports.ENTITY_TYPE_METADATA, entityType);
|
|
48
68
|
};
|
|
49
69
|
exports.EntityType = EntityType;
|
|
50
70
|
/**
|
|
51
|
-
* @JobType decorator
|
|
71
|
+
* @JobType decorator (LEGACY)
|
|
52
72
|
*
|
|
53
73
|
* Specifies the job type for a processor method.
|
|
54
74
|
*
|
|
55
|
-
* @
|
|
56
|
-
* ```typescript
|
|
57
|
-
* @Injectable()
|
|
58
|
-
* export class TableProcessor {
|
|
59
|
-
* @JobType('make-bet')
|
|
60
|
-
* async handleMakeBet(job: Job) {
|
|
61
|
-
* // Process bet
|
|
62
|
-
* }
|
|
63
|
-
* }
|
|
64
|
-
* ```
|
|
75
|
+
* @deprecated Use @JobHandler method decorator instead
|
|
65
76
|
*/
|
|
66
77
|
const JobType = (jobType) => {
|
|
67
78
|
return (0, common_1.SetMetadata)(exports.JOB_TYPE_METADATA, jobType);
|
|
@@ -72,9 +83,6 @@ exports.JobType = JobType;
|
|
|
72
83
|
*
|
|
73
84
|
* Custom parameter decorator for injecting a specific queue.
|
|
74
85
|
* Useful when you need direct access to a queue in a service.
|
|
75
|
-
*
|
|
76
|
-
* Note: This is a placeholder - actual implementation would use
|
|
77
|
-
* NestJS's custom parameter decorators with module injection.
|
|
78
86
|
*/
|
|
79
87
|
const InjectAtomicQueue = (entityType, entityId) => {
|
|
80
88
|
return (target, propertyKey, parameterIndex) => {
|
|
@@ -88,4 +96,216 @@ const InjectAtomicQueue = (entityType, entityId) => {
|
|
|
88
96
|
};
|
|
89
97
|
};
|
|
90
98
|
exports.InjectAtomicQueue = InjectAtomicQueue;
|
|
99
|
+
// =============================================================================
|
|
100
|
+
// NEW DECORATORS - Worker-First Architecture
|
|
101
|
+
// =============================================================================
|
|
102
|
+
/**
|
|
103
|
+
* @WorkerProcessor class decorator
|
|
104
|
+
*
|
|
105
|
+
* Marks a class as a worker processor for a specific entity type.
|
|
106
|
+
* Combined with @JobHandler method decorators, this enables declarative
|
|
107
|
+
* job processing with automatic worker creation and management.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* @WorkerProcessor({
|
|
112
|
+
* entityType: 'table',
|
|
113
|
+
* queueName: (tableId) => `${tableId}-queue`,
|
|
114
|
+
* workerName: (tableId) => `table-worker-${tableId}`,
|
|
115
|
+
* workerConfig: {
|
|
116
|
+
* concurrency: 1,
|
|
117
|
+
* heartbeatTTL: 3,
|
|
118
|
+
* }
|
|
119
|
+
* })
|
|
120
|
+
* @Injectable()
|
|
121
|
+
* export class TableWorkerProcessor {
|
|
122
|
+
* constructor(private readonly commandBus: CommandBus) {}
|
|
123
|
+
*
|
|
124
|
+
* @JobHandler('make-bet')
|
|
125
|
+
* async handleMakeBet(job: Job<MakeBetData>, entityId: string) {
|
|
126
|
+
* return this.commandBus.execute(new MakeBetCommand(entityId, job.data));
|
|
127
|
+
* }
|
|
128
|
+
*
|
|
129
|
+
* @JobHandler('*') // Wildcard handler for any unmatched job
|
|
130
|
+
* async handleDynamic(job: Job, entityId: string) {
|
|
131
|
+
* // Dynamic handling
|
|
132
|
+
* }
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
function WorkerProcessor(options) {
|
|
137
|
+
return (target) => {
|
|
138
|
+
// Store the options on the class
|
|
139
|
+
Reflect.defineMetadata(exports.WORKER_PROCESSOR_METADATA, options, target);
|
|
140
|
+
// Mark as injectable if not already
|
|
141
|
+
if (!Reflect.hasMetadata('injectable', target)) {
|
|
142
|
+
Reflect.defineMetadata('injectable', true, target);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @JobHandler method decorator
|
|
148
|
+
*
|
|
149
|
+
* Marks a method as a handler for a specific job name.
|
|
150
|
+
* Use '*' as jobName to create a wildcard handler that catches
|
|
151
|
+
* any jobs not matched by specific handlers.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* @JobHandler('make-bet')
|
|
156
|
+
* async handleMakeBet(job: Job<MakeBetData>, entityId: string) {
|
|
157
|
+
* // Handle make-bet jobs
|
|
158
|
+
* }
|
|
159
|
+
*
|
|
160
|
+
* @JobHandler('*')
|
|
161
|
+
* async handleOther(job: Job, entityId: string) {
|
|
162
|
+
* // Handle any other jobs
|
|
163
|
+
* }
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
function JobHandler(jobName) {
|
|
167
|
+
return (target, propertyKey, descriptor) => {
|
|
168
|
+
const methodName = String(propertyKey);
|
|
169
|
+
const isWildcard = jobName === '*';
|
|
170
|
+
// Store handler metadata on the method
|
|
171
|
+
const metadata = {
|
|
172
|
+
jobName,
|
|
173
|
+
methodName,
|
|
174
|
+
isWildcard,
|
|
175
|
+
};
|
|
176
|
+
Reflect.defineMetadata(exports.JOB_HANDLER_METADATA, metadata, target, propertyKey);
|
|
177
|
+
// Collect all handlers on the class
|
|
178
|
+
const existingHandlers = Reflect.getMetadata(exports.JOB_HANDLER_METADATA, target.constructor) || [];
|
|
179
|
+
existingHandlers.push(metadata);
|
|
180
|
+
Reflect.defineMetadata(exports.JOB_HANDLER_METADATA, existingHandlers, target.constructor);
|
|
181
|
+
return descriptor;
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* @EntityScaler class decorator
|
|
186
|
+
*
|
|
187
|
+
* Marks a class as an entity scaler provider for a specific entity type.
|
|
188
|
+
* Methods decorated with @GetActiveEntities, @GetDesiredWorkerCount,
|
|
189
|
+
* @OnSpawnWorker, and @OnTerminateWorker define the scaling behavior.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* @EntityScaler({
|
|
194
|
+
* entityType: 'table',
|
|
195
|
+
* maxWorkersPerEntity: 1,
|
|
196
|
+
* })
|
|
197
|
+
* @Injectable()
|
|
198
|
+
* export class TableEntityScaler {
|
|
199
|
+
* constructor(private readonly redis: Redis) {}
|
|
200
|
+
*
|
|
201
|
+
* @GetActiveEntities()
|
|
202
|
+
* async getAllTables(): Promise<string[]> {
|
|
203
|
+
* // Return all table IDs that need workers
|
|
204
|
+
* }
|
|
205
|
+
*
|
|
206
|
+
* @GetDesiredWorkerCount()
|
|
207
|
+
* async getWorkerCount(entityId: string): Promise<number> {
|
|
208
|
+
* return 1; // Each table gets 1 worker
|
|
209
|
+
* }
|
|
210
|
+
*
|
|
211
|
+
* @OnSpawnWorker()
|
|
212
|
+
* async spawnWorker(entityId: string): Promise<void> {
|
|
213
|
+
* // Called when a worker should be spawned
|
|
214
|
+
* }
|
|
215
|
+
* }
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
function EntityScaler(options) {
|
|
219
|
+
return (target) => {
|
|
220
|
+
Reflect.defineMetadata(exports.ENTITY_SCALER_METADATA, options, target);
|
|
221
|
+
if (!Reflect.hasMetadata('injectable', target)) {
|
|
222
|
+
Reflect.defineMetadata('injectable', true, target);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* @GetActiveEntities method decorator
|
|
228
|
+
*
|
|
229
|
+
* Marks a method that returns all active entity IDs for scaling decisions.
|
|
230
|
+
* Used within an @EntityScaler class.
|
|
231
|
+
*/
|
|
232
|
+
function GetActiveEntities() {
|
|
233
|
+
return (target, propertyKey, descriptor) => {
|
|
234
|
+
Reflect.defineMetadata(exports.GET_ACTIVE_ENTITIES_METADATA, true, target, propertyKey);
|
|
235
|
+
Reflect.defineMetadata(exports.GET_ACTIVE_ENTITIES_METADATA + ':method', String(propertyKey), target.constructor);
|
|
236
|
+
return descriptor;
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* @GetDesiredWorkerCount method decorator
|
|
241
|
+
*
|
|
242
|
+
* Marks a method that returns the desired worker count for an entity.
|
|
243
|
+
* Used within an @EntityScaler class.
|
|
244
|
+
*/
|
|
245
|
+
function GetDesiredWorkerCount() {
|
|
246
|
+
return (target, propertyKey, descriptor) => {
|
|
247
|
+
Reflect.defineMetadata(exports.GET_DESIRED_WORKER_COUNT_METADATA, true, target, propertyKey);
|
|
248
|
+
Reflect.defineMetadata(exports.GET_DESIRED_WORKER_COUNT_METADATA + ':method', String(propertyKey), target.constructor);
|
|
249
|
+
return descriptor;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* @OnSpawnWorker method decorator
|
|
254
|
+
*
|
|
255
|
+
* Marks a method that is called when a worker should be spawned.
|
|
256
|
+
* Used within an @EntityScaler class.
|
|
257
|
+
*/
|
|
258
|
+
function OnSpawnWorker() {
|
|
259
|
+
return (target, propertyKey, descriptor) => {
|
|
260
|
+
Reflect.defineMetadata(exports.ON_SPAWN_WORKER_METADATA, true, target, propertyKey);
|
|
261
|
+
Reflect.defineMetadata(exports.ON_SPAWN_WORKER_METADATA + ':method', String(propertyKey), target.constructor);
|
|
262
|
+
return descriptor;
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* @OnTerminateWorker method decorator
|
|
267
|
+
*
|
|
268
|
+
* Marks a method that is called when a worker should be terminated.
|
|
269
|
+
* Used within an @EntityScaler class.
|
|
270
|
+
*/
|
|
271
|
+
function OnTerminateWorker() {
|
|
272
|
+
return (target, propertyKey, descriptor) => {
|
|
273
|
+
Reflect.defineMetadata(exports.ON_TERMINATE_WORKER_METADATA, true, target, propertyKey);
|
|
274
|
+
Reflect.defineMetadata(exports.ON_TERMINATE_WORKER_METADATA + ':method', String(propertyKey), target.constructor);
|
|
275
|
+
return descriptor;
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
// =============================================================================
|
|
279
|
+
// UTILITY FUNCTIONS
|
|
280
|
+
// =============================================================================
|
|
281
|
+
/**
|
|
282
|
+
* Get WorkerProcessor metadata from a class
|
|
283
|
+
*/
|
|
284
|
+
function getWorkerProcessorMetadata(target) {
|
|
285
|
+
return Reflect.getMetadata(exports.WORKER_PROCESSOR_METADATA, target);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Get all JobHandler metadata from a class
|
|
289
|
+
*/
|
|
290
|
+
function getJobHandlerMetadata(target) {
|
|
291
|
+
return Reflect.getMetadata(exports.JOB_HANDLER_METADATA, target) || [];
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Get EntityScaler metadata from a class
|
|
295
|
+
*/
|
|
296
|
+
function getEntityScalerMetadata(target) {
|
|
297
|
+
return Reflect.getMetadata(exports.ENTITY_SCALER_METADATA, target);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Check if a class is a WorkerProcessor
|
|
301
|
+
*/
|
|
302
|
+
function isWorkerProcessor(target) {
|
|
303
|
+
return Reflect.hasMetadata(exports.WORKER_PROCESSOR_METADATA, target);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Check if a class is an EntityScaler
|
|
307
|
+
*/
|
|
308
|
+
function isEntityScaler(target) {
|
|
309
|
+
return Reflect.hasMetadata(exports.ENTITY_SCALER_METADATA, target);
|
|
310
|
+
}
|
|
91
311
|
//# sourceMappingURL=decorators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/decorators/decorators.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/decorators/decorators.ts"],"names":[],"mappings":";;;AA4MA,0CAUC;AAsBD,gCAyBC;AAoCD,oCAQC;AAQD,8CAcC;AAQD,sDAcC;AAQD,sCAcC;AAQD,8CAcC;AASD,gEAEC;AAKD,sDAEC;AAKD,0DAEC;AAKD,8CAEC;AAKD,wCAEC;AAhbD,2CAAmD;AAGnD,gFAAgF;AAChF,gBAAgB;AAChB,gFAAgF;AAEhF;;GAEG;AACU,QAAA,yBAAyB,GAAG,kBAAkB,CAAC;AAC/C,QAAA,oBAAoB,GAAG,oBAAoB,CAAC;AAC5C,QAAA,iBAAiB,GAAG,iBAAiB,CAAC;AACtC,QAAA,yBAAyB,GAAG,yBAAyB,CAAC;AACtD,QAAA,oBAAoB,GAAG,oBAAoB,CAAC;AAC5C,QAAA,sBAAsB,GAAG,sBAAsB,CAAC;AAChD,QAAA,4BAA4B,GAAG,4BAA4B,CAAC;AAC5D,QAAA,iCAAiC,GAAG,iCAAiC,CAAC;AACtE,QAAA,wBAAwB,GAAG,wBAAwB,CAAC;AACpD,QAAA,4BAA4B,GAAG,4BAA4B,CAAC;AAiEzE,gFAAgF;AAChF,2DAA2D;AAC3D,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;GAkBG;AACI,MAAM,eAAe,GAAG,CAAC,OAAe,EAAmB,EAAE;IAClE,OAAO,IAAA,oBAAW,EAAC,iCAAyB,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC,CAAC;AAFW,QAAA,eAAe,mBAE1B;AAEF;;;;;;GAMG;AACI,MAAM,UAAU,GAAG,CAAC,UAAkB,EAAoC,EAAE;IACjF,OAAO,IAAA,oBAAW,EAAC,4BAAoB,EAAE,UAAU,CAAC,CAAC;AACvD,CAAC,CAAC;AAFW,QAAA,UAAU,cAErB;AAEF;;;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AAoB;AACpB,gFAAgF;AAEhF;;GAEG;AACH,SAAgB,0BAA0B,CAAC,MAAiB;IAC1D,OAAO,OAAO,CAAC,WAAW,CAAC,iCAAyB,EAAE,MAAM,CAAC,CAAC;AAChE,CAAC;AAED;;GAEG;AACH,SAAgB,qBAAqB,CAAC,MAAiB;IACrD,OAAO,OAAO,CAAC,WAAW,CAAC,4BAAoB,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;AACjE,CAAC;AAED;;GAEG;AACH,SAAgB,uBAAuB,CAAC,MAAiB;IACvD,OAAO,OAAO,CAAC,WAAW,CAAC,8BAAsB,EAAE,MAAM,CAAC,CAAC;AAC7D,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,MAAiB;IACjD,OAAO,OAAO,CAAC,WAAW,CAAC,iCAAyB,EAAE,MAAM,CAAC,CAAC;AAChE,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,MAAiB;IAC9C,OAAO,OAAO,CAAC,WAAW,CAAC,8BAAsB,EAAE,MAAM,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atomic-queues.module.d.ts","sourceRoot":"","sources":["../../src/module/atomic-queues.module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAIb,IAAI,EACL,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"atomic-queues.module.d.ts","sourceRoot":"","sources":["../../src/module/atomic-queues.module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAIb,IAAI,EACL,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,yBAAyB,EAAe,MAAM,WAAW,CAAC;AAkBnE;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;OAEG;IACH,OAAO,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IAE1B;;OAEG;IACH,UAAU,EAAE,CACV,GAAG,IAAI,EAAE,OAAO,EAAE,KACf,OAAO,CAAC,yBAAyB,CAAC,GAAG,yBAAyB,CAAC;IAEpE;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;IAEnB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAmBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,qBAEa,kBAAkB;IAC7B;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,yBAAyB,GAAG,aAAa;IA0BhE;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,8BAA8B,GAAG,aAAa;IAyB3E;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE;QACzB,UAAU,EAAE,MAAM,CAAC;QACnB,qBAAqB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7D,kBAAkB,EAAE,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QAC5C,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B,GAAG,aAAa;IAgBjB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAuBlC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,yBAAyB;IAUxC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,wBAAwB;CAqBxC"}
|
|
@@ -12,6 +12,7 @@ var AtomicQueuesModule_1;
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.AtomicQueuesModule = void 0;
|
|
14
14
|
const common_1 = require("@nestjs/common");
|
|
15
|
+
const core_1 = require("@nestjs/core");
|
|
15
16
|
const ioredis_1 = __importDefault(require("ioredis"));
|
|
16
17
|
const services_1 = require("../services");
|
|
17
18
|
/**
|
|
@@ -28,6 +29,7 @@ const CORE_SERVICES = [
|
|
|
28
29
|
services_1.CronManagerService,
|
|
29
30
|
services_1.ServiceQueueManager,
|
|
30
31
|
services_1.ShutdownStateService,
|
|
32
|
+
services_1.ProcessorDiscoveryService,
|
|
31
33
|
];
|
|
32
34
|
/**
|
|
33
35
|
* AtomicQueuesModule
|
|
@@ -80,12 +82,15 @@ let AtomicQueuesModule = AtomicQueuesModule_1 = class AtomicQueuesModule {
|
|
|
80
82
|
module: AtomicQueuesModule_1,
|
|
81
83
|
// Note: CqrsModule should be imported by the consuming app, not here
|
|
82
84
|
// to avoid duplicate CommandBus/QueryBus instances
|
|
85
|
+
imports: [core_1.DiscoveryModule],
|
|
83
86
|
providers: [
|
|
84
87
|
{
|
|
85
88
|
provide: services_1.ATOMIC_QUEUES_CONFIG,
|
|
86
89
|
useValue: config,
|
|
87
90
|
},
|
|
88
91
|
redisProvider,
|
|
92
|
+
core_1.DiscoveryService,
|
|
93
|
+
core_1.MetadataScanner,
|
|
89
94
|
...CORE_SERVICES,
|
|
90
95
|
],
|
|
91
96
|
exports: [
|
|
@@ -105,8 +110,14 @@ let AtomicQueuesModule = AtomicQueuesModule_1 = class AtomicQueuesModule {
|
|
|
105
110
|
module: AtomicQueuesModule_1,
|
|
106
111
|
// Note: CqrsModule should be imported by the consuming app, not here
|
|
107
112
|
// to avoid duplicate CommandBus/QueryBus instances
|
|
108
|
-
imports: [...(options.imports || [])],
|
|
109
|
-
providers: [
|
|
113
|
+
imports: [core_1.DiscoveryModule, ...(options.imports || [])],
|
|
114
|
+
providers: [
|
|
115
|
+
configProvider,
|
|
116
|
+
redisProvider,
|
|
117
|
+
core_1.DiscoveryService,
|
|
118
|
+
core_1.MetadataScanner,
|
|
119
|
+
...CORE_SERVICES,
|
|
120
|
+
],
|
|
110
121
|
exports: [
|
|
111
122
|
services_1.ATOMIC_QUEUES_CONFIG,
|
|
112
123
|
services_1.ATOMIC_QUEUES_REDIS,
|