atomic-queues 1.4.1 → 1.6.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/README.md +300 -283
- package/dist/decorators/constants.d.ts +17 -0
- package/dist/decorators/constants.d.ts.map +1 -0
- package/dist/decorators/constants.js +23 -0
- package/dist/decorators/constants.js.map +1 -0
- package/dist/decorators/entity.decorators.d.ts +88 -0
- package/dist/decorators/entity.decorators.d.ts.map +1 -0
- package/dist/decorators/entity.decorators.js +150 -0
- package/dist/decorators/entity.decorators.js.map +1 -0
- package/dist/decorators/index.d.ts +9 -1
- package/dist/decorators/index.d.ts.map +1 -1
- package/dist/decorators/index.js +9 -1
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/interfaces.d.ts +130 -0
- package/dist/decorators/interfaces.d.ts.map +1 -0
- package/dist/decorators/interfaces.js +3 -0
- package/dist/decorators/interfaces.js.map +1 -0
- package/dist/decorators/job.decorators.d.ts +60 -0
- package/dist/decorators/job.decorators.d.ts.map +1 -0
- package/dist/decorators/job.decorators.js +97 -0
- package/dist/decorators/job.decorators.js.map +1 -0
- package/dist/decorators/legacy.decorators.d.ts +36 -0
- package/dist/decorators/legacy.decorators.d.ts.map +1 -0
- package/dist/decorators/legacy.decorators.js +61 -0
- package/dist/decorators/legacy.decorators.js.map +1 -0
- package/dist/decorators/metadata-readers.d.ts +31 -0
- package/dist/decorators/metadata-readers.d.ts.map +1 -0
- package/dist/decorators/metadata-readers.js +53 -0
- package/dist/decorators/metadata-readers.js.map +1 -0
- package/dist/decorators/registry.d.ts +2 -0
- package/dist/decorators/registry.d.ts.map +1 -0
- package/dist/decorators/registry.js +6 -0
- package/dist/decorators/registry.js.map +1 -0
- package/dist/decorators/scaler.decorators.d.ts +65 -0
- package/dist/decorators/scaler.decorators.d.ts.map +1 -0
- package/dist/decorators/scaler.decorators.js +103 -0
- package/dist/decorators/scaler.decorators.js.map +1 -0
- package/dist/decorators/type-guards.d.ts +18 -0
- package/dist/decorators/type-guards.d.ts.map +1 -0
- package/dist/decorators/type-guards.js +32 -0
- package/dist/decorators/type-guards.js.map +1 -0
- package/dist/decorators/utils.d.ts +20 -0
- package/dist/decorators/utils.d.ts.map +1 -0
- package/dist/decorators/utils.js +98 -0
- package/dist/decorators/utils.js.map +1 -0
- package/dist/decorators/worker.decorators.d.ts +58 -0
- package/dist/decorators/worker.decorators.d.ts.map +1 -0
- package/dist/decorators/worker.decorators.js +92 -0
- package/dist/decorators/worker.decorators.js.map +1 -0
- package/dist/domain/interfaces/config.interfaces.d.ts +188 -0
- package/dist/domain/interfaces/config.interfaces.d.ts.map +1 -0
- package/dist/domain/interfaces/config.interfaces.js +3 -0
- package/dist/domain/interfaces/config.interfaces.js.map +1 -0
- package/dist/domain/interfaces/cqrs.interfaces.d.ts +7 -0
- package/dist/domain/interfaces/cqrs.interfaces.d.ts.map +1 -0
- package/dist/domain/interfaces/cqrs.interfaces.js +3 -0
- package/dist/domain/interfaces/cqrs.interfaces.js.map +1 -0
- package/dist/domain/interfaces/event.interfaces.d.ts +71 -0
- package/dist/domain/interfaces/event.interfaces.d.ts.map +1 -0
- package/dist/domain/interfaces/event.interfaces.js +3 -0
- package/dist/domain/interfaces/event.interfaces.js.map +1 -0
- package/dist/domain/interfaces/index-tracking.interfaces.d.ts +69 -0
- package/dist/domain/interfaces/index-tracking.interfaces.d.ts.map +1 -0
- package/dist/domain/interfaces/index-tracking.interfaces.js +3 -0
- package/dist/domain/interfaces/index-tracking.interfaces.js.map +1 -0
- package/dist/domain/interfaces/index.d.ts +12 -0
- package/dist/domain/interfaces/index.d.ts.map +1 -0
- package/dist/domain/interfaces/index.js +28 -0
- package/dist/domain/interfaces/index.js.map +1 -0
- package/dist/domain/interfaces/job.interfaces.d.ts +76 -0
- package/dist/domain/interfaces/job.interfaces.d.ts.map +1 -0
- package/dist/domain/interfaces/job.interfaces.js +3 -0
- package/dist/domain/interfaces/job.interfaces.js.map +1 -0
- package/dist/domain/interfaces/lock.interfaces.d.ts +54 -0
- package/dist/domain/interfaces/lock.interfaces.d.ts.map +1 -0
- package/dist/domain/interfaces/lock.interfaces.js +3 -0
- package/dist/domain/interfaces/lock.interfaces.js.map +1 -0
- package/dist/domain/interfaces/process.interfaces.d.ts +44 -0
- package/dist/domain/interfaces/process.interfaces.d.ts.map +1 -0
- package/dist/domain/interfaces/process.interfaces.js +3 -0
- package/dist/domain/interfaces/process.interfaces.js.map +1 -0
- package/dist/domain/interfaces/queue.interfaces.d.ts +46 -0
- package/dist/domain/interfaces/queue.interfaces.d.ts.map +1 -0
- package/dist/domain/interfaces/queue.interfaces.js +3 -0
- package/dist/domain/interfaces/queue.interfaces.js.map +1 -0
- package/dist/domain/interfaces/scaling.interfaces.d.ts +62 -0
- package/dist/domain/interfaces/scaling.interfaces.d.ts.map +1 -0
- package/dist/domain/interfaces/scaling.interfaces.js +3 -0
- package/dist/domain/interfaces/scaling.interfaces.js.map +1 -0
- package/dist/domain/interfaces/utility.types.d.ts +15 -0
- package/dist/domain/interfaces/utility.types.d.ts.map +1 -0
- package/dist/domain/interfaces/utility.types.js +3 -0
- package/dist/domain/interfaces/utility.types.js.map +1 -0
- package/dist/domain/interfaces/worker.interfaces.d.ts +120 -0
- package/dist/domain/interfaces/worker.interfaces.d.ts.map +1 -0
- package/dist/domain/interfaces/worker.interfaces.js +3 -0
- package/dist/domain/interfaces/worker.interfaces.js.map +1 -0
- package/dist/module/atomic-queues.module.d.ts.map +1 -1
- package/dist/module/atomic-queues.module.js +5 -0
- package/dist/module/atomic-queues.module.js.map +1 -1
- package/dist/services/cron-manager/cron-manager.service.d.ts +5 -4
- package/dist/services/cron-manager/cron-manager.service.d.ts.map +1 -1
- package/dist/services/cron-manager/cron-manager.service.js +26 -57
- package/dist/services/cron-manager/cron-manager.service.js.map +1 -1
- package/dist/services/index-manager/index-manager.service.d.ts +0 -4
- package/dist/services/index-manager/index-manager.service.d.ts.map +1 -1
- package/dist/services/index-manager/index-manager.service.js +4 -16
- package/dist/services/index-manager/index-manager.service.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/decorator-discovery.service.d.ts +40 -0
- package/dist/services/processor-discovery/decorator-discovery.service.d.ts.map +1 -0
- package/dist/services/processor-discovery/decorator-discovery.service.js +191 -0
- package/dist/services/processor-discovery/decorator-discovery.service.js.map +1 -0
- package/dist/services/processor-discovery/index.d.ts +4 -0
- package/dist/services/processor-discovery/index.d.ts.map +1 -1
- package/dist/services/processor-discovery/index.js +4 -0
- package/dist/services/processor-discovery/index.js.map +1 -1
- package/dist/services/processor-discovery/processor-discovery.service.d.ts +30 -138
- package/dist/services/processor-discovery/processor-discovery.service.d.ts.map +1 -1
- package/dist/services/processor-discovery/processor-discovery.service.js +125 -502
- package/dist/services/processor-discovery/processor-discovery.service.js.map +1 -1
- package/dist/services/processor-discovery/processor-registry.d.ts +58 -0
- package/dist/services/processor-discovery/processor-registry.d.ts.map +1 -0
- package/dist/services/processor-discovery/processor-registry.js +74 -0
- package/dist/services/processor-discovery/processor-registry.js.map +1 -0
- package/dist/services/processor-discovery/scaling-registration.service.d.ts +60 -0
- package/dist/services/processor-discovery/scaling-registration.service.d.ts.map +1 -0
- package/dist/services/processor-discovery/scaling-registration.service.js +261 -0
- package/dist/services/processor-discovery/scaling-registration.service.js.map +1 -0
- package/dist/services/processor-discovery/worker-factory.service.d.ts +54 -0
- package/dist/services/processor-discovery/worker-factory.service.d.ts.map +1 -0
- package/dist/services/processor-discovery/worker-factory.service.js +185 -0
- package/dist/services/processor-discovery/worker-factory.service.js.map +1 -0
- package/dist/services/queue-bus/entity-target.d.ts +58 -0
- package/dist/services/queue-bus/entity-target.d.ts.map +1 -0
- package/dist/services/queue-bus/entity-target.js +109 -0
- package/dist/services/queue-bus/entity-target.js.map +1 -0
- package/dist/services/queue-bus/index.d.ts +4 -0
- package/dist/services/queue-bus/index.d.ts.map +1 -1
- package/dist/services/queue-bus/index.js +4 -0
- package/dist/services/queue-bus/index.js.map +1 -1
- package/dist/services/queue-bus/queue-bus.service.d.ts +9 -145
- package/dist/services/queue-bus/queue-bus.service.d.ts.map +1 -1
- package/dist/services/queue-bus/queue-bus.service.js +23 -311
- package/dist/services/queue-bus/queue-bus.service.js.map +1 -1
- package/dist/services/queue-bus/queue-bus.types.d.ts +40 -0
- package/dist/services/queue-bus/queue-bus.types.d.ts.map +1 -0
- package/dist/services/queue-bus/queue-bus.types.js +3 -0
- package/dist/services/queue-bus/queue-bus.types.js.map +1 -0
- package/dist/services/queue-bus/queue-bus.utils.d.ts +34 -0
- package/dist/services/queue-bus/queue-bus.utils.d.ts.map +1 -0
- package/dist/services/queue-bus/queue-bus.utils.js +82 -0
- package/dist/services/queue-bus/queue-bus.utils.js.map +1 -0
- package/dist/services/queue-bus/queue-target.d.ts +61 -0
- package/dist/services/queue-bus/queue-target.d.ts.map +1 -0
- package/dist/services/queue-bus/queue-target.js +123 -0
- package/dist/services/queue-bus/queue-target.js.map +1 -0
- package/dist/services/queue-events-manager/queue-events-manager.service.d.ts +23 -6
- package/dist/services/queue-events-manager/queue-events-manager.service.d.ts.map +1 -1
- package/dist/services/queue-events-manager/queue-events-manager.service.js +69 -37
- package/dist/services/queue-events-manager/queue-events-manager.service.js.map +1 -1
- package/dist/services/resource-lock/resource-lock.service.d.ts +0 -4
- package/dist/services/resource-lock/resource-lock.service.d.ts.map +1 -1
- package/dist/services/resource-lock/resource-lock.service.js +4 -16
- package/dist/services/resource-lock/resource-lock.service.js.map +1 -1
- package/dist/services/service-queue/index.d.ts +1 -0
- package/dist/services/service-queue/index.d.ts.map +1 -1
- package/dist/services/service-queue/index.js +1 -0
- package/dist/services/service-queue/index.js.map +1 -1
- package/dist/services/service-queue/service-queue.service.d.ts +2 -35
- package/dist/services/service-queue/service-queue.service.d.ts.map +1 -1
- package/dist/services/service-queue/service-queue.service.js +17 -49
- package/dist/services/service-queue/service-queue.service.js.map +1 -1
- package/dist/services/service-queue/service-queue.types.d.ts +32 -0
- package/dist/services/service-queue/service-queue.types.d.ts.map +1 -0
- package/dist/services/service-queue/service-queue.types.js +27 -0
- package/dist/services/service-queue/service-queue.types.js.map +1 -0
- package/dist/services/spawn-queue/index.d.ts +2 -0
- package/dist/services/spawn-queue/index.d.ts.map +1 -0
- package/dist/services/spawn-queue/index.js +18 -0
- package/dist/services/spawn-queue/index.js.map +1 -0
- package/dist/services/spawn-queue/spawn-queue.service.d.ts +119 -0
- package/dist/services/spawn-queue/spawn-queue.service.d.ts.map +1 -0
- package/dist/services/spawn-queue/spawn-queue.service.js +273 -0
- package/dist/services/spawn-queue/spawn-queue.service.js.map +1 -0
- package/dist/services/worker-manager/worker-manager.service.d.ts +18 -3
- package/dist/services/worker-manager/worker-manager.service.d.ts.map +1 -1
- package/dist/services/worker-manager/worker-manager.service.js +46 -21
- package/dist/services/worker-manager/worker-manager.service.js.map +1 -1
- package/dist/utils/async.utils.d.ts +51 -0
- package/dist/utils/async.utils.d.ts.map +1 -0
- package/dist/utils/async.utils.js +87 -0
- package/dist/utils/async.utils.js.map +1 -0
- package/dist/utils/helpers.d.ts +4 -123
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/helpers.js +18 -226
- package/dist/utils/helpers.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/job.utils.d.ts +50 -0
- package/dist/utils/job.utils.d.ts.map +1 -0
- package/dist/utils/job.utils.js +89 -0
- package/dist/utils/job.utils.js.map +1 -0
- package/dist/utils/naming.utils.d.ts +21 -0
- package/dist/utils/naming.utils.d.ts.map +1 -0
- package/dist/utils/naming.utils.js +38 -0
- package/dist/utils/naming.utils.js.map +1 -0
- package/dist/utils/rate-limit.utils.d.ts +9 -0
- package/dist/utils/rate-limit.utils.d.ts.map +1 -0
- package/dist/utils/rate-limit.utils.js +30 -0
- package/dist/utils/rate-limit.utils.js.map +1 -0
- package/dist/utils/redis.utils.d.ts +3 -0
- package/dist/utils/redis.utils.d.ts.map +1 -0
- package/dist/utils/redis.utils.js +14 -0
- package/dist/utils/redis.utils.js.map +1 -0
- package/package.json +17 -17
- package/dist/decorators/decorators.d.ts +0 -489
- package/dist/decorators/decorators.d.ts.map +0 -1
- package/dist/decorators/decorators.js +0 -680
- package/dist/decorators/decorators.js.map +0 -1
- package/dist/domain/interfaces.d.ts +0 -748
- package/dist/domain/interfaces.d.ts.map +0 -1
- package/dist/domain/interfaces.js +0 -19
- package/dist/domain/interfaces.js.map +0 -1
|
@@ -1,748 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* =============================================================================
|
|
3
|
-
* ATOMIC QUEUES - Core Domain Interfaces
|
|
4
|
-
* =============================================================================
|
|
5
|
-
*
|
|
6
|
-
* This file defines all the core interfaces for the AtomicQueues library.
|
|
7
|
-
* These abstractions enable atomic process handling per entity (user, table, etc.)
|
|
8
|
-
* with features like:
|
|
9
|
-
*
|
|
10
|
-
* - Dynamic per-entity queue creation
|
|
11
|
-
* - Worker lifecycle management with heartbeat TTL
|
|
12
|
-
* - Distributed resource locking (Redis/Lua scripts)
|
|
13
|
-
* - Graceful shutdown coordination via pub/sub
|
|
14
|
-
* - Cron-based worker spawning/cleanup
|
|
15
|
-
* - CQRS command/query dynamic execution
|
|
16
|
-
*/
|
|
17
|
-
import { Job, Queue, Worker } from 'bullmq';
|
|
18
|
-
/**
|
|
19
|
-
* Redis connection configuration
|
|
20
|
-
*/
|
|
21
|
-
export interface IRedisConfig {
|
|
22
|
-
host?: string;
|
|
23
|
-
port?: number;
|
|
24
|
-
password?: string;
|
|
25
|
-
db?: number;
|
|
26
|
-
url?: string;
|
|
27
|
-
maxRetriesPerRequest?: number | null;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Worker configuration options
|
|
31
|
-
*/
|
|
32
|
-
export interface IWorkerConfig {
|
|
33
|
-
/** Number of concurrent jobs a worker can process */
|
|
34
|
-
concurrency?: number;
|
|
35
|
-
/** Interval in ms to check for stalled jobs */
|
|
36
|
-
stalledInterval?: number;
|
|
37
|
-
/** Duration in ms that a job lock is held */
|
|
38
|
-
lockDuration?: number;
|
|
39
|
-
/** Maximum number of times a job can be marked as stalled before failing */
|
|
40
|
-
maxStalledCount?: number;
|
|
41
|
-
/** Heartbeat TTL in seconds for worker liveness tracking */
|
|
42
|
-
heartbeatTTL?: number;
|
|
43
|
-
/** Interval in ms between heartbeat updates */
|
|
44
|
-
heartbeatInterval?: number;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Queue configuration options
|
|
48
|
-
*/
|
|
49
|
-
export interface IQueueConfig {
|
|
50
|
-
/** Default job options for the queue */
|
|
51
|
-
defaultJobOptions?: IJobOptions;
|
|
52
|
-
/** Limiter configuration for rate limiting */
|
|
53
|
-
limiter?: {
|
|
54
|
-
groupKey?: string;
|
|
55
|
-
max?: number;
|
|
56
|
-
duration?: number;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Job configuration options
|
|
61
|
-
*/
|
|
62
|
-
export interface IJobOptions {
|
|
63
|
-
/** Remove job from queue when completed */
|
|
64
|
-
removeOnComplete?: boolean | number;
|
|
65
|
-
/** Remove job from queue when failed */
|
|
66
|
-
removeOnFail?: boolean | number;
|
|
67
|
-
/** Number of attempts before marking as failed */
|
|
68
|
-
attempts?: number;
|
|
69
|
-
/** Backoff strategy for retries */
|
|
70
|
-
backoff?: {
|
|
71
|
-
type: 'fixed' | 'exponential';
|
|
72
|
-
delay: number;
|
|
73
|
-
};
|
|
74
|
-
/** Job priority (lower = higher priority) */
|
|
75
|
-
priority?: number;
|
|
76
|
-
/** Delay in ms before the job becomes available */
|
|
77
|
-
delay?: number;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Service queue configuration for global singleton operations
|
|
81
|
-
*/
|
|
82
|
-
export interface IServiceQueueConfig {
|
|
83
|
-
/** Whether to enable the service queue (default: true) */
|
|
84
|
-
enabled?: boolean;
|
|
85
|
-
/** Custom queue name (default: {keyPrefix}-service-queue) */
|
|
86
|
-
queueName?: string;
|
|
87
|
-
/** Custom worker name (default: {keyPrefix}-service-worker) */
|
|
88
|
-
workerName?: string;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Entity-specific configuration for per-entity queue defaults
|
|
92
|
-
* Used in module-level `entities` config to define defaults per entity type.
|
|
93
|
-
*
|
|
94
|
-
* When configured in the module, entities automatically get:
|
|
95
|
-
* - Worker spawning when jobs arrive (via QueueEvents)
|
|
96
|
-
* - Idle worker termination (via CronManager)
|
|
97
|
-
* - Job routing via CQRS CommandBus/QueryBus
|
|
98
|
-
*
|
|
99
|
-
* No @WorkerProcessor class needed!
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```typescript
|
|
103
|
-
* AtomicQueuesModule.forRoot({
|
|
104
|
-
* redis: { host: 'localhost', port: 6379 },
|
|
105
|
-
* enableCronManager: true,
|
|
106
|
-
* entities: {
|
|
107
|
-
* account: {
|
|
108
|
-
* queueName: (id) => `${id}-queue`,
|
|
109
|
-
* workerName: (id) => `${id}-worker`,
|
|
110
|
-
* maxWorkersPerEntity: 1,
|
|
111
|
-
* idleTimeoutSeconds: 15,
|
|
112
|
-
* },
|
|
113
|
-
* },
|
|
114
|
-
* })
|
|
115
|
-
* ```
|
|
116
|
-
*/
|
|
117
|
-
export interface IEntityConfig {
|
|
118
|
-
/**
|
|
119
|
-
* Default property name to use for entity ID extraction.
|
|
120
|
-
* This is used when commands don't have an @QueueEntityId() decorator.
|
|
121
|
-
* Example: 'tableId', 'accountId', 'userId'
|
|
122
|
-
*/
|
|
123
|
-
defaultEntityId?: string;
|
|
124
|
-
/**
|
|
125
|
-
* Custom queue name generator for this entity type.
|
|
126
|
-
* If not provided, uses: {keyPrefix}:{entityType}:{entityId}:queue
|
|
127
|
-
*/
|
|
128
|
-
queueName?: (entityId: string) => string;
|
|
129
|
-
/**
|
|
130
|
-
* Custom worker name generator for this entity type.
|
|
131
|
-
* If not provided, uses: {keyPrefix}:{entityType}:{entityId}:worker
|
|
132
|
-
*/
|
|
133
|
-
workerName?: (entityId: string) => string;
|
|
134
|
-
/** Worker configuration overrides for this entity type */
|
|
135
|
-
workerConfig?: Partial<IWorkerConfig>;
|
|
136
|
-
/**
|
|
137
|
-
* Maximum workers per entity (default: 1).
|
|
138
|
-
* Determines how many concurrent workers can process jobs for a single entity.
|
|
139
|
-
*/
|
|
140
|
-
maxWorkersPerEntity?: number;
|
|
141
|
-
/**
|
|
142
|
-
* Idle timeout in seconds before a worker is terminated (default: 15).
|
|
143
|
-
* Workers are terminated when they have no jobs to process for this duration.
|
|
144
|
-
*/
|
|
145
|
-
idleTimeoutSeconds?: number;
|
|
146
|
-
/**
|
|
147
|
-
* If true, workers are automatically spawned when jobs arrive (default: true).
|
|
148
|
-
* When enabled, no @WorkerProcessor or @EntityScaler is required.
|
|
149
|
-
*/
|
|
150
|
-
autoSpawn?: boolean;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Main module configuration
|
|
154
|
-
*/
|
|
155
|
-
export interface IAtomicQueuesModuleConfig {
|
|
156
|
-
/** Redis connection configuration */
|
|
157
|
-
redis: IRedisConfig;
|
|
158
|
-
/** Default worker configuration */
|
|
159
|
-
workerDefaults?: IWorkerConfig;
|
|
160
|
-
/** Default queue configuration */
|
|
161
|
-
queueDefaults?: IQueueConfig;
|
|
162
|
-
/** Enable cron-based worker management */
|
|
163
|
-
enableCronManager?: boolean;
|
|
164
|
-
/** Cron interval in ms for worker management cycle */
|
|
165
|
-
cronInterval?: number;
|
|
166
|
-
/** Prefix for all Redis keys */
|
|
167
|
-
keyPrefix?: string;
|
|
168
|
-
/** Service queue configuration for global atomic operations */
|
|
169
|
-
serviceQueue?: IServiceQueueConfig;
|
|
170
|
-
/** Enable verbose logging (debug logs for service jobs, scaling cycles, etc.) */
|
|
171
|
-
verbose?: boolean;
|
|
172
|
-
/**
|
|
173
|
-
* Auto-register commands from @nestjs/cqrs handlers (default: true)
|
|
174
|
-
* When enabled, all @CommandHandler and @QueryHandler decorated classes
|
|
175
|
-
* are automatically discovered and registered with QueueBus.
|
|
176
|
-
*/
|
|
177
|
-
autoRegisterCommands?: boolean;
|
|
178
|
-
/**
|
|
179
|
-
* Per-entity type configuration.
|
|
180
|
-
* Allows setting defaults for specific entity types (e.g., 'table', 'account').
|
|
181
|
-
* These defaults are merged with processor-level and command-level settings.
|
|
182
|
-
*
|
|
183
|
-
* Priority chain (highest to lowest):
|
|
184
|
-
* 1. @QueueEntityId() decorator on command property
|
|
185
|
-
* 2. @WorkerProcessor({ defaultEntityId })
|
|
186
|
-
* 3. entities[entityType].defaultEntityId
|
|
187
|
-
* 4. Error (no fallback to magic extraction)
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* ```typescript
|
|
191
|
-
* entities: {
|
|
192
|
-
* table: {
|
|
193
|
-
* defaultEntityId: 'tableId',
|
|
194
|
-
* workerConfig: { concurrency: 1 }
|
|
195
|
-
* },
|
|
196
|
-
* account: {
|
|
197
|
-
* defaultEntityId: 'accountId',
|
|
198
|
-
* queueName: (id) => `accounts-${id}-queue`
|
|
199
|
-
* }
|
|
200
|
-
* }
|
|
201
|
-
* ```
|
|
202
|
-
*/
|
|
203
|
-
entities?: Record<string, IEntityConfig>;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Represents a managed queue instance
|
|
207
|
-
*/
|
|
208
|
-
export interface IManagedQueue {
|
|
209
|
-
name: string;
|
|
210
|
-
queue: Queue;
|
|
211
|
-
createdAt: Date;
|
|
212
|
-
entityId: string;
|
|
213
|
-
entityType: string;
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Queue manager service interface for dynamic queue creation/destruction
|
|
217
|
-
*/
|
|
218
|
-
export interface IQueueManager {
|
|
219
|
-
/**
|
|
220
|
-
* Get or create a queue for the given name
|
|
221
|
-
*/
|
|
222
|
-
getOrCreateQueue(queueName: string): Queue;
|
|
223
|
-
/**
|
|
224
|
-
* Get or create an entity-specific queue
|
|
225
|
-
*/
|
|
226
|
-
getOrCreateEntityQueue(entityType: string, entityId: string): Queue;
|
|
227
|
-
/**
|
|
228
|
-
* Close and remove a specific queue
|
|
229
|
-
*/
|
|
230
|
-
closeQueue(queueName: string): Promise<void>;
|
|
231
|
-
/**
|
|
232
|
-
* Close all managed queues
|
|
233
|
-
*/
|
|
234
|
-
closeAllQueues(): Promise<void>;
|
|
235
|
-
/**
|
|
236
|
-
* Get all queue names
|
|
237
|
-
*/
|
|
238
|
-
getQueueNames(): string[];
|
|
239
|
-
/**
|
|
240
|
-
* Delete a specific job from a queue
|
|
241
|
-
*/
|
|
242
|
-
deleteJob(queueName: string, jobId: string): Promise<void>;
|
|
243
|
-
/**
|
|
244
|
-
* Add a job to a queue
|
|
245
|
-
*/
|
|
246
|
-
addJob<T>(queueName: string, jobName: string, data: T, options?: IJobOptions): Promise<Job<T>>;
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Worker state tracking
|
|
250
|
-
*/
|
|
251
|
-
export interface IWorkerState {
|
|
252
|
-
workerId: string;
|
|
253
|
-
workerName: string;
|
|
254
|
-
nodeId: string;
|
|
255
|
-
entityId?: string;
|
|
256
|
-
entityType?: string;
|
|
257
|
-
status: 'starting' | 'ready' | 'processing' | 'closing' | 'closed';
|
|
258
|
-
createdAt: Date;
|
|
259
|
-
lastHeartbeat: Date;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Worker lifecycle events
|
|
263
|
-
*/
|
|
264
|
-
export interface IWorkerEvents {
|
|
265
|
-
onReady?: (worker: Worker, workerName: string) => void | Promise<void>;
|
|
266
|
-
onCompleted?: (job: Job, workerName: string) => void | Promise<void>;
|
|
267
|
-
onFailed?: (job: Job | undefined, error: Error, workerName: string) => void | Promise<void>;
|
|
268
|
-
onProgress?: (job: Job, progress: number | object) => void | Promise<void>;
|
|
269
|
-
onStalled?: (jobId: string, workerName: string) => void | Promise<void>;
|
|
270
|
-
onClosing?: (workerName: string) => void | Promise<void>;
|
|
271
|
-
onClosed?: (workerName: string) => void | Promise<void>;
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Worker creation options
|
|
275
|
-
*/
|
|
276
|
-
export interface IWorkerCreationOptions {
|
|
277
|
-
workerName: string;
|
|
278
|
-
queueName: string;
|
|
279
|
-
config?: IWorkerConfig;
|
|
280
|
-
events?: IWorkerEvents;
|
|
281
|
-
processor: (job: Job) => Promise<unknown>;
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Worker manager service interface
|
|
285
|
-
*/
|
|
286
|
-
export interface IWorkerManager {
|
|
287
|
-
/**
|
|
288
|
-
* Create a new worker with automatic lifecycle management
|
|
289
|
-
*/
|
|
290
|
-
createWorker(options: IWorkerCreationOptions): Promise<Worker>;
|
|
291
|
-
/**
|
|
292
|
-
* Check if a worker exists and is alive (across ALL nodes)
|
|
293
|
-
*/
|
|
294
|
-
workerExists(workerName: string): Promise<boolean>;
|
|
295
|
-
/**
|
|
296
|
-
* Check if a worker exists on THIS node specifically
|
|
297
|
-
*/
|
|
298
|
-
workerExistsOnThisNode(workerName: string): Promise<boolean>;
|
|
299
|
-
/**
|
|
300
|
-
* Get all running workers for current node
|
|
301
|
-
*/
|
|
302
|
-
getNodeWorkers(): Promise<string[]>;
|
|
303
|
-
/**
|
|
304
|
-
* Get all running workers across all nodes
|
|
305
|
-
*/
|
|
306
|
-
getAllWorkers(): Promise<string[]>;
|
|
307
|
-
/**
|
|
308
|
-
* Get all workers for a specific entity
|
|
309
|
-
*/
|
|
310
|
-
getEntityWorkers(entityType: string, entityId: string): Promise<string[]>;
|
|
311
|
-
/**
|
|
312
|
-
* Signal a worker to close gracefully
|
|
313
|
-
*/
|
|
314
|
-
signalWorkerClose(workerName: string): Promise<void>;
|
|
315
|
-
/**
|
|
316
|
-
* Signal all workers on current node to close
|
|
317
|
-
*/
|
|
318
|
-
signalNodeWorkersClose(): Promise<void>;
|
|
319
|
-
/**
|
|
320
|
-
* Wait for all node workers to close
|
|
321
|
-
*/
|
|
322
|
-
waitForWorkersToClose(timeoutMs?: number): Promise<void>;
|
|
323
|
-
/**
|
|
324
|
-
* Reset worker heartbeat TTL
|
|
325
|
-
*/
|
|
326
|
-
resetWorkerHeartbeat(workerName: string): Promise<void>;
|
|
327
|
-
/**
|
|
328
|
-
* Remove worker heartbeat (mark as dead)
|
|
329
|
-
*/
|
|
330
|
-
removeWorkerHeartbeat(workerName: string): Promise<void>;
|
|
331
|
-
/**
|
|
332
|
-
* Get the node ID for this instance
|
|
333
|
-
*/
|
|
334
|
-
getNodeId(): string;
|
|
335
|
-
/**
|
|
336
|
-
* Mark that a worker has completed a job (resets idle counter).
|
|
337
|
-
* Called internally when job completes.
|
|
338
|
-
*/
|
|
339
|
-
markWorkerActive(workerName: string): void;
|
|
340
|
-
/**
|
|
341
|
-
* Get the idle seconds counter for a worker.
|
|
342
|
-
* This is incremented by the heartbeat and reset when a job completes.
|
|
343
|
-
*/
|
|
344
|
-
getWorkerIdleSeconds(workerName: string): Promise<number>;
|
|
345
|
-
/**
|
|
346
|
-
* Reset the idle counter for a worker (called when job completes).
|
|
347
|
-
*/
|
|
348
|
-
resetWorkerIdleCounter(workerName: string): Promise<void>;
|
|
349
|
-
/**
|
|
350
|
-
* Increment the idle counter for a worker (called by heartbeat).
|
|
351
|
-
* Returns the new idle seconds value.
|
|
352
|
-
*/
|
|
353
|
-
incrementWorkerIdleCounter(workerName: string, incrementBy?: number): Promise<number>;
|
|
354
|
-
/**
|
|
355
|
-
* Remove the idle counter for a worker (cleanup).
|
|
356
|
-
*/
|
|
357
|
-
removeWorkerIdleCounter(workerName: string): Promise<void>;
|
|
358
|
-
/**
|
|
359
|
-
* Check if a worker is idle based on threshold.
|
|
360
|
-
* @param workerName - Worker name
|
|
361
|
-
* @param thresholdSeconds - Idle threshold in seconds (default: 15)
|
|
362
|
-
*/
|
|
363
|
-
isWorkerIdle(workerName: string, thresholdSeconds?: number): Promise<boolean>;
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
* Lock state for a resource
|
|
367
|
-
*/
|
|
368
|
-
export interface IResourceLock {
|
|
369
|
-
resourceId: string;
|
|
370
|
-
resourceType: string;
|
|
371
|
-
ownerId: string;
|
|
372
|
-
ownerType: string;
|
|
373
|
-
acquiredAt: Date;
|
|
374
|
-
expiresAt: Date;
|
|
375
|
-
metadata?: Record<string, unknown>;
|
|
376
|
-
}
|
|
377
|
-
/**
|
|
378
|
-
* Lock acquisition result
|
|
379
|
-
*/
|
|
380
|
-
export interface ILockResult {
|
|
381
|
-
acquired: boolean;
|
|
382
|
-
lock?: IResourceLock;
|
|
383
|
-
reason?: string;
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Resource lock service interface for distributed locking
|
|
387
|
-
*/
|
|
388
|
-
export interface IResourceLockService {
|
|
389
|
-
/**
|
|
390
|
-
* Acquire a lock on a resource
|
|
391
|
-
*/
|
|
392
|
-
acquireLock(resourceType: string, resourceId: string, ownerId: string, ownerType: string, ttlSeconds?: number, metadata?: Record<string, unknown>): Promise<ILockResult>;
|
|
393
|
-
/**
|
|
394
|
-
* Release a lock on a resource
|
|
395
|
-
*/
|
|
396
|
-
releaseLock(resourceType: string, resourceId: string): Promise<boolean>;
|
|
397
|
-
/**
|
|
398
|
-
* Check if a resource is locked
|
|
399
|
-
*/
|
|
400
|
-
isLocked(resourceType: string, resourceId: string): Promise<boolean>;
|
|
401
|
-
/**
|
|
402
|
-
* Get lock info for a resource
|
|
403
|
-
*/
|
|
404
|
-
getLockInfo(resourceType: string, resourceId: string): Promise<IResourceLock | null>;
|
|
405
|
-
/**
|
|
406
|
-
* Get all locked resources of a type for an owner
|
|
407
|
-
*/
|
|
408
|
-
getOwnerLocks(ownerType: string, ownerId: string): Promise<IResourceLock[]>;
|
|
409
|
-
/**
|
|
410
|
-
* Get available (unlocked) resource from a pool
|
|
411
|
-
*/
|
|
412
|
-
getAvailableResource(resourceType: string, candidateIds: string[], ownerId: string, ownerType: string, ttlSeconds?: number): Promise<ILockResult>;
|
|
413
|
-
/**
|
|
414
|
-
* Extend lock TTL
|
|
415
|
-
*/
|
|
416
|
-
extendLock(resourceType: string, resourceId: string, ttlSeconds: number): Promise<boolean>;
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* Job data structure for atomic processing
|
|
420
|
-
*/
|
|
421
|
-
export interface IAtomicJobData<T = unknown> {
|
|
422
|
-
/** Unique job identifier */
|
|
423
|
-
uuid: string;
|
|
424
|
-
/** Entity ID this job belongs to */
|
|
425
|
-
entityId: string;
|
|
426
|
-
/** Entity type (user, table, etc.) */
|
|
427
|
-
entityType: string;
|
|
428
|
-
/** Command/Query class name to execute */
|
|
429
|
-
commandName?: string;
|
|
430
|
-
/** Type of operation */
|
|
431
|
-
type: 'command' | 'query' | 'custom';
|
|
432
|
-
/** Payload data */
|
|
433
|
-
payload: T;
|
|
434
|
-
/** Additional metadata */
|
|
435
|
-
metadata?: Record<string, unknown>;
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Job processing result
|
|
439
|
-
*/
|
|
440
|
-
export interface IJobResult<T = unknown> {
|
|
441
|
-
success: boolean;
|
|
442
|
-
result?: T;
|
|
443
|
-
error?: string;
|
|
444
|
-
processingTime: number;
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Job processor function type
|
|
448
|
-
*/
|
|
449
|
-
export type JobProcessor<T = unknown, R = unknown> = (job: Job<IAtomicJobData<T>>) => Promise<R>;
|
|
450
|
-
/**
|
|
451
|
-
* Job processor registry interface
|
|
452
|
-
*/
|
|
453
|
-
export interface IJobProcessorRegistry {
|
|
454
|
-
/**
|
|
455
|
-
* Register a processor for a job type
|
|
456
|
-
*/
|
|
457
|
-
registerProcessor<T, R>(jobType: string, processor: JobProcessor<T, R>): void;
|
|
458
|
-
/**
|
|
459
|
-
* Get processor for a job type
|
|
460
|
-
*/
|
|
461
|
-
getProcessor<T, R>(jobType: string): JobProcessor<T, R> | undefined;
|
|
462
|
-
/**
|
|
463
|
-
* Check if processor exists
|
|
464
|
-
*/
|
|
465
|
-
hasProcessor(jobType: string): boolean;
|
|
466
|
-
/**
|
|
467
|
-
* Get all registered job types
|
|
468
|
-
*/
|
|
469
|
-
getRegisteredTypes(): string[];
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Dynamic command/query executor interface
|
|
473
|
-
*/
|
|
474
|
-
export interface IDynamicExecutor {
|
|
475
|
-
/**
|
|
476
|
-
* Execute a command by class name
|
|
477
|
-
*/
|
|
478
|
-
executeCommand<T>(commandName: string, payload: T): Promise<unknown>;
|
|
479
|
-
/**
|
|
480
|
-
* Execute a query by class name
|
|
481
|
-
*/
|
|
482
|
-
executeQuery<T>(queryName: string, payload: T): Promise<unknown>;
|
|
483
|
-
/**
|
|
484
|
-
* Register command module for dynamic loading
|
|
485
|
-
*/
|
|
486
|
-
registerCommandModule(modulePath: string): void;
|
|
487
|
-
/**
|
|
488
|
-
* Register query module for dynamic loading
|
|
489
|
-
*/
|
|
490
|
-
registerQueryModule(modulePath: string): void;
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Worker scaling decision
|
|
494
|
-
*/
|
|
495
|
-
export interface IScalingDecision {
|
|
496
|
-
entityId: string;
|
|
497
|
-
entityType: string;
|
|
498
|
-
currentWorkers: number;
|
|
499
|
-
desiredWorkers: number;
|
|
500
|
-
action: 'spawn' | 'terminate' | 'none';
|
|
501
|
-
count: number;
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* Entity scaling configuration
|
|
505
|
-
*/
|
|
506
|
-
export interface IEntityScalingConfig {
|
|
507
|
-
entityType: string;
|
|
508
|
-
/** Function to get desired worker count for an entity */
|
|
509
|
-
getDesiredWorkerCount: (entityId: string) => Promise<number>;
|
|
510
|
-
/** Function to get all active entity IDs */
|
|
511
|
-
getActiveEntityIds: () => Promise<string[]>;
|
|
512
|
-
/** Maximum workers per entity */
|
|
513
|
-
maxWorkersPerEntity?: number;
|
|
514
|
-
/**
|
|
515
|
-
* Idle timeout in seconds before a worker is considered idle and can be terminated.
|
|
516
|
-
* Workers self-report idle time via heartbeat. Default: 15 seconds.
|
|
517
|
-
*/
|
|
518
|
-
idleTimeoutSeconds?: number;
|
|
519
|
-
/** Function called when spawning a worker */
|
|
520
|
-
onSpawnWorker?: (entityId: string) => Promise<void>;
|
|
521
|
-
/** Function called when terminating a worker */
|
|
522
|
-
onTerminateWorker?: (entityId: string, workerId: string) => Promise<void>;
|
|
523
|
-
}
|
|
524
|
-
/**
|
|
525
|
-
* Cron manager interface for worker lifecycle management
|
|
526
|
-
*/
|
|
527
|
-
export interface ICronManager {
|
|
528
|
-
/**
|
|
529
|
-
* Register an entity type for automatic scaling
|
|
530
|
-
*/
|
|
531
|
-
registerEntityType(config: IEntityScalingConfig): void;
|
|
532
|
-
/**
|
|
533
|
-
* Run scaling cycle for all registered entity types
|
|
534
|
-
*/
|
|
535
|
-
runScalingCycle(): Promise<IScalingDecision[]>;
|
|
536
|
-
/**
|
|
537
|
-
* Get current scaling state
|
|
538
|
-
*/
|
|
539
|
-
getScalingState(): Promise<Map<string, IScalingDecision[]>>;
|
|
540
|
-
/**
|
|
541
|
-
* Start the cron manager
|
|
542
|
-
*/
|
|
543
|
-
start(intervalMs?: number): void;
|
|
544
|
-
/**
|
|
545
|
-
* Stop the cron manager
|
|
546
|
-
*/
|
|
547
|
-
stop(): void;
|
|
548
|
-
/**
|
|
549
|
-
* Check if cron manager is running
|
|
550
|
-
*/
|
|
551
|
-
isRunning(): boolean;
|
|
552
|
-
}
|
|
553
|
-
/**
|
|
554
|
-
* Index entry for tracking jobs, workers, queues
|
|
555
|
-
*/
|
|
556
|
-
export interface IIndexEntry {
|
|
557
|
-
id: string;
|
|
558
|
-
type: 'job' | 'worker' | 'queue' | 'death' | 'custom';
|
|
559
|
-
entityId: string;
|
|
560
|
-
entityType: string;
|
|
561
|
-
createdAt: Date;
|
|
562
|
-
metadata?: Record<string, unknown>;
|
|
563
|
-
}
|
|
564
|
-
/**
|
|
565
|
-
* Index manager interface for tracking various entities
|
|
566
|
-
*/
|
|
567
|
-
export interface IIndexManager {
|
|
568
|
-
/**
|
|
569
|
-
* Index a job for an entity
|
|
570
|
-
*/
|
|
571
|
-
indexJob(entityType: string, entityId: string, jobId: string): Promise<void>;
|
|
572
|
-
/**
|
|
573
|
-
* Remove job index
|
|
574
|
-
*/
|
|
575
|
-
removeJobIndex(entityType: string, entityId: string, jobId: string): Promise<void>;
|
|
576
|
-
/**
|
|
577
|
-
* Get all job IDs for an entity
|
|
578
|
-
*/
|
|
579
|
-
getEntityJobs(entityType: string, entityId: string): Promise<string[]>;
|
|
580
|
-
/**
|
|
581
|
-
* Get all entities with jobs
|
|
582
|
-
*/
|
|
583
|
-
getEntitiesWithJobs(entityType: string): Promise<Record<string, number>>;
|
|
584
|
-
/**
|
|
585
|
-
* Index a worker death signal
|
|
586
|
-
*/
|
|
587
|
-
indexWorkerDeath(entityType: string, entityId: string, deathId: string): Promise<void>;
|
|
588
|
-
/**
|
|
589
|
-
* Remove worker death index
|
|
590
|
-
*/
|
|
591
|
-
removeWorkerDeathIndex(entityType: string, entityId: string, deathId: string): Promise<void>;
|
|
592
|
-
/**
|
|
593
|
-
* Get queued worker deaths for an entity
|
|
594
|
-
*/
|
|
595
|
-
getQueuedWorkerDeaths(entityType: string, entityId: string): Promise<string[]>;
|
|
596
|
-
/**
|
|
597
|
-
* Index entity queue
|
|
598
|
-
*/
|
|
599
|
-
indexEntityQueue(entityType: string, entityId: string): Promise<void>;
|
|
600
|
-
/**
|
|
601
|
-
* Remove entity queue index
|
|
602
|
-
*/
|
|
603
|
-
removeEntityQueueIndex(entityType: string, entityId: string): Promise<void>;
|
|
604
|
-
/**
|
|
605
|
-
* Get all entities with active queues
|
|
606
|
-
*/
|
|
607
|
-
getEntitiesWithQueues(entityType: string): Promise<string[]>;
|
|
608
|
-
/**
|
|
609
|
-
* Index a queue death signal
|
|
610
|
-
*/
|
|
611
|
-
indexQueueDeath(entityType: string, entityId: string): Promise<void>;
|
|
612
|
-
/**
|
|
613
|
-
* Remove queue death index
|
|
614
|
-
*/
|
|
615
|
-
removeQueueDeathIndex(entityType: string, entityId: string): Promise<void>;
|
|
616
|
-
/**
|
|
617
|
-
* Get all entities with queued queue deaths
|
|
618
|
-
*/
|
|
619
|
-
getEntitiesWithQueuedQueueDeaths(entityType: string): Promise<string[]>;
|
|
620
|
-
}
|
|
621
|
-
/**
|
|
622
|
-
* Socket connection tracking interface
|
|
623
|
-
*/
|
|
624
|
-
export interface IConnectionTracker {
|
|
625
|
-
/**
|
|
626
|
-
* Track a socket connection for an entity
|
|
627
|
-
*/
|
|
628
|
-
trackConnection(entityType: string, entityId: string, socketId: string, nodeId: string): Promise<void>;
|
|
629
|
-
/**
|
|
630
|
-
* Untrack a socket connection
|
|
631
|
-
*/
|
|
632
|
-
untrackConnection(entityType: string, entityId: string, socketId: string): Promise<void>;
|
|
633
|
-
/**
|
|
634
|
-
* Get all socket connections for an entity
|
|
635
|
-
*/
|
|
636
|
-
getEntityConnections(entityType: string, entityId: string): Promise<string[]>;
|
|
637
|
-
/**
|
|
638
|
-
* Get entity connections for a specific node
|
|
639
|
-
*/
|
|
640
|
-
getEntityNodeConnections(entityType: string, entityId: string, nodeId: string): Promise<string[]>;
|
|
641
|
-
/**
|
|
642
|
-
* Untrack all connections for current node
|
|
643
|
-
*/
|
|
644
|
-
untrackNodeConnections(): Promise<void>;
|
|
645
|
-
/**
|
|
646
|
-
* Check if entity has active connections
|
|
647
|
-
*/
|
|
648
|
-
hasActiveConnections(entityType: string, entityId: string): Promise<boolean>;
|
|
649
|
-
/**
|
|
650
|
-
* Get node ID for a socket connection
|
|
651
|
-
*/
|
|
652
|
-
getNodeForSocket(entityType: string, entityId: string, socketId: string): Promise<string | null>;
|
|
653
|
-
}
|
|
654
|
-
/**
|
|
655
|
-
* Event types for pub/sub communication
|
|
656
|
-
*/
|
|
657
|
-
export type AtomicQueueEventType = 'worker:shutdown' | 'worker:ready' | 'worker:closed' | 'job:completed' | 'job:failed' | 'job:progress' | 'queue:closed' | 'custom';
|
|
658
|
-
/**
|
|
659
|
-
* Event payload structure
|
|
660
|
-
*/
|
|
661
|
-
export interface IAtomicQueueEvent<T = unknown> {
|
|
662
|
-
type: AtomicQueueEventType;
|
|
663
|
-
nodeId: string;
|
|
664
|
-
workerId?: string;
|
|
665
|
-
entityId?: string;
|
|
666
|
-
entityType?: string;
|
|
667
|
-
timestamp: Date;
|
|
668
|
-
data?: T;
|
|
669
|
-
}
|
|
670
|
-
/**
|
|
671
|
-
* Event bus interface for internal pub/sub
|
|
672
|
-
*/
|
|
673
|
-
export interface IEventBus {
|
|
674
|
-
/**
|
|
675
|
-
* Publish an event
|
|
676
|
-
*/
|
|
677
|
-
publish<T>(channel: string, event: IAtomicQueueEvent<T>): Promise<void>;
|
|
678
|
-
/**
|
|
679
|
-
* Subscribe to a channel
|
|
680
|
-
*/
|
|
681
|
-
subscribe(channel: string, handler: (event: IAtomicQueueEvent) => void | Promise<void>): Promise<void>;
|
|
682
|
-
/**
|
|
683
|
-
* Unsubscribe from a channel
|
|
684
|
-
*/
|
|
685
|
-
unsubscribe(channel: string): Promise<void>;
|
|
686
|
-
/**
|
|
687
|
-
* Subscribe to worker shutdown events for a specific worker
|
|
688
|
-
*/
|
|
689
|
-
subscribeToWorkerShutdown(workerName: string, handler: () => void | Promise<void>): Promise<void>;
|
|
690
|
-
}
|
|
691
|
-
/**
|
|
692
|
-
* Atomic process status
|
|
693
|
-
*/
|
|
694
|
-
export type AtomicProcessStatus = 'pending' | 'processing' | 'completed' | 'failed';
|
|
695
|
-
/**
|
|
696
|
-
* Atomic process state
|
|
697
|
-
*/
|
|
698
|
-
export interface IAtomicProcessState {
|
|
699
|
-
uuid: string;
|
|
700
|
-
status: AtomicProcessStatus;
|
|
701
|
-
entityId: string;
|
|
702
|
-
entityType: string;
|
|
703
|
-
commandName?: string;
|
|
704
|
-
createdAt: Date;
|
|
705
|
-
updatedAt: Date;
|
|
706
|
-
result?: unknown;
|
|
707
|
-
error?: string;
|
|
708
|
-
}
|
|
709
|
-
/**
|
|
710
|
-
* Atomic process status tracker interface
|
|
711
|
-
*/
|
|
712
|
-
export interface IAtomicProcessTracker {
|
|
713
|
-
/**
|
|
714
|
-
* Set process status
|
|
715
|
-
*/
|
|
716
|
-
setStatus(uuid: string, status: AtomicProcessStatus): Promise<void>;
|
|
717
|
-
/**
|
|
718
|
-
* Get process status
|
|
719
|
-
*/
|
|
720
|
-
getStatus(uuid: string): Promise<IAtomicProcessState | null>;
|
|
721
|
-
/**
|
|
722
|
-
* Set process result
|
|
723
|
-
*/
|
|
724
|
-
setResult(uuid: string, result: unknown): Promise<void>;
|
|
725
|
-
/**
|
|
726
|
-
* Set process error
|
|
727
|
-
*/
|
|
728
|
-
setError(uuid: string, error: string): Promise<void>;
|
|
729
|
-
/**
|
|
730
|
-
* Clean up old process states
|
|
731
|
-
*/
|
|
732
|
-
cleanup(maxAgeMs?: number): Promise<number>;
|
|
733
|
-
}
|
|
734
|
-
/**
|
|
735
|
-
* Deep partial type utility
|
|
736
|
-
*/
|
|
737
|
-
export type DeepPartial<T> = {
|
|
738
|
-
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
739
|
-
};
|
|
740
|
-
/**
|
|
741
|
-
* Constructor type
|
|
742
|
-
*/
|
|
743
|
-
export type Constructor<T = unknown> = new (...args: unknown[]) => T;
|
|
744
|
-
/**
|
|
745
|
-
* Async factory function type
|
|
746
|
-
*/
|
|
747
|
-
export type AsyncFactory<T> = () => Promise<T> | T;
|
|
748
|
-
//# sourceMappingURL=interfaces.d.ts.map
|