@lenne.tech/nest-server 11.32.4 → 11.33.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/.claude/rules/architecture.md +16 -0
- package/.claude/rules/configurable-features.md +11 -3
- package/.claude/rules/testing.md +101 -1
- package/CLAUDE.md +5 -0
- package/FRAMEWORK-API.md +58 -3
- package/dist/core/common/helpers/content-disposition.helper.d.ts +1 -0
- package/dist/core/common/helpers/content-disposition.helper.js +14 -0
- package/dist/core/common/helpers/content-disposition.helper.js.map +1 -0
- package/dist/core/common/helpers/file.helper.d.ts +7 -0
- package/dist/core/common/helpers/file.helper.js +21 -4
- package/dist/core/common/helpers/file.helper.js.map +1 -1
- package/dist/core/common/helpers/graceful-shutdown.helper.d.ts +2 -0
- package/dist/core/common/helpers/graceful-shutdown.helper.js +55 -0
- package/dist/core/common/helpers/graceful-shutdown.helper.js.map +1 -0
- package/dist/core/common/helpers/project-name.helper.d.ts +2 -0
- package/dist/core/common/helpers/project-name.helper.js +38 -0
- package/dist/core/common/helpers/project-name.helper.js.map +1 -0
- package/dist/core/common/interfaces/cron-job-config.interface.d.ts +1 -0
- package/dist/core/common/interfaces/server-options.interface.d.ts +39 -0
- package/dist/core/common/services/core-cron-jobs.initializer.d.ts +10 -0
- package/dist/core/common/services/core-cron-jobs.initializer.js +46 -0
- package/dist/core/common/services/core-cron-jobs.initializer.js.map +1 -0
- package/dist/core/common/services/core-cron-jobs.registry.d.ts +8 -0
- package/dist/core/common/services/core-cron-jobs.registry.js +12 -0
- package/dist/core/common/services/core-cron-jobs.registry.js.map +1 -0
- package/dist/core/common/services/core-cron-jobs.service.d.ts +37 -7
- package/dist/core/common/services/core-cron-jobs.service.js +278 -27
- package/dist/core/common/services/core-cron-jobs.service.js.map +1 -1
- package/dist/core/common/services/core-redis-pubsub.d.ts +20 -0
- package/dist/core/common/services/core-redis-pubsub.js +112 -0
- package/dist/core/common/services/core-redis-pubsub.js.map +1 -0
- package/dist/core/common/services/core-redis.service.d.ts +25 -0
- package/dist/core/common/services/core-redis.service.js +154 -0
- package/dist/core/common/services/core-redis.service.js.map +1 -0
- package/dist/core/common/services/core-s3.service.d.ts +51 -0
- package/dist/core/common/services/core-s3.service.js +261 -0
- package/dist/core/common/services/core-s3.service.js.map +1 -0
- package/dist/core/common/services/core-trust-proxy.initializer.d.ts +16 -0
- package/dist/core/common/services/core-trust-proxy.initializer.js +77 -0
- package/dist/core/common/services/core-trust-proxy.initializer.js.map +1 -0
- package/dist/core/common/services/rate-limit-store.d.ts +61 -0
- package/dist/core/common/services/rate-limit-store.js +235 -0
- package/dist/core/common/services/rate-limit-store.js.map +1 -0
- package/dist/core/modules/ai/core-ai-mcp.controller.d.ts +19 -3
- package/dist/core/modules/ai/core-ai-mcp.controller.js +148 -18
- package/dist/core/modules/ai/core-ai-mcp.controller.js.map +1 -1
- package/dist/core/modules/ai/services/core-ai.service.d.ts +7 -2
- package/dist/core/modules/ai/services/core-ai.service.js +24 -20
- package/dist/core/modules/ai/services/core-ai.service.js.map +1 -1
- package/dist/core/modules/auth/core-auth.module.js +4 -1
- package/dist/core/modules/auth/core-auth.module.js.map +1 -1
- package/dist/core/modules/auth/guards/legacy-auth-rate-limit.guard.d.ts +1 -1
- package/dist/core/modules/auth/guards/legacy-auth-rate-limit.guard.js +3 -14
- package/dist/core/modules/auth/guards/legacy-auth-rate-limit.guard.js.map +1 -1
- package/dist/core/modules/auth/services/legacy-auth-rate-limiter.service.d.ts +12 -10
- package/dist/core/modules/auth/services/legacy-auth-rate-limiter.service.js +30 -59
- package/dist/core/modules/auth/services/legacy-auth-rate-limiter.service.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth-email-verification.service.d.ts +8 -2
- package/dist/core/modules/better-auth/core-better-auth-email-verification.service.js +118 -45
- package/dist/core/modules/better-auth/core-better-auth-email-verification.service.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth-rate-limit.middleware.d.ts +1 -1
- package/dist/core/modules/better-auth/core-better-auth-rate-limit.middleware.js +2 -11
- package/dist/core/modules/better-auth/core-better-auth-rate-limit.middleware.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth-rate-limiter.service.d.ts +12 -10
- package/dist/core/modules/better-auth/core-better-auth-rate-limiter.service.js +30 -85
- package/dist/core/modules/better-auth/core-better-auth-rate-limiter.service.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth-user.mapper.js +0 -1
- package/dist/core/modules/better-auth/core-better-auth-user.mapper.js.map +1 -1
- package/dist/core/modules/file/core-file.controller.d.ts +11 -2
- package/dist/core/modules/file/core-file.controller.js +52 -15
- package/dist/core/modules/file/core-file.controller.js.map +1 -1
- package/dist/core/modules/file/core-file.resolver.d.ts +4 -4
- package/dist/core/modules/file/core-file.resolver.js +23 -16
- package/dist/core/modules/file/core-file.resolver.js.map +1 -1
- package/dist/core/modules/file/core-file.service.d.ts +41 -7
- package/dist/core/modules/file/core-file.service.js +227 -7
- package/dist/core/modules/file/core-file.service.js.map +1 -1
- package/dist/core/modules/file/file-metadata.helper.d.ts +16 -0
- package/dist/core/modules/file/file-metadata.helper.js +33 -0
- package/dist/core/modules/file/file-metadata.helper.js.map +1 -0
- package/dist/core/modules/file/file-roles.helper.d.ts +4 -0
- package/dist/core/modules/file/file-roles.helper.js +53 -0
- package/dist/core/modules/file/file-roles.helper.js.map +1 -0
- package/dist/core/modules/file/file-storage.helper.d.ts +13 -0
- package/dist/core/modules/file/file-storage.helper.js +65 -0
- package/dist/core/modules/file/file-storage.helper.js.map +1 -0
- package/dist/core/modules/file/filesystem-file.helper.d.ts +22 -0
- package/dist/core/modules/file/filesystem-file.helper.js +77 -0
- package/dist/core/modules/file/filesystem-file.helper.js.map +1 -0
- package/dist/core/modules/file/interfaces/file-service-options.interface.d.ts +1 -0
- package/dist/core/modules/file/interfaces/file-upload.interface.d.ts +7 -1
- package/dist/core/modules/file/s3-file.helper.d.ts +37 -0
- package/dist/core/modules/file/s3-file.helper.js +81 -0
- package/dist/core/modules/file/s3-file.helper.js.map +1 -0
- package/dist/core/modules/hub/core-hub.controller.d.ts +8 -8
- package/dist/core/modules/hub/core-hub.controller.js +24 -22
- package/dist/core/modules/hub/core-hub.controller.js.map +1 -1
- package/dist/core/modules/hub/helpers/hub-mask.helper.js +2 -2
- package/dist/core/modules/hub/helpers/hub-mask.helper.js.map +1 -1
- package/dist/core/modules/hub/hub-buffer.d.ts +23 -0
- package/dist/core/modules/hub/hub-buffer.js +101 -0
- package/dist/core/modules/hub/hub-buffer.js.map +1 -0
- package/dist/core/modules/hub/services/core-hub-mailbox.service.d.ts +7 -5
- package/dist/core/modules/hub/services/core-hub-mailbox.service.js +14 -10
- package/dist/core/modules/hub/services/core-hub-mailbox.service.js.map +1 -1
- package/dist/core/modules/hub/services/hub-log-buffer.service.d.ts +5 -2
- package/dist/core/modules/hub/services/hub-log-buffer.service.js +17 -8
- package/dist/core/modules/hub/services/hub-log-buffer.service.js.map +1 -1
- package/dist/core/modules/hub/services/hub-query-profiler.service.d.ts +4 -2
- package/dist/core/modules/hub/services/hub-query-profiler.service.js +13 -7
- package/dist/core/modules/hub/services/hub-query-profiler.service.js.map +1 -1
- package/dist/core/modules/hub/services/hub-trace-buffer.service.d.ts +4 -2
- package/dist/core/modules/hub/services/hub-trace-buffer.service.js +13 -8
- package/dist/core/modules/hub/services/hub-trace-buffer.service.js.map +1 -1
- package/dist/core/modules/migrate/helpers/migration.helper.d.ts +2 -6
- package/dist/core/modules/migrate/helpers/migration.helper.js +4 -4
- package/dist/core/modules/migrate/helpers/migration.helper.js.map +1 -1
- package/dist/core/modules/migrate/migration-runner.d.ts +1 -0
- package/dist/core/modules/migrate/migration-runner.js +4 -0
- package/dist/core/modules/migrate/migration-runner.js.map +1 -1
- package/dist/core/modules/migrate/mongo-state-store.d.ts +1 -0
- package/dist/core/modules/migrate/mongo-state-store.js +98 -9
- package/dist/core/modules/migrate/mongo-state-store.js.map +1 -1
- package/dist/core/modules/system-setup/core-system-setup.service.d.ts +2 -0
- package/dist/core/modules/system-setup/core-system-setup.service.js +31 -1
- package/dist/core/modules/system-setup/core-system-setup.service.js.map +1 -1
- package/dist/core/modules/tenant/core-tenant.guard.d.ts +17 -3
- package/dist/core/modules/tenant/core-tenant.guard.js +92 -15
- package/dist/core/modules/tenant/core-tenant.guard.js.map +1 -1
- package/dist/core/modules/tenant/core-tenant.module.js +3 -4
- package/dist/core/modules/tenant/core-tenant.module.js.map +1 -1
- package/dist/core/modules/tus/core-tus.controller.d.ts +2 -0
- package/dist/core/modules/tus/core-tus.controller.js +29 -3
- package/dist/core/modules/tus/core-tus.controller.js.map +1 -1
- package/dist/core/modules/tus/core-tus.service.d.ts +24 -1
- package/dist/core/modules/tus/core-tus.service.js +182 -28
- package/dist/core/modules/tus/core-tus.service.js.map +1 -1
- package/dist/core/modules/tus/interfaces/tus-config.interface.js +3 -0
- package/dist/core/modules/tus/interfaces/tus-config.interface.js.map +1 -1
- package/dist/core/modules/tus/tus-redis-locker.d.ts +25 -0
- package/dist/core/modules/tus/tus-redis-locker.js +87 -0
- package/dist/core/modules/tus/tus-redis-locker.js.map +1 -0
- package/dist/core/modules/tus/tus.module.d.ts +1 -0
- package/dist/core/modules/tus/tus.module.js +30 -4
- package/dist/core/modules/tus/tus.module.js.map +1 -1
- package/dist/core.module.js +18 -1
- package/dist/core.module.js.map +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/main.js +2 -1
- package/dist/main.js.map +1 -1
- package/dist/server/modules/file/file.controller.js.map +1 -1
- package/dist/server/modules/file/file.resolver.js +1 -12
- package/dist/server/modules/file/file.resolver.js.map +1 -1
- package/dist/server/modules/file/file.service.d.ts +5 -1
- package/dist/server/modules/file/file.service.js +12 -3
- package/dist/server/modules/file/file.service.js.map +1 -1
- package/dist/server/modules/user/avatar.controller.d.ts +5 -1
- package/dist/server/modules/user/avatar.controller.js +26 -10
- package/dist/server/modules/user/avatar.controller.js.map +1 -1
- package/dist/server/modules/user/user.model.js +3 -2
- package/dist/server/modules/user/user.model.js.map +1 -1
- package/dist/server/modules/user/user.module.js +6 -2
- package/dist/server/modules/user/user.module.js.map +1 -1
- package/dist/server/modules/user/user.service.d.ts +1 -1
- package/dist/server/modules/user/user.service.js +6 -13
- package/dist/server/modules/user/user.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/docs/REQUEST-LIFECYCLE.md +57 -8
- package/docs/security-overrides.md +21 -3
- package/migration-guides/11.32.3-to-11.32.4.md +15 -3
- package/migration-guides/11.32.x-to-11.33.x.md +1551 -0
- package/package.json +74 -42
- package/src/core/common/helpers/content-disposition.helper.ts +90 -0
- package/src/core/common/helpers/file.helper.ts +53 -10
- package/src/core/common/helpers/graceful-shutdown.helper.ts +116 -0
- package/src/core/common/helpers/project-name.helper.ts +71 -0
- package/src/core/common/interfaces/cron-job-config.interface.ts +16 -0
- package/src/core/common/interfaces/server-options.interface.ts +439 -2
- package/src/core/common/services/core-cron-jobs.initializer.ts +39 -0
- package/src/core/common/services/core-cron-jobs.registry.ts +45 -0
- package/src/core/common/services/core-cron-jobs.service.ts +589 -47
- package/src/core/common/services/core-redis-pubsub.ts +183 -0
- package/src/core/common/services/core-redis.service.ts +249 -0
- package/src/core/common/services/core-s3.service.ts +465 -0
- package/src/core/common/services/core-trust-proxy.initializer.ts +112 -0
- package/src/core/common/services/rate-limit-store.ts +492 -0
- package/src/core/modules/ai/README.md +25 -0
- package/src/core/modules/ai/core-ai-mcp.controller.ts +253 -22
- package/src/core/modules/ai/services/core-ai.service.ts +33 -24
- package/src/core/modules/auth/core-auth.module.ts +7 -1
- package/src/core/modules/auth/guards/legacy-auth-rate-limit.guard.ts +12 -21
- package/src/core/modules/auth/services/legacy-auth-rate-limiter.service.ts +49 -93
- package/src/core/modules/better-auth/core-better-auth-email-verification.service.ts +202 -66
- package/src/core/modules/better-auth/core-better-auth-rate-limit.middleware.ts +11 -18
- package/src/core/modules/better-auth/core-better-auth-rate-limiter.service.ts +51 -132
- package/src/core/modules/better-auth/core-better-auth-user.mapper.ts +7 -1
- package/src/core/modules/file/INTEGRATION-CHECKLIST.md +108 -0
- package/src/core/modules/file/README.md +277 -53
- package/src/core/modules/file/core-file.controller.ts +168 -12
- package/src/core/modules/file/core-file.resolver.ts +46 -12
- package/src/core/modules/file/core-file.service.ts +482 -16
- package/src/core/modules/file/file-metadata.helper.ts +142 -0
- package/src/core/modules/file/file-roles.helper.ts +110 -0
- package/src/core/modules/file/file-storage.helper.ts +163 -0
- package/src/core/modules/file/filesystem-file.helper.ts +184 -0
- package/src/core/modules/file/interfaces/file-service-options.interface.ts +14 -0
- package/src/core/modules/file/interfaces/file-upload.interface.ts +17 -1
- package/src/core/modules/file/s3-file.helper.ts +209 -0
- package/src/core/modules/hub/README.md +48 -0
- package/src/core/modules/hub/core-hub.controller.ts +18 -16
- package/src/core/modules/hub/helpers/hub-mask.helper.ts +21 -4
- package/src/core/modules/hub/hub-buffer.ts +198 -0
- package/src/core/modules/hub/services/core-hub-mailbox.service.ts +22 -12
- package/src/core/modules/hub/services/hub-log-buffer.service.ts +24 -8
- package/src/core/modules/hub/services/hub-query-profiler.service.ts +9 -6
- package/src/core/modules/hub/services/hub-trace-buffer.service.ts +14 -9
- package/src/core/modules/migrate/README.md +33 -6
- package/src/core/modules/migrate/helpers/migration.helper.ts +13 -6
- package/src/core/modules/migrate/migration-runner.ts +10 -1
- package/src/core/modules/migrate/mongo-state-store.ts +179 -11
- package/src/core/modules/system-setup/README.md +7 -2
- package/src/core/modules/system-setup/core-system-setup.service.ts +95 -1
- package/src/core/modules/tenant/README.md +21 -1
- package/src/core/modules/tenant/core-tenant.guard.ts +135 -14
- package/src/core/modules/tenant/core-tenant.module.ts +8 -4
- package/src/core/modules/tus/INTEGRATION-CHECKLIST.md +93 -21
- package/src/core/modules/tus/README.md +35 -2
- package/src/core/modules/tus/core-tus.controller.ts +64 -12
- package/src/core/modules/tus/core-tus.service.ts +358 -34
- package/src/core/modules/tus/interfaces/tus-config.interface.ts +9 -0
- package/src/core/modules/tus/tus-redis-locker.ts +139 -0
- package/src/core/modules/tus/tus.module.ts +78 -6
- package/src/core.module.ts +26 -1
- package/src/index.ts +10 -0
- package/src/main.ts +7 -1
- package/src/server/modules/file/file.controller.ts +7 -3
- package/src/server/modules/file/file.resolver.ts +5 -17
- package/src/server/modules/file/file.service.ts +42 -3
- package/src/server/modules/user/avatar.controller.ts +39 -9
- package/src/server/modules/user/user.model.ts +9 -3
- package/src/server/modules/user/user.module.ts +12 -3
- package/src/server/modules/user/user.service.ts +20 -17
- package/src/test/README.md +7 -2
- package/src/core/common/helpers/file.helper.spec.ts +0 -145
- package/src/core/common/helpers/logging.helper.spec.ts +0 -61
- package/src/core/common/helpers/process-diagnostics.helper.spec.ts +0 -310
- package/src/core/common/services/brevo.service.spec.ts +0 -266
- package/src/core/modules/file/core-file.controller.spec.ts +0 -164
- package/src/core/modules/hub/core-hub.module.spec.ts +0 -108
- package/src/core/modules/hub/helpers/hub-command-shape.helper.spec.ts +0 -48
- package/src/core/modules/hub/helpers/hub-mask.helper.spec.ts +0 -67
- package/src/core/modules/hub/helpers/hub-mermaid.helper.spec.ts +0 -61
- package/src/core/modules/hub/helpers/hub-shell.helper.spec.ts +0 -106
- package/src/core/modules/hub/hub-config.helper.spec.ts +0 -108
- package/src/core/modules/hub/hub-ring-buffer.spec.ts +0 -95
- package/src/core/modules/hub/services/core-hub-mailbox.service.spec.ts +0 -116
- package/src/core/modules/hub/services/hub-trace-buffer.service.spec.ts +0 -112
- package/src/core/modules/migrate/helpers/migration.helper.spec.ts +0 -85
|
@@ -108,6 +108,13 @@ export interface IErrorCode {
|
|
|
108
108
|
}>;
|
|
109
109
|
autoRegister?: boolean;
|
|
110
110
|
}
|
|
111
|
+
export interface IFileConfig {
|
|
112
|
+
deleteRoles?: string[];
|
|
113
|
+
downloadRoles?: string[];
|
|
114
|
+
storage?: 'filesystem' | 'gridfs' | 's3';
|
|
115
|
+
storageDir?: string;
|
|
116
|
+
uploadRoles?: string[];
|
|
117
|
+
}
|
|
111
118
|
export interface IJwt {
|
|
112
119
|
privateKey?: string;
|
|
113
120
|
publicKey?: string;
|
|
@@ -243,6 +250,7 @@ export interface IServerOptions {
|
|
|
243
250
|
version?: string;
|
|
244
251
|
errorCode?: IErrorCode;
|
|
245
252
|
execAfterInit?: string;
|
|
253
|
+
file?: IFileConfig;
|
|
246
254
|
filter?: {
|
|
247
255
|
maxLimit?: number;
|
|
248
256
|
};
|
|
@@ -301,6 +309,8 @@ export interface IServerOptions {
|
|
|
301
309
|
multiTenancy?: IMultiTenancy;
|
|
302
310
|
permissions?: boolean | IPermissions;
|
|
303
311
|
port?: number;
|
|
312
|
+
redis?: boolean | IRedisConfig;
|
|
313
|
+
s3?: IS3Config;
|
|
304
314
|
security?: {
|
|
305
315
|
checkResponseInterceptor?: boolean | {
|
|
306
316
|
checkObjectItself?: boolean;
|
|
@@ -334,6 +344,7 @@ export interface IServerOptions {
|
|
|
334
344
|
secretFields?: string[];
|
|
335
345
|
};
|
|
336
346
|
sha256?: boolean;
|
|
347
|
+
shutdownDelayMs?: number;
|
|
337
348
|
staticAssets?: {
|
|
338
349
|
options?: ServeStaticOptions;
|
|
339
350
|
path?: string;
|
|
@@ -343,8 +354,34 @@ export interface IServerOptions {
|
|
|
343
354
|
engine?: string;
|
|
344
355
|
path?: string;
|
|
345
356
|
};
|
|
357
|
+
trustProxy?: boolean | number | string | string[];
|
|
346
358
|
tus?: boolean | ITusConfig;
|
|
347
359
|
}
|
|
360
|
+
export interface IRedisConfig {
|
|
361
|
+
db?: number;
|
|
362
|
+
enabled?: boolean;
|
|
363
|
+
host?: string;
|
|
364
|
+
keyPrefix?: string;
|
|
365
|
+
options?: Record<string, unknown>;
|
|
366
|
+
password?: string;
|
|
367
|
+
port?: number;
|
|
368
|
+
url?: string;
|
|
369
|
+
username?: string;
|
|
370
|
+
}
|
|
371
|
+
export interface IS3Config {
|
|
372
|
+
accessKeyId?: string;
|
|
373
|
+
autoCreateBucket?: boolean;
|
|
374
|
+
bucket: string;
|
|
375
|
+
enabled?: boolean;
|
|
376
|
+
endpoint?: string;
|
|
377
|
+
forcePathStyle?: boolean;
|
|
378
|
+
presignedDownloads?: boolean | {
|
|
379
|
+
expiresInSeconds?: number;
|
|
380
|
+
};
|
|
381
|
+
region?: string;
|
|
382
|
+
secretAccessKey?: string;
|
|
383
|
+
stagingBucket?: string;
|
|
384
|
+
}
|
|
348
385
|
export interface ISystemSetup {
|
|
349
386
|
enabled?: boolean;
|
|
350
387
|
initialAdmin?: ISystemSetupInitialAdmin;
|
|
@@ -365,6 +402,8 @@ export interface ITusConfig {
|
|
|
365
402
|
expiration?: boolean | ITusExpirationConfig;
|
|
366
403
|
maxSize?: number;
|
|
367
404
|
path?: string;
|
|
405
|
+
roles?: string[];
|
|
406
|
+
s3Staging?: boolean;
|
|
368
407
|
termination?: boolean;
|
|
369
408
|
uploadDir?: string;
|
|
370
409
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { OnApplicationShutdown, OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { Connection } from 'mongoose';
|
|
3
|
+
import { CoreRedisService } from './core-redis.service';
|
|
4
|
+
export declare class CoreCronJobsInitializer implements OnApplicationShutdown, OnModuleInit {
|
|
5
|
+
protected readonly connection: Connection;
|
|
6
|
+
protected readonly redisService?: CoreRedisService;
|
|
7
|
+
constructor(connection: Connection, redisService?: CoreRedisService);
|
|
8
|
+
onModuleInit(): void;
|
|
9
|
+
onApplicationShutdown(): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CoreCronJobsInitializer = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
18
|
+
const mongoose_2 = require("mongoose");
|
|
19
|
+
const core_cron_jobs_registry_1 = require("./core-cron-jobs.registry");
|
|
20
|
+
const core_redis_service_1 = require("./core-redis.service");
|
|
21
|
+
let CoreCronJobsInitializer = class CoreCronJobsInitializer {
|
|
22
|
+
connection;
|
|
23
|
+
redisService;
|
|
24
|
+
constructor(connection, redisService) {
|
|
25
|
+
this.connection = connection;
|
|
26
|
+
this.redisService = redisService;
|
|
27
|
+
}
|
|
28
|
+
onModuleInit() {
|
|
29
|
+
(0, core_cron_jobs_registry_1.setCronJobsInfrastructure)({
|
|
30
|
+
connection: this.connection,
|
|
31
|
+
redisService: this.redisService?.enabled ? this.redisService : undefined,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
onApplicationShutdown() {
|
|
35
|
+
(0, core_cron_jobs_registry_1.setCronJobsInfrastructure)({});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.CoreCronJobsInitializer = CoreCronJobsInitializer;
|
|
39
|
+
exports.CoreCronJobsInitializer = CoreCronJobsInitializer = __decorate([
|
|
40
|
+
(0, common_1.Injectable)(),
|
|
41
|
+
__param(0, (0, mongoose_1.InjectConnection)()),
|
|
42
|
+
__param(1, (0, common_1.Optional)()),
|
|
43
|
+
__metadata("design:paramtypes", [mongoose_2.Connection,
|
|
44
|
+
core_redis_service_1.CoreRedisService])
|
|
45
|
+
], CoreCronJobsInitializer);
|
|
46
|
+
//# sourceMappingURL=core-cron-jobs.initializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-cron-jobs.initializer.js","sourceRoot":"","sources":["../../../../src/core/common/services/core-cron-jobs.initializer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2F;AAC3F,+CAAoD;AACpD,uCAAsC;AAEtC,uEAAsE;AACtE,6DAAwD;AAUjD,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAEO;IACR;IAFjC,YACyC,UAAsB,EAC9B,YAA+B;QADvB,eAAU,GAAV,UAAU,CAAY;QAC9B,iBAAY,GAAZ,YAAY,CAAmB;IAC7D,CAAC;IAEJ,YAAY;QACV,IAAA,mDAAyB,EAAC;YACxB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;SACzE,CAAC,CAAC;IACL,CAAC;IASD,qBAAqB;QACnB,IAAA,mDAAyB,EAAC,EAAE,CAAC,CAAC;IAChC,CAAC;CACF,CAAA;AAvBY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,2BAAgB,GAAE,CAAA;IAClB,WAAA,IAAA,iBAAQ,GAAE,CAAA;qCADwC,qBAAU;QACf,qCAAgB;GAHrD,uBAAuB,CAuBnC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CoreRedisService } from './core-redis.service';
|
|
2
|
+
import type { Connection } from 'mongoose';
|
|
3
|
+
export interface CronJobsInfrastructure {
|
|
4
|
+
connection?: Connection;
|
|
5
|
+
redisService?: CoreRedisService;
|
|
6
|
+
}
|
|
7
|
+
export declare function getCronJobsInfrastructure(): CronJobsInfrastructure;
|
|
8
|
+
export declare function setCronJobsInfrastructure(value: CronJobsInfrastructure): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCronJobsInfrastructure = getCronJobsInfrastructure;
|
|
4
|
+
exports.setCronJobsInfrastructure = setCronJobsInfrastructure;
|
|
5
|
+
let infrastructure = {};
|
|
6
|
+
function getCronJobsInfrastructure() {
|
|
7
|
+
return infrastructure;
|
|
8
|
+
}
|
|
9
|
+
function setCronJobsInfrastructure(value) {
|
|
10
|
+
infrastructure = value ?? {};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=core-cron-jobs.registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-cron-jobs.registry.js","sourceRoot":"","sources":["../../../../src/core/common/services/core-cron-jobs.registry.ts"],"names":[],"mappings":";;AAkCA,8DAEC;AAMD,8DAEC;AAfD,IAAI,cAAc,GAA2B,EAAE,CAAC;AAKhD,SAAgB,yBAAyB;IACvC,OAAO,cAAc,CAAC;AACxB,CAAC;AAMD,SAAgB,yBAAyB,CAAC,KAA6B;IACrE,cAAc,GAAG,KAAK,IAAI,EAAE,CAAC;AAC/B,CAAC"}
|
|
@@ -1,19 +1,49 @@
|
|
|
1
|
-
import { OnApplicationBootstrap } from '@nestjs/common';
|
|
1
|
+
import { OnApplicationBootstrap, OnApplicationShutdown } from '@nestjs/common';
|
|
2
2
|
import { CronExpression, SchedulerRegistry } from '@nestjs/schedule';
|
|
3
3
|
import { CronJobConfigWithTimeZone } from '../interfaces/cron-job-config-with-time-zone.interface';
|
|
4
4
|
import { CronJobConfigWithUtcOffset } from '../interfaces/cron-job-config-with-utc-offset.interface';
|
|
5
5
|
import { Falsy } from '../types/falsy.type';
|
|
6
|
-
|
|
6
|
+
import type { CoreRedisService } from './core-redis.service';
|
|
7
|
+
import type { Redis } from 'ioredis';
|
|
8
|
+
import type { Connection } from 'mongoose';
|
|
9
|
+
export interface CoreCronJobsOptions {
|
|
10
|
+
connection?: Connection;
|
|
11
|
+
log?: boolean;
|
|
12
|
+
redisService?: CoreRedisService;
|
|
13
|
+
}
|
|
14
|
+
export declare abstract class CoreCronJobs implements OnApplicationBootstrap, OnApplicationShutdown {
|
|
7
15
|
protected schedulerRegistry: SchedulerRegistry;
|
|
8
16
|
protected cronJobs: Record<string, CronExpression | CronJobConfigWithTimeZone | CronJobConfigWithUtcOffset | Date | Falsy | string>;
|
|
17
|
+
protected readonly options?: CoreCronJobsOptions;
|
|
9
18
|
config: {
|
|
10
19
|
[key: string]: any;
|
|
11
20
|
log: boolean;
|
|
12
21
|
};
|
|
13
22
|
runningJobs: Record<string, Date[]>;
|
|
14
|
-
protected
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
protected
|
|
23
|
+
protected bullQueue?: any;
|
|
24
|
+
protected bullWorker?: any;
|
|
25
|
+
protected dedupWarned: boolean;
|
|
26
|
+
protected jobConfigs: Record<string, CronJobConfigWithTimeZone>;
|
|
27
|
+
protected leaseIndexReady?: Promise<void>;
|
|
28
|
+
protected constructor(schedulerRegistry: SchedulerRegistry, cronJobs: Record<string, CronExpression | CronJobConfigWithTimeZone | CronJobConfigWithUtcOffset | Date | Falsy | string>, options?: CoreCronJobsOptions);
|
|
29
|
+
onApplicationBootstrap(): Promise<void>;
|
|
30
|
+
onApplicationShutdown(): Promise<void>;
|
|
31
|
+
protected initCronJobs(): Promise<void>;
|
|
32
|
+
protected acquireLease(name: string, fireTime: Date | 'init' | 'manual'): Promise<boolean>;
|
|
33
|
+
protected ensureLeaseIndex(connection: Connection): Promise<void>;
|
|
34
|
+
protected getConnection(): Connection | undefined;
|
|
35
|
+
protected getRedisClient(): Redis | undefined;
|
|
36
|
+
protected getRedisService(): CoreRedisService | undefined;
|
|
37
|
+
protected importBullMq(): Promise<any>;
|
|
38
|
+
protected initBullMq(): Promise<boolean>;
|
|
39
|
+
protected drainRunningJobs(timeoutMs?: number): Promise<void>;
|
|
40
|
+
protected removeStaleBullSchedulers(active: Set<string>): Promise<void>;
|
|
41
|
+
protected startBullWorker(): void;
|
|
42
|
+
protected logSkippedTick(leaseKey: string): void;
|
|
43
|
+
protected registerBullJob(name: string, config: CronJobConfigWithTimeZone): Promise<void>;
|
|
44
|
+
protected registerLocalJob(name: string, config: CronJobConfigWithTimeZone, distributed: boolean): void;
|
|
45
|
+
protected runDistributedTick(name: string, fireTime: Date | 'init' | 'manual'): Promise<void>;
|
|
46
|
+
protected runInitTick(name: string): void;
|
|
47
|
+
protected runTick(name: string): Promise<void>;
|
|
48
|
+
protected warnDedupInactive(): void;
|
|
19
49
|
}
|
|
@@ -2,29 +2,54 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CoreCronJobs = void 0;
|
|
4
4
|
const cron_1 = require("cron");
|
|
5
|
+
const core_cron_jobs_registry_1 = require("./core-cron-jobs.registry");
|
|
6
|
+
const CRON_LOCK_COLLECTION = 'cron-locks';
|
|
7
|
+
const CRON_LOCK_TTL_SECONDS = 3600;
|
|
8
|
+
const CRON_INIT_LOCK_TTL_SECONDS = 300;
|
|
9
|
+
const CRON_QUEUE_NAME = 'cron';
|
|
5
10
|
class CoreCronJobs {
|
|
6
11
|
schedulerRegistry;
|
|
7
12
|
cronJobs;
|
|
13
|
+
options;
|
|
8
14
|
config;
|
|
9
15
|
runningJobs = {};
|
|
16
|
+
bullQueue;
|
|
17
|
+
bullWorker;
|
|
18
|
+
dedupWarned = false;
|
|
19
|
+
jobConfigs = {};
|
|
20
|
+
leaseIndexReady;
|
|
10
21
|
constructor(schedulerRegistry, cronJobs, options) {
|
|
11
22
|
this.schedulerRegistry = schedulerRegistry;
|
|
12
23
|
this.cronJobs = cronJobs;
|
|
24
|
+
this.options = options;
|
|
13
25
|
this.config = {
|
|
14
26
|
log: true,
|
|
15
27
|
...options,
|
|
16
28
|
};
|
|
17
29
|
}
|
|
18
|
-
onApplicationBootstrap() {
|
|
30
|
+
async onApplicationBootstrap() {
|
|
19
31
|
if (this.config.log) {
|
|
20
32
|
console.info('Init CronJobs after application bootstrap');
|
|
21
33
|
}
|
|
22
|
-
this.initCronJobs();
|
|
34
|
+
await this.initCronJobs();
|
|
23
35
|
}
|
|
24
|
-
|
|
36
|
+
async onApplicationShutdown() {
|
|
37
|
+
await this.drainRunningJobs();
|
|
38
|
+
const results = await Promise.allSettled([this.bullWorker?.close(), this.bullQueue?.close()]);
|
|
39
|
+
for (const result of results) {
|
|
40
|
+
if (result.status === 'rejected') {
|
|
41
|
+
console.error('BullMQ shutdown failed', result.reason);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
this.bullWorker = undefined;
|
|
45
|
+
this.bullQueue = undefined;
|
|
46
|
+
}
|
|
47
|
+
async initCronJobs() {
|
|
25
48
|
if (!this.cronJobs) {
|
|
26
49
|
return;
|
|
27
50
|
}
|
|
51
|
+
const bullMqActive = await this.initBullMq();
|
|
52
|
+
const bullScheduled = new Set();
|
|
28
53
|
for (const [name, CronExpressionOrConfig] of Object.entries(this.cronJobs)) {
|
|
29
54
|
if (!CronExpressionOrConfig ||
|
|
30
55
|
(typeof CronExpressionOrConfig === 'object' && CronExpressionOrConfig.disabled)) {
|
|
@@ -37,6 +62,7 @@ class CoreCronJobs {
|
|
|
37
62
|
};
|
|
38
63
|
}
|
|
39
64
|
const config = {
|
|
65
|
+
distributed: !!this.getRedisService()?.enabled,
|
|
40
66
|
runOnInit: true,
|
|
41
67
|
runParallel: true,
|
|
42
68
|
throwException: true,
|
|
@@ -52,36 +78,261 @@ class CoreCronJobs {
|
|
|
52
78
|
}
|
|
53
79
|
continue;
|
|
54
80
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
81
|
+
this.jobConfigs[name] = config;
|
|
82
|
+
const distributed = config.distributed !== false;
|
|
83
|
+
if (bullMqActive && distributed) {
|
|
84
|
+
if (typeof config.cronTime === 'string' && !config.utcOffset) {
|
|
85
|
+
await this.registerBullJob(name, config);
|
|
86
|
+
bullScheduled.add(name);
|
|
87
|
+
continue;
|
|
60
88
|
}
|
|
61
|
-
|
|
62
|
-
|
|
89
|
+
console.debug(`CronJob ${name} cannot be expressed as BullMQ scheduler (${typeof config.cronTime === 'string' ? 'utcOffset is set' : 'cronTime is a Date'}), falling back to a local timer with lease`);
|
|
90
|
+
}
|
|
91
|
+
this.registerLocalJob(name, config, distributed);
|
|
92
|
+
}
|
|
93
|
+
await this.removeStaleBullSchedulers(bullScheduled);
|
|
94
|
+
this.startBullWorker();
|
|
95
|
+
}
|
|
96
|
+
async acquireLease(name, fireTime) {
|
|
97
|
+
const leaseKey = fireTime === 'manual'
|
|
98
|
+
? `${name}:manual:${Date.now()}:${process.pid}`
|
|
99
|
+
: fireTime === 'init'
|
|
100
|
+
? `${name}:init`
|
|
101
|
+
: `${name}:${new Date(Math.floor(fireTime.getTime() / 1000) * 1000).toISOString()}`;
|
|
102
|
+
const ttlSeconds = fireTime === 'init' ? CRON_INIT_LOCK_TTL_SECONDS : CRON_LOCK_TTL_SECONDS;
|
|
103
|
+
const redis = this.getRedisClient();
|
|
104
|
+
if (redis) {
|
|
105
|
+
try {
|
|
106
|
+
const acquired = await redis.set(this.getRedisService().key('cron-lock', leaseKey), '1', 'EX', ttlSeconds, 'NX');
|
|
107
|
+
if (acquired === null) {
|
|
108
|
+
this.logSkippedTick(leaseKey);
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
console.error(`Cron lease for ${leaseKey} failed on Redis, running the tick anyway`, e);
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const connection = this.getConnection();
|
|
119
|
+
if (!connection) {
|
|
120
|
+
this.warnDedupInactive();
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
await this.ensureLeaseIndex(connection);
|
|
124
|
+
try {
|
|
125
|
+
await connection.db.collection(CRON_LOCK_COLLECTION).insertOne({
|
|
126
|
+
_id: leaseKey,
|
|
127
|
+
createdAt: new Date(),
|
|
128
|
+
expiresAt: new Date(Date.now() + ttlSeconds * 1000),
|
|
129
|
+
});
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
if (e?.code === 11000) {
|
|
134
|
+
this.logSkippedTick(leaseKey);
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
console.error(`Cron lease for ${leaseKey} failed, running the tick anyway`, e);
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async ensureLeaseIndex(connection) {
|
|
142
|
+
if (!this.leaseIndexReady) {
|
|
143
|
+
this.leaseIndexReady = connection.db
|
|
144
|
+
.collection(CRON_LOCK_COLLECTION)
|
|
145
|
+
.createIndex({ expiresAt: 1 }, { expireAfterSeconds: 0 })
|
|
146
|
+
.then(() => undefined)
|
|
147
|
+
.catch((e) => {
|
|
148
|
+
console.error('Could not create TTL index on cron lock collection', e);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return this.leaseIndexReady;
|
|
152
|
+
}
|
|
153
|
+
getConnection() {
|
|
154
|
+
return this.options?.connection ?? (0, core_cron_jobs_registry_1.getCronJobsInfrastructure)().connection;
|
|
155
|
+
}
|
|
156
|
+
getRedisClient() {
|
|
157
|
+
const service = this.getRedisService();
|
|
158
|
+
if (!service?.enabled) {
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
return service.getClient();
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
getRedisService() {
|
|
169
|
+
return this.options?.redisService ?? (0, core_cron_jobs_registry_1.getCronJobsInfrastructure)().redisService;
|
|
170
|
+
}
|
|
171
|
+
importBullMq() {
|
|
172
|
+
return Promise.resolve().then(() => require('bullmq'));
|
|
173
|
+
}
|
|
174
|
+
async initBullMq() {
|
|
175
|
+
const service = this.getRedisService();
|
|
176
|
+
if (!service?.enabled) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
let bullmq;
|
|
180
|
+
try {
|
|
181
|
+
bullmq = await this.importBullMq();
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
console.warn('Redis is configured but the optional peer dependency "bullmq" is not installed — cron jobs fall back to ' +
|
|
185
|
+
'per-tick MongoDB leases. Run: pnpm add bullmq');
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
const prefix = `${service.getConfig().keyPrefix}:bull`;
|
|
189
|
+
const blockingOptions = { commandTimeout: undefined, maxRetriesPerRequest: null };
|
|
190
|
+
const queueOptions = { commandTimeout: 10_000, maxRetriesPerRequest: 3 };
|
|
191
|
+
this.bullQueue = new bullmq.Queue(CRON_QUEUE_NAME, {
|
|
192
|
+
connection: service.createClient('cron-queue', queueOptions),
|
|
193
|
+
prefix,
|
|
194
|
+
});
|
|
195
|
+
const workerConnection = service.createClient('cron-worker', blockingOptions);
|
|
196
|
+
this.bullWorker = new bullmq.Worker(CRON_QUEUE_NAME, async (job) => this.runTick(job.name), {
|
|
197
|
+
autorun: false,
|
|
198
|
+
connection: workerConnection,
|
|
199
|
+
prefix,
|
|
200
|
+
});
|
|
201
|
+
this.bullWorker.on('error', (error) => {
|
|
202
|
+
console.error(`BullMQ cron worker error: ${error.message}`);
|
|
203
|
+
});
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
async drainRunningJobs(timeoutMs = 10_000) {
|
|
207
|
+
const deadline = Date.now() + timeoutMs;
|
|
208
|
+
const running = () => Object.values(this.runningJobs).reduce((sum, dates) => sum + (dates?.length ?? 0), 0);
|
|
209
|
+
if (!running()) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
console.info(`Waiting up to ${timeoutMs}ms for ${running()} running cron job(s) to finish`);
|
|
213
|
+
while (running() && Date.now() < deadline) {
|
|
214
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
215
|
+
}
|
|
216
|
+
if (running()) {
|
|
217
|
+
console.warn(`${running()} cron job(s) still running after ${timeoutMs}ms — shutting down anyway`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
async removeStaleBullSchedulers(active) {
|
|
221
|
+
if (!this.bullQueue) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
const known = new Set(Object.keys(this.cronJobs ?? {}));
|
|
226
|
+
for (const scheduler of await this.bullQueue.getJobSchedulers()) {
|
|
227
|
+
if (scheduler?.key && known.has(scheduler.key) && !active.has(scheduler.key)) {
|
|
228
|
+
await this.bullQueue.removeJobScheduler(scheduler.key);
|
|
229
|
+
console.info(`CronJob scheduler ${scheduler.key} removed — no longer configured`);
|
|
63
230
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
console.warn('Failed to reconcile BullMQ job schedulers', error);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
startBullWorker() {
|
|
238
|
+
if (!this.bullWorker) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
this.bullWorker.concurrency = Math.max(1, Object.keys(this.jobConfigs).length);
|
|
242
|
+
this.bullWorker.run().catch((e) => console.error('BullMQ cron worker stopped', e));
|
|
243
|
+
}
|
|
244
|
+
logSkippedTick(leaseKey) {
|
|
245
|
+
if (this.config.log) {
|
|
246
|
+
console.debug(`CronJob tick ${leaseKey} skipped, lease held by another replica`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
async registerBullJob(name, config) {
|
|
250
|
+
await this.bullQueue.upsertJobScheduler(name, { pattern: config.cronTime, tz: config.timeZone ?? undefined }, { name });
|
|
251
|
+
if (config.runOnInit) {
|
|
252
|
+
this.runInitTick(name);
|
|
253
|
+
}
|
|
254
|
+
if (!this.schedulerRegistry.doesExist('cron', name)) {
|
|
255
|
+
const registryJob = new cron_1.CronJob(config.cronTime, () => this.runInitTick(name), null, false, config.timeZone, config.context, false, config.utcOffset, config.unrefTimeout);
|
|
256
|
+
this.schedulerRegistry.addCronJob(name, registryJob);
|
|
257
|
+
}
|
|
258
|
+
if (this.config.log) {
|
|
259
|
+
console.info(`CronJob ${name} initialized with "${config.cronTime}" (BullMQ scheduler)`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
registerLocalJob(name, config, distributed) {
|
|
263
|
+
const ref = {};
|
|
264
|
+
let lastLeasedFireTime;
|
|
265
|
+
const job = new cron_1.CronJob(config.cronTime, async () => {
|
|
266
|
+
if (distributed) {
|
|
267
|
+
const scheduled = ref.job?.lastDate();
|
|
268
|
+
if (!scheduled) {
|
|
269
|
+
this.runInitTick(name);
|
|
270
|
+
return;
|
|
68
271
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
throw e;
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
console.error(e);
|
|
76
|
-
}
|
|
272
|
+
if (scheduled.getTime() === lastLeasedFireTime) {
|
|
273
|
+
await this.runDistributedTick(name, 'manual');
|
|
274
|
+
return;
|
|
77
275
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (this.config.log && this.schedulerRegistry.getCronJob(name)) {
|
|
82
|
-
console.info(`CronJob ${name} initialized with "${config.cronTime}"`);
|
|
276
|
+
lastLeasedFireTime = scheduled.getTime();
|
|
277
|
+
await this.runDistributedTick(name, scheduled);
|
|
278
|
+
return;
|
|
83
279
|
}
|
|
280
|
+
await this.runTick(name);
|
|
281
|
+
}, null, true, config.timeZone, config.context, config.runOnInit, config.utcOffset, config.unrefTimeout);
|
|
282
|
+
ref.job = job;
|
|
283
|
+
this.schedulerRegistry.addCronJob(name, job);
|
|
284
|
+
if (this.config.log && this.schedulerRegistry.getCronJob(name)) {
|
|
285
|
+
console.info(`CronJob ${name} initialized with "${config.cronTime}"`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
async runDistributedTick(name, fireTime) {
|
|
289
|
+
if (!(await this.acquireLease(name, fireTime))) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
await this.runTick(name);
|
|
293
|
+
}
|
|
294
|
+
runInitTick(name) {
|
|
295
|
+
this.runDistributedTick(name, 'init').catch((e) => {
|
|
296
|
+
console.error(`CronJob ${name} failed on its startup run`, e);
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
async runTick(name) {
|
|
300
|
+
const config = this.jobConfigs[name];
|
|
301
|
+
if (!config) {
|
|
302
|
+
console.warn(`CronJob tick for "${name}" dropped — no registered config`);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const dates = this.runningJobs[name];
|
|
306
|
+
if (dates?.length &&
|
|
307
|
+
(!config.runParallel || (typeof config.runParallel === 'number' && dates.length >= config.runParallel))) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (!this.runningJobs[name]) {
|
|
311
|
+
this.runningJobs[name] = [];
|
|
312
|
+
}
|
|
313
|
+
const date = new Date();
|
|
314
|
+
this.runningJobs[name].push(date);
|
|
315
|
+
try {
|
|
316
|
+
await this[name]();
|
|
317
|
+
}
|
|
318
|
+
catch (e) {
|
|
319
|
+
this.runningJobs[name] = this.runningJobs[name].filter((item) => item !== date);
|
|
320
|
+
if (config.throwException) {
|
|
321
|
+
throw e;
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
console.error(e);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
this.runningJobs[name] = this.runningJobs[name].filter((item) => item !== date);
|
|
328
|
+
}
|
|
329
|
+
warnDedupInactive() {
|
|
330
|
+
if (this.dedupWarned) {
|
|
331
|
+
return;
|
|
84
332
|
}
|
|
333
|
+
this.dedupWarned = true;
|
|
334
|
+
console.warn('Cron job deduplication is inactive: neither a Redis service nor a Mongoose connection was passed to ' +
|
|
335
|
+
'CoreCronJobs. Every replica runs every tick.');
|
|
85
336
|
}
|
|
86
337
|
}
|
|
87
338
|
exports.CoreCronJobs = CoreCronJobs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-cron-jobs.service.js","sourceRoot":"","sources":["../../../../src/core/common/services/core-cron-jobs.service.ts"],"names":[],"mappings":";;;AAEA,+BAA+B;AAS/B,MAAsB,YAAY;IAsBpB;IACA;IAnBZ,MAAM,CAGJ;IAKF,WAAW,GAA2B,EAAE,CAAC;IASzC,YACY,iBAAoC,EACpC,QAGT,EACD,OAA2B;QALjB,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,aAAQ,GAAR,QAAQ,CAGjB;QAGD,IAAI,CAAC,MAAM,GAAG;YACZ,GAAG,EAAE,IAAI;YACT,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;IAMD,sBAAsB;QACpB,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;YACpB,OAAO,CAAC,IAAI,CAAC,2CAA2C,CAAC,CAAC;QAC5D,CAAC;QACD,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAKS,YAAY;QAEpB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAO;QACT,CAAC;QAGD,KAAK,MAAM,CAAC,IAAI,EAAE,sBAAsB,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YAE3E,IACE,CAAC,sBAAsB;gBACvB,CAAC,OAAO,sBAAsB,KAAK,QAAQ,IAAK,sBAAoD,CAAC,QAAQ,CAAC,EAC9G,CAAC;gBACD,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CAAC;QACrB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YAEX,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;YAChF,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC;gBAC1B,MAAM,CAAC,CAAC;YACV,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACnB,CAAC;QACH,CAAC;QAGD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IAClF,CAAC;IAKS,iBAAiB;QACzB,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,OAAO;QACT,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,OAAO,CAAC,IAAI,CACV,sGAAsG;YACpG,8CAA8C,CACjD,CAAC;IACJ,CAAC;CACF;AA5mBD,oCA4mBC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Logger, OnModuleDestroy } from '@nestjs/common';
|
|
2
|
+
import { PubSubEngine } from 'graphql-subscriptions';
|
|
3
|
+
import type { CoreRedisService } from './core-redis.service';
|
|
4
|
+
import type { Redis } from 'ioredis';
|
|
5
|
+
export declare class CoreRedisPubSub extends PubSubEngine implements OnModuleDestroy {
|
|
6
|
+
protected readonly redisService: CoreRedisService;
|
|
7
|
+
protected readonly logger: Logger;
|
|
8
|
+
protected readonly handlers: Map<string, Map<number, (...args: any[]) => void>>;
|
|
9
|
+
protected messageListener?: (channel: string, message: string) => void;
|
|
10
|
+
protected readonly subscriptions: Map<number, string>;
|
|
11
|
+
protected subIdCounter: number;
|
|
12
|
+
constructor(redisService: CoreRedisService);
|
|
13
|
+
publish(triggerName: string, payload: any): Promise<void>;
|
|
14
|
+
subscribe(triggerName: string, onMessage: (...args: any[]) => void): Promise<number>;
|
|
15
|
+
unsubscribe(subId: number): Promise<void>;
|
|
16
|
+
protected channel(triggerName: string): string;
|
|
17
|
+
protected dispatch(channel: string, message: string): void;
|
|
18
|
+
onModuleDestroy(): Promise<void>;
|
|
19
|
+
protected getSubscriber(): Redis;
|
|
20
|
+
}
|