@solidxai/core 0.1.6-beta.2 → 0.1.6-beta.21
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/dist/controllers/dashboard-layout.controller.d.ts +47 -0
- package/dist/controllers/dashboard-layout.controller.d.ts.map +1 -0
- package/dist/controllers/dashboard-layout.controller.js +204 -0
- package/dist/controllers/dashboard-layout.controller.js.map +1 -0
- package/dist/controllers/scheduled-job.controller.d.ts +1 -0
- package/dist/controllers/scheduled-job.controller.d.ts.map +1 -1
- package/dist/controllers/scheduled-job.controller.js +12 -0
- package/dist/controllers/scheduled-job.controller.js.map +1 -1
- package/dist/dtos/create-dashboard-layout.dto.d.ts +8 -0
- package/dist/dtos/create-dashboard-layout.dto.d.ts.map +1 -0
- package/dist/dtos/create-dashboard-layout.dto.js +53 -0
- package/dist/dtos/create-dashboard-layout.dto.js.map +1 -0
- package/dist/dtos/create-dashboard-variable.dto.d.ts +1 -0
- package/dist/dtos/create-dashboard-variable.dto.d.ts.map +1 -1
- package/dist/dtos/create-dashboard-variable.dto.js +7 -1
- package/dist/dtos/create-dashboard-variable.dto.js.map +1 -1
- package/dist/dtos/update-dashboard-layout.dto.d.ts +8 -0
- package/dist/dtos/update-dashboard-layout.dto.d.ts.map +1 -0
- package/dist/dtos/update-dashboard-layout.dto.js +53 -0
- package/dist/dtos/update-dashboard-layout.dto.js.map +1 -0
- package/dist/dtos/update-dashboard-variable.dto.d.ts +1 -0
- package/dist/dtos/update-dashboard-variable.dto.d.ts.map +1 -1
- package/dist/dtos/update-dashboard-variable.dto.js +7 -1
- package/dist/dtos/update-dashboard-variable.dto.js.map +1 -1
- package/dist/entities/action-metadata.entity.d.ts.map +1 -1
- package/dist/entities/action-metadata.entity.js.map +1 -1
- package/dist/entities/ai-interaction.entity.d.ts.map +1 -1
- package/dist/entities/ai-interaction.entity.js +5 -4
- package/dist/entities/ai-interaction.entity.js.map +1 -1
- package/dist/entities/chatter-message-details.entity.d.ts +1 -0
- package/dist/entities/chatter-message-details.entity.d.ts.map +1 -1
- package/dist/entities/chatter-message-details.entity.js +9 -4
- package/dist/entities/chatter-message-details.entity.js.map +1 -1
- package/dist/entities/chatter-message.entity.d.ts.map +1 -1
- package/dist/entities/chatter-message.entity.js +4 -3
- package/dist/entities/chatter-message.entity.js.map +1 -1
- package/dist/entities/common.entity.js +1 -1
- package/dist/entities/common.entity.js.map +1 -1
- package/dist/entities/dashboard-layout.entity.d.ts +9 -0
- package/dist/entities/dashboard-layout.entity.d.ts.map +1 -0
- package/dist/entities/dashboard-layout.entity.js +41 -0
- package/dist/entities/dashboard-layout.entity.js.map +1 -0
- package/dist/entities/dashboard-question-sql-dataset-config.entity.d.ts.map +1 -1
- package/dist/entities/dashboard-question-sql-dataset-config.entity.js +5 -4
- package/dist/entities/dashboard-question-sql-dataset-config.entity.js.map +1 -1
- package/dist/entities/dashboard-question.entity.d.ts.map +1 -1
- package/dist/entities/dashboard-question.entity.js +5 -4
- package/dist/entities/dashboard-question.entity.js.map +1 -1
- package/dist/entities/dashboard-variable.entity.d.ts +1 -0
- package/dist/entities/dashboard-variable.entity.d.ts.map +1 -1
- package/dist/entities/dashboard-variable.entity.js +10 -4
- package/dist/entities/dashboard-variable.entity.js.map +1 -1
- package/dist/entities/dashboard.entity.d.ts +2 -0
- package/dist/entities/dashboard.entity.d.ts.map +1 -1
- package/dist/entities/dashboard.entity.js +9 -3
- package/dist/entities/dashboard.entity.js.map +1 -1
- package/dist/entities/email-attachment.entity.d.ts.map +1 -1
- package/dist/entities/email-attachment.entity.js +2 -1
- package/dist/entities/email-attachment.entity.js.map +1 -1
- package/dist/entities/email-template.entity.js +1 -1
- package/dist/entities/email-template.entity.js.map +1 -1
- package/dist/entities/export-transaction.entity.d.ts.map +1 -1
- package/dist/entities/export-transaction.entity.js +2 -1
- package/dist/entities/export-transaction.entity.js.map +1 -1
- package/dist/entities/field-metadata.entity.js +2 -2
- package/dist/entities/field-metadata.entity.js.map +1 -1
- package/dist/entities/import-transaction-error-log.entity.d.ts.map +1 -1
- package/dist/entities/import-transaction-error-log.entity.js +3 -2
- package/dist/entities/import-transaction-error-log.entity.js.map +1 -1
- package/dist/entities/import-transaction.entity.d.ts.map +1 -1
- package/dist/entities/import-transaction.entity.js +2 -1
- package/dist/entities/import-transaction.entity.js.map +1 -1
- package/dist/entities/legacy-common.entity.d.ts.map +1 -1
- package/dist/entities/legacy-common.entity.js +1 -1
- package/dist/entities/legacy-common.entity.js.map +1 -1
- package/dist/entities/mq-message.entity.d.ts.map +1 -1
- package/dist/entities/mq-message.entity.js +5 -3
- package/dist/entities/mq-message.entity.js.map +1 -1
- package/dist/entities/saved-filters.entity.d.ts.map +1 -1
- package/dist/entities/saved-filters.entity.js +3 -2
- package/dist/entities/saved-filters.entity.js.map +1 -1
- package/dist/entities/security-rule.entity.d.ts.map +1 -1
- package/dist/entities/security-rule.entity.js +2 -1
- package/dist/entities/security-rule.entity.js.map +1 -1
- package/dist/entities/sms-template.entity.js +1 -1
- package/dist/entities/sms-template.entity.js.map +1 -1
- package/dist/entities/user-view-metadata.entity.d.ts.map +1 -1
- package/dist/entities/user-view-metadata.entity.js +2 -1
- package/dist/entities/user-view-metadata.entity.js.map +1 -1
- package/dist/entities/user.entity.d.ts.map +1 -1
- package/dist/entities/user.entity.js +2 -0
- package/dist/entities/user.entity.js.map +1 -1
- package/dist/entities/view-metadata.entity.d.ts.map +1 -1
- package/dist/entities/view-metadata.entity.js.map +1 -1
- package/dist/helpers/bootstrap.helper.d.ts +14 -0
- package/dist/helpers/bootstrap.helper.d.ts.map +1 -0
- package/dist/helpers/bootstrap.helper.js +132 -0
- package/dist/helpers/bootstrap.helper.js.map +1 -0
- package/dist/helpers/cache.helper.d.ts +2 -0
- package/dist/helpers/cache.helper.d.ts.map +1 -0
- package/dist/helpers/cache.helper.js +8 -0
- package/dist/helpers/cache.helper.js.map +1 -0
- package/dist/helpers/field-crud-managers/MediaFieldCrudManager.d.ts +1 -0
- package/dist/helpers/field-crud-managers/MediaFieldCrudManager.d.ts.map +1 -1
- package/dist/helpers/field-crud-managers/MediaFieldCrudManager.js +8 -9
- package/dist/helpers/field-crud-managers/MediaFieldCrudManager.js.map +1 -1
- package/dist/helpers/field-crud-managers/SelectionDynamicFieldCrudManager.d.ts +2 -2
- package/dist/helpers/field-crud-managers/SelectionDynamicFieldCrudManager.d.ts.map +1 -1
- package/dist/helpers/field-crud-managers/SelectionDynamicFieldCrudManager.js +8 -5
- package/dist/helpers/field-crud-managers/SelectionDynamicFieldCrudManager.js.map +1 -1
- package/dist/helpers/solid-registry.d.ts.map +1 -1
- package/dist/helpers/solid-registry.js.map +1 -1
- package/dist/helpers/typeorm-db-helper.d.ts.map +1 -1
- package/dist/helpers/typeorm-db-helper.js +21 -0
- package/dist/helpers/typeorm-db-helper.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +5 -1
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/jobs/computed-field-evaluation-queue-options.d.ts +1 -0
- package/dist/jobs/computed-field-evaluation-queue-options.d.ts.map +1 -1
- package/dist/jobs/computed-field-evaluation-queue-options.js +1 -0
- package/dist/jobs/computed-field-evaluation-queue-options.js.map +1 -1
- package/dist/repository/dashboard-layout.repository.d.ts +12 -0
- package/dist/repository/dashboard-layout.repository.d.ts.map +1 -0
- package/dist/repository/dashboard-layout.repository.js +34 -0
- package/dist/repository/dashboard-layout.repository.js.map +1 -0
- package/dist/seeders/module-metadata-seeder.service.js +4 -4
- package/dist/seeders/module-metadata-seeder.service.js.map +1 -1
- package/dist/seeders/seed-data/solid-core-metadata.json +445 -35
- package/dist/services/authentication.service.d.ts.map +1 -1
- package/dist/services/authentication.service.js +44 -21
- package/dist/services/authentication.service.js.map +1 -1
- package/dist/services/chatter-message.service.d.ts +0 -1
- package/dist/services/chatter-message.service.d.ts.map +1 -1
- package/dist/services/chatter-message.service.js +22 -19
- package/dist/services/chatter-message.service.js.map +1 -1
- package/dist/services/computed-fields/entity/sequence-num-computed-field-provider.d.ts +7 -3
- package/dist/services/computed-fields/entity/sequence-num-computed-field-provider.d.ts.map +1 -1
- package/dist/services/computed-fields/entity/sequence-num-computed-field-provider.js +61 -22
- package/dist/services/computed-fields/entity/sequence-num-computed-field-provider.js.map +1 -1
- package/dist/services/crud.service.js +1 -1
- package/dist/services/crud.service.js.map +1 -1
- package/dist/services/dashboard-layout.service.d.ts +20 -0
- package/dist/services/dashboard-layout.service.d.ts.map +1 -0
- package/dist/services/dashboard-layout.service.js +120 -0
- package/dist/services/dashboard-layout.service.js.map +1 -0
- package/dist/services/dashboard-question.service.d.ts +4 -0
- package/dist/services/dashboard-question.service.d.ts.map +1 -1
- package/dist/services/dashboard-question.service.js +22 -8
- package/dist/services/dashboard-question.service.js.map +1 -1
- package/dist/services/dashboard.service.d.ts +2 -0
- package/dist/services/dashboard.service.d.ts.map +1 -1
- package/dist/services/dashboard.service.js +4 -0
- package/dist/services/dashboard.service.js.map +1 -1
- package/dist/services/model-metadata.service.d.ts +6 -1
- package/dist/services/model-metadata.service.d.ts.map +1 -1
- package/dist/services/model-metadata.service.js +151 -8
- package/dist/services/model-metadata.service.js.map +1 -1
- package/dist/services/permission-metadata.service.d.ts +5 -1
- package/dist/services/permission-metadata.service.d.ts.map +1 -1
- package/dist/services/permission-metadata.service.js +66 -20
- package/dist/services/permission-metadata.service.js.map +1 -1
- package/dist/services/question-data-providers/chartjs-sql-data-provider.service.d.ts +2 -4
- package/dist/services/question-data-providers/chartjs-sql-data-provider.service.d.ts.map +1 -1
- package/dist/services/question-data-providers/chartjs-sql-data-provider.service.js +2 -1
- package/dist/services/question-data-providers/chartjs-sql-data-provider.service.js.map +1 -1
- package/dist/services/question-data-providers/interfaces.d.ts +1 -0
- package/dist/services/question-data-providers/interfaces.d.ts.map +1 -0
- package/dist/services/question-data-providers/interfaces.js +1 -0
- package/dist/services/question-data-providers/interfaces.js.map +1 -0
- package/dist/services/question-data-providers/prime-react-datatable-sql-data-provider.service.d.ts +2 -5
- package/dist/services/question-data-providers/prime-react-datatable-sql-data-provider.service.d.ts.map +1 -1
- package/dist/services/question-data-providers/prime-react-datatable-sql-data-provider.service.js +2 -1
- package/dist/services/question-data-providers/prime-react-datatable-sql-data-provider.service.js.map +1 -1
- package/dist/services/question-data-providers/prime-react-meter-group-sql-data-provider.service.d.ts +2 -5
- package/dist/services/question-data-providers/prime-react-meter-group-sql-data-provider.service.d.ts.map +1 -1
- package/dist/services/question-data-providers/prime-react-meter-group-sql-data-provider.service.js +2 -1
- package/dist/services/question-data-providers/prime-react-meter-group-sql-data-provider.service.js.map +1 -1
- package/dist/services/queues/database-subscriber.service.d.ts +4 -2
- package/dist/services/queues/database-subscriber.service.d.ts.map +1 -1
- package/dist/services/queues/database-subscriber.service.js +15 -2
- package/dist/services/queues/database-subscriber.service.js.map +1 -1
- package/dist/services/queues/publisher-factory.service.d.ts.map +1 -1
- package/dist/services/queues/publisher-factory.service.js +4 -6
- package/dist/services/queues/publisher-factory.service.js.map +1 -1
- package/dist/services/queues/rabbitmq-subscriber.service.d.ts +8 -3
- package/dist/services/queues/rabbitmq-subscriber.service.d.ts.map +1 -1
- package/dist/services/queues/rabbitmq-subscriber.service.js +78 -6
- package/dist/services/queues/rabbitmq-subscriber.service.js.map +1 -1
- package/dist/services/scheduled-job.service.d.ts +6 -1
- package/dist/services/scheduled-job.service.d.ts.map +1 -1
- package/dist/services/scheduled-job.service.js +26 -2
- package/dist/services/scheduled-job.service.js.map +1 -1
- package/dist/services/scheduled-jobs/scheduler.interface.d.ts +2 -0
- package/dist/services/scheduled-jobs/scheduler.interface.d.ts.map +1 -1
- package/dist/services/scheduled-jobs/scheduler.interface.js.map +1 -1
- package/dist/services/scheduled-jobs/scheduler.service.d.ts +6 -2
- package/dist/services/scheduled-jobs/scheduler.service.d.ts.map +1 -1
- package/dist/services/scheduled-jobs/scheduler.service.js +75 -17
- package/dist/services/scheduled-jobs/scheduler.service.js.map +1 -1
- package/dist/services/selection-providers/list-of-dashboard-question-providers-selection-provider.service.d.ts.map +1 -1
- package/dist/services/selection-providers/list-of-dashboard-question-providers-selection-provider.service.js +4 -1
- package/dist/services/selection-providers/list-of-dashboard-question-providers-selection-provider.service.js.map +1 -1
- package/dist/services/solid-ts-morph.service.d.ts +9 -0
- package/dist/services/solid-ts-morph.service.d.ts.map +1 -1
- package/dist/services/solid-ts-morph.service.js +76 -0
- package/dist/services/solid-ts-morph.service.js.map +1 -1
- package/dist/solid-core.module.d.ts.map +1 -1
- package/dist/solid-core.module.js +8 -0
- package/dist/solid-core.module.js.map +1 -1
- package/dist/subscribers/computed-entity-field.subscriber.js +3 -1
- package/dist/subscribers/computed-entity-field.subscriber.js.map +1 -1
- package/dist/transformers/typeorm/local-date-time-transformer.d.ts +4 -4
- package/dist/transformers/typeorm/local-date-time-transformer.d.ts.map +1 -1
- package/dist/transformers/typeorm/local-date-time-transformer.js +25 -28
- package/dist/transformers/typeorm/local-date-time-transformer.js.map +1 -1
- package/dist-tests/api/authenticate.spec.js +119 -0
- package/dist-tests/api/authenticate.spec.js.map +1 -0
- package/dist-tests/api/crud-service.findOne.cityMaster.spec.js +97 -0
- package/dist-tests/api/crud-service.findOne.cityMaster.spec.js.map +1 -0
- package/dist-tests/api/ping.spec.js +21 -0
- package/dist-tests/api/ping.spec.js.map +1 -0
- package/dist-tests/helpers/auth.js +41 -0
- package/dist-tests/helpers/auth.js.map +1 -0
- package/dist-tests/helpers/env.js +11 -0
- package/dist-tests/helpers/env.js.map +1 -0
- package/package.json +3 -1
- package/sql/default/mariadb/proc_CleanupModelMetadata.sql +153 -0
- package/sql/default/mariadb/proc_CleanupModuleMetadata.sql +56 -0
- package/sql/default/mysql/proc_CleanupModelMetadata.sql +153 -0
- package/sql/default/mysql/proc_CleanupModuleMetadata.sql +56 -0
- package/src/controllers/dashboard-layout.controller.ts +106 -0
- package/src/controllers/scheduled-job.controller.ts +6 -0
- package/src/dtos/create-dashboard-layout.dto.ts +31 -0
- package/src/dtos/create-dashboard-variable.dto.ts +4 -0
- package/src/dtos/update-dashboard-layout.dto.ts +30 -0
- package/src/dtos/update-dashboard-variable.dto.ts +5 -1
- package/src/entities/action-metadata.entity.ts +3 -2
- package/src/entities/ai-interaction.entity.ts +5 -4
- package/src/entities/chatter-message-details.entity.ts +7 -3
- package/src/entities/chatter-message.entity.ts +4 -3
- package/src/entities/common.entity.ts +2 -2
- package/src/entities/dashboard-layout.entity.ts +18 -0
- package/src/entities/dashboard-question-sql-dataset-config.entity.ts +5 -4
- package/src/entities/dashboard-question.entity.ts +5 -4
- package/src/entities/dashboard-variable.entity.ts +9 -4
- package/src/entities/dashboard.entity.ts +7 -2
- package/src/entities/email-attachment.entity.ts +2 -1
- package/src/entities/email-template.entity.ts +1 -1
- package/src/entities/export-transaction.entity.ts +2 -1
- package/src/entities/field-metadata.entity.ts +2 -2
- package/src/entities/import-transaction-error-log.entity.ts +3 -2
- package/src/entities/import-transaction.entity.ts +2 -1
- package/src/entities/legacy-common.entity.ts +3 -4
- package/src/entities/mq-message.entity.ts +5 -3
- package/src/entities/saved-filters.entity.ts +3 -2
- package/src/entities/security-rule.entity.ts +2 -1
- package/src/entities/sms-template.entity.ts +1 -1
- package/src/entities/user-view-metadata.entity.ts +2 -1
- package/src/entities/user.entity.ts +37 -2
- package/src/entities/view-metadata.entity.ts +3 -0
- package/src/helpers/bootstrap.helper.ts +222 -0
- package/src/helpers/cache.helper.ts +5 -0
- package/src/helpers/field-crud-managers/MediaFieldCrudManager.ts +9 -9
- package/src/helpers/field-crud-managers/SelectionDynamicFieldCrudManager.ts +9 -6
- package/src/helpers/solid-registry.ts +1 -5
- package/src/helpers/typeorm-db-helper.ts +26 -0
- package/src/index.ts +3 -0
- package/src/interfaces.ts +9 -1
- package/src/jobs/computed-field-evaluation-queue-options.ts +1 -0
- package/src/repository/dashboard-layout.repository.ts +17 -0
- package/src/seeders/module-metadata-seeder.service.ts +5 -5
- package/src/seeders/seed-data/solid-core-metadata.json +446 -36
- package/src/services/authentication.service.ts +46 -24
- package/src/services/chatter-message.service.ts +21 -21
- package/src/services/computed-fields/entity/sequence-num-computed-field-provider.ts +79 -40
- package/src/services/crud.service.ts +1 -1
- package/src/services/dashboard-layout.service.ts +111 -0
- package/src/services/dashboard-question.service.ts +23 -4
- package/src/services/dashboard.service.ts +7 -0
- package/src/services/model-metadata.service.ts +173 -50
- package/src/services/permission-metadata.service.ts +73 -20
- package/src/services/question-data-providers/chartjs-sql-data-provider.service.ts +3 -7
- package/src/services/question-data-providers/interfaces.ts +0 -0
- package/src/services/question-data-providers/prime-react-datatable-sql-data-provider.service.ts +4 -8
- package/src/services/question-data-providers/prime-react-meter-group-sql-data-provider.service.ts +4 -8
- package/src/services/queues/database-subscriber.service.ts +19 -2
- package/src/services/queues/publisher-factory.service.ts +8 -6
- package/src/services/queues/rabbitmq-subscriber.service.ts +123 -6
- package/src/services/scheduled-job.service.ts +31 -2
- package/src/services/scheduled-jobs/scheduler.interface.ts +4 -1
- package/src/services/scheduled-jobs/scheduler.service.ts +82 -20
- package/src/services/selection-providers/list-of-dashboard-question-providers-selection-provider.service.ts +4 -1
- package/src/services/solid-ts-morph.service.ts +98 -0
- package/src/solid-core.module.ts +13 -0
- package/src/subscribers/computed-entity-field.subscriber.ts +3 -3
- package/src/transformers/typeorm/local-date-time-transformer.ts +41 -33
- package/.claude/settings.local.json +0 -15
- package/src/services/1.js +0 -6
|
@@ -37,11 +37,19 @@ exports.RabbitMqSubscriber = void 0;
|
|
|
37
37
|
const common_1 = require("@nestjs/common");
|
|
38
38
|
const amqp = __importStar(require("amqplib"));
|
|
39
39
|
const common_2 = require("./common");
|
|
40
|
+
class ConsumerProcessingTimeoutError extends Error {
|
|
41
|
+
constructor(queueName, messageId, timeoutMs) {
|
|
42
|
+
super(`Subscriber processing timed out after ${timeoutMs}ms for queue ${queueName} and messageId ${messageId}`);
|
|
43
|
+
this.queueName = queueName;
|
|
44
|
+
this.messageId = messageId;
|
|
45
|
+
this.timeoutMs = timeoutMs;
|
|
46
|
+
this.name = 'ConsumerProcessingTimeoutError';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
40
49
|
class RabbitMqSubscriber {
|
|
41
50
|
constructor(mqMessageService, mqMessageQueueService) {
|
|
42
51
|
this.mqMessageService = mqMessageService;
|
|
43
52
|
this.mqMessageQueueService = mqMessageQueueService;
|
|
44
|
-
this.logger = new common_1.Logger(RabbitMqSubscriber.name);
|
|
45
53
|
this.connection = null;
|
|
46
54
|
this.channel = null;
|
|
47
55
|
this.consumerTag = null;
|
|
@@ -57,6 +65,15 @@ class RabbitMqSubscriber {
|
|
|
57
65
|
this.logger.debug('Queue service Role is not defined in the environment variables');
|
|
58
66
|
}
|
|
59
67
|
}
|
|
68
|
+
get loggerContext() {
|
|
69
|
+
return this.constructor.name;
|
|
70
|
+
}
|
|
71
|
+
get logger() {
|
|
72
|
+
if (!this._loggerInstance) {
|
|
73
|
+
this._loggerInstance = new common_1.Logger(this.loggerContext);
|
|
74
|
+
}
|
|
75
|
+
return this._loggerInstance;
|
|
76
|
+
}
|
|
60
77
|
async establishConnection() {
|
|
61
78
|
const url = new URL(this.url);
|
|
62
79
|
const connection = await amqp.connect({
|
|
@@ -74,7 +91,12 @@ class RabbitMqSubscriber {
|
|
|
74
91
|
const defaultBroker = process.env.QUEUES_DEFAULT_BROKER || 'rabbitmq';
|
|
75
92
|
const solidCliRunning = process.env.SOLID_CLI_RUNNING || "false";
|
|
76
93
|
const queueNameRegex = (process.env.QUEUES_QUEUE_NAME_REGEX_TO_ENABLE || '').trim();
|
|
77
|
-
|
|
94
|
+
const roleAllowed = ['both', 'subscriber'].includes(this.serviceRole);
|
|
95
|
+
if (!roleAllowed) {
|
|
96
|
+
this.logger.log(`RabbitMqSubscriber is disabled because QUEUES_SERVICE_ROLE is "${this.serviceRole}". Expected "both" or "subscriber".`);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (this.url && solidCliRunning === "false" && defaultBroker === 'rabbitmq') {
|
|
78
100
|
const options = this.options();
|
|
79
101
|
const queueName = options.queueName;
|
|
80
102
|
if (queueNameRegex && queueNameRegex !== "all") {
|
|
@@ -109,6 +131,10 @@ class RabbitMqSubscriber {
|
|
|
109
131
|
if (prefetch < 1) {
|
|
110
132
|
throw new Error(`RabbitMqSubscriber prefetch must be >= 1 for queue ${queueName}`);
|
|
111
133
|
}
|
|
134
|
+
const processingTimeoutMs = this.resolveProcessingTimeoutMs();
|
|
135
|
+
if (processingTimeoutMs > 0) {
|
|
136
|
+
this.logger.log(`RabbitMqSubscriber using processing timeout ${processingTimeoutMs}ms for queue ${queueName}`);
|
|
137
|
+
}
|
|
112
138
|
let connection;
|
|
113
139
|
try {
|
|
114
140
|
connection = await this.establishConnection();
|
|
@@ -180,7 +206,7 @@ class RabbitMqSubscriber {
|
|
|
180
206
|
if (!message.currentRetry)
|
|
181
207
|
message.currentRetry = 0;
|
|
182
208
|
try {
|
|
183
|
-
await this.processMessage(message, rawMessage, channel);
|
|
209
|
+
await this.processMessage(message, rawMessage, channel, queueName);
|
|
184
210
|
}
|
|
185
211
|
catch (error) {
|
|
186
212
|
await this.handleProcessingError(message, rawMessage, channel, error, queueName);
|
|
@@ -190,7 +216,7 @@ class RabbitMqSubscriber {
|
|
|
190
216
|
}
|
|
191
217
|
async handleProcessingError(message, rawMessage, channel, error, queueName) {
|
|
192
218
|
const errorMessage = error?.message || String(error);
|
|
193
|
-
this.logger.error(`Error processing message on queue ${queueName}: ${errorMessage}
|
|
219
|
+
this.logger.error(`Error processing message on queue ${queueName}: ${errorMessage}`, error?.stack);
|
|
194
220
|
if (message.currentRetry < message.retryCount) {
|
|
195
221
|
await this.updateStatusInDatabase('retrying', message);
|
|
196
222
|
message.currentRetry++;
|
|
@@ -290,9 +316,9 @@ class RabbitMqSubscriber {
|
|
|
290
316
|
const jitter = Math.floor(Math.random() * (exp * 0.2));
|
|
291
317
|
return Math.min(maxMs, exp + jitter);
|
|
292
318
|
}
|
|
293
|
-
async processMessage(message, rawMessage, channel) {
|
|
319
|
+
async processMessage(message, rawMessage, channel, queueName) {
|
|
294
320
|
await this.updateStatusInDatabase('started', message);
|
|
295
|
-
const result = await this.
|
|
321
|
+
const result = await this.subscribeWithTimeout(message, queueName);
|
|
296
322
|
channel.ack(rawMessage);
|
|
297
323
|
await this.updateStatusInDatabase('succeeded', message, '', result ? JSON.stringify(result, null, 2) : '');
|
|
298
324
|
}
|
|
@@ -324,6 +350,52 @@ class RabbitMqSubscriber {
|
|
|
324
350
|
this.logger.error(error.message, error.stack);
|
|
325
351
|
}
|
|
326
352
|
}
|
|
353
|
+
resolveProcessingTimeoutMs() {
|
|
354
|
+
const brokerTimeoutMs = this.parsePositiveInt(process.env.QUEUES_RABBITMQ_CONSUMER_ACK_TIMEOUT_MS, 30 * 60 * 1000);
|
|
355
|
+
const defaultSoftTimeoutMs = Math.max(1_000, brokerTimeoutMs - 30_000);
|
|
356
|
+
return this.parsePositiveInt(process.env.QUEUES_RABBITMQ_SUBSCRIBER_PROCESSING_TIMEOUT_MS, defaultSoftTimeoutMs);
|
|
357
|
+
}
|
|
358
|
+
parsePositiveInt(value, fallback) {
|
|
359
|
+
if (!value)
|
|
360
|
+
return fallback;
|
|
361
|
+
const parsed = Number.parseInt(value, 10);
|
|
362
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
363
|
+
}
|
|
364
|
+
async subscribeWithTimeout(message, queueName) {
|
|
365
|
+
const timeoutMs = this.resolveProcessingTimeoutMs();
|
|
366
|
+
const messageId = message?.messageId || 'unknown';
|
|
367
|
+
if (timeoutMs <= 0) {
|
|
368
|
+
return this.subscribe(message);
|
|
369
|
+
}
|
|
370
|
+
let timedOut = false;
|
|
371
|
+
let timeoutHandle = null;
|
|
372
|
+
const subscribePromise = this.subscribe(message).catch((error) => {
|
|
373
|
+
if (timedOut) {
|
|
374
|
+
this.logger.error(`Subscriber promise rejected after timeout for queue ${queueName} and messageId ${messageId}: ${error?.message || String(error)}`, error?.stack);
|
|
375
|
+
return undefined;
|
|
376
|
+
}
|
|
377
|
+
throw error;
|
|
378
|
+
});
|
|
379
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
380
|
+
timeoutHandle = setTimeout(() => {
|
|
381
|
+
timedOut = true;
|
|
382
|
+
reject(new ConsumerProcessingTimeoutError(queueName, messageId, timeoutMs));
|
|
383
|
+
}, timeoutMs);
|
|
384
|
+
});
|
|
385
|
+
try {
|
|
386
|
+
return await Promise.race([subscribePromise, timeoutPromise]);
|
|
387
|
+
}
|
|
388
|
+
catch (error) {
|
|
389
|
+
const errorMessage = error?.message || String(error);
|
|
390
|
+
this.logger.error(`Subscriber execution failed for queue ${queueName} and messageId ${messageId}: ${errorMessage}`, error?.stack);
|
|
391
|
+
throw error;
|
|
392
|
+
}
|
|
393
|
+
finally {
|
|
394
|
+
if (timeoutHandle) {
|
|
395
|
+
clearTimeout(timeoutHandle);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
327
399
|
}
|
|
328
400
|
exports.RabbitMqSubscriber = RabbitMqSubscriber;
|
|
329
401
|
//# sourceMappingURL=rabbitmq-subscriber.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rabbitmq-subscriber.service.js","sourceRoot":"","sources":["../../../src/services/queues/rabbitmq-subscriber.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAsD;AACtD,8CAAgC;AAKhC,qCAAoD;AAGpD,MAAsB,kBAAkB;IAWpC,YAA+B,gBAAkC,EAAqB,qBAA4C;QAAnG,qBAAgB,GAAhB,gBAAgB,CAAkB;QAAqB,0BAAqB,GAArB,qBAAqB,CAAuB;QAVjH,WAAM,GAAG,IAAI,eAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAGtD,eAAU,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,WAAW,EAAE,CAAC;oBACxB,aAAa,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC;gBACrC,CAAC;gBACD,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;oBACrB,aAAa,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC;gBACnC,CAAC;gBACD,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC;YACzE,CAAC;QACL,CAAC;QACD,OAAO,KAAK,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAClD,CAAC;IAEL,CAAC;CAEJ;AA3WD,gDA2WC","sourcesContent":["import { Logger, OnModuleInit } from '@nestjs/common';\nimport * as amqp from 'amqplib';\nimport { QueuesModuleOptions } from \"../../interfaces\";\nimport { QueueMessage, QueueSubscriber } from '../../interfaces/mq';\nimport { MqMessageQueueService } from '../mq-message-queue.service';\nimport { MqMessageService } from '../mq-message.service';\nimport { buildNamespacedQueueName } from './common';\n\n\nexport abstract class RabbitMqSubscriber<T> implements OnModuleInit, QueueSubscriber<T> { // TODO This can be made a generic type for better type visibility\n private readonly logger = new Logger(RabbitMqSubscriber.name);\n private readonly url: string;\n private readonly serviceRole: string;\n private connection: amqp.Connection | null = null;\n private channel: amqp.Channel | null = null;\n private consumerTag: string | null = null;\n private reconnectPromise: Promise<void> | null = null;\n private reconnectAttempt = 0;\n private stopping = false;\n\n constructor(protected readonly mqMessageService: MqMessageService, protected readonly mqMessageQueueService: MqMessageQueueService) {\n this.url = process.env.QUEUES_RABBIT_MQ_URL;\n this.serviceRole = process.env.QUEUES_SERVICE_ROLE;\n if (!this.url) {\n this.logger.debug('RabbitMqPublisher url is not defined in the environment variables');\n }\n if (!this.serviceRole) {\n this.logger.debug('Queue service Role is not defined in the environment variables');\n }\n // this.logger.debug(`RabbitMqSubscriber instance created with options: ${JSON.stringify(this.options())} and url: ${this.url}`);\n }\n\n abstract subscribe(message: QueueMessage<T>);\n\n abstract options(): QueuesModuleOptions;\n\n async establishConnection(): Promise<amqp.Connection> {\n\n const url = new URL(this.url);\n\n // this.logger.debug(`user: ${url.username}`);\n // // just for local debug, don’t log in prod\n // this.logger.debug(`pass: ${url.password}`);\n // this.logger.debug(`path (vhost): ${url.pathname}`);\n\n const connection = await amqp.connect({\n protocol: url.protocol.replace(':', ''),\n hostname: url.hostname,\n port: parseInt(url.port),\n username: url.username,\n password: decodeURIComponent(url.password),\n frameMax: 131072,\n heartbeat: 30,\n });\n\n return connection\n }\n\n async onModuleInit(): Promise<void> {\n // Not using SettingService here as that will necessitate all implementors of RabbitMqSubscriber to also inject SettingService which is not ideal. \n // Instead we directly read the environment variables here.\n const defaultBroker = process.env.QUEUES_DEFAULT_BROKER || 'rabbitmq';\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n const queueNameRegex = (process.env.QUEUES_QUEUE_NAME_REGEX_TO_ENABLE || '').trim();\n\n // we will start subscriber only if the current service role is subscriber. \n if (this.url && ['both', 'subscriber'].includes(this.serviceRole) && solidCliRunning === \"false\" && defaultBroker === 'rabbitmq') {\n const options = this.options();\n const queueName = options.queueName;\n\n if (queueNameRegex && queueNameRegex !== \"all\") {\n try {\n const regex = new RegExp(queueNameRegex);\n if (!regex.test(queueName)) {\n this.logger.log(`RabbitMqSubscriber for queue ${queueName} is disabled because it does not match QUEUES_QUEUE_NAME_REGEX_TO_ENABLE=${queueNameRegex}`);\n return;\n }\n } catch (error) {\n this.logger.error(`Invalid QUEUES_QUEUE_NAME_REGEX_TO_ENABLE regex \"${queueNameRegex}\". Subscriber for queue ${queueName} will not start.`);\n return;\n }\n }\n\n const namespacedQueueName = buildNamespacedQueueName(queueName);\n try {\n await this.connectAndConsume(namespacedQueueName);\n } catch (err) {\n this.logger.error(`Failed to connect to RabbitMQ for queue ${namespacedQueueName}: ${(err as Error).message}`, (err as Error).stack);\n this.triggerReconnect(namespacedQueueName, 'initial connection failure');\n }\n\n this.logger.log(`RabbitMqSubscriber ready to consume messages: ${JSON.stringify(options)} and url: ${this.url}`);\n }\n }\n\n private async connectAndConsume(queueName: string): Promise<void> {\n await this.cleanup();\n this.logger.log(`RabbitMqSubscriber in connectAndConsume for queue: ${queueName} and url: ${this.url}`);\n\n const options = this.options();\n const prefetch = options.prefetch ?? 1;\n if (prefetch < 1) {\n throw new Error(`RabbitMqSubscriber prefetch must be >= 1 for queue ${queueName}`);\n }\n\n let connection: amqp.Connection;\n try {\n connection = await this.establishConnection();\n } catch (err) {\n this.logger.error(`Failed to connect to RabbitMQ for queue ${queueName}: ${(err as Error).message}`, (err as Error).stack);\n throw err;\n }\n\n this.connection = connection;\n\n connection.on('error', (err) => {\n if (connection !== this.connection) return;\n this.logger.error(`RabbitMqSubscriber connection error for queue ${queueName}: ${(err as Error).message}`);\n });\n\n connection.on('close', () => {\n if (connection !== this.connection) return;\n this.logger.warn(`RabbitMqSubscriber connection closed for queue ${queueName}`);\n this.triggerReconnect(queueName, 'connection closed');\n });\n\n const channel = await connection.createChannel();\n this.channel = channel;\n\n channel.on('error', (err) => {\n if (channel !== this.channel) return;\n this.logger.error(`RabbitMqSubscriber channel error for queue ${queueName}: ${(err as Error).message}`);\n });\n\n channel.on('close', () => {\n if (channel !== this.channel) return;\n this.logger.warn(`RabbitMqSubscriber channel closed for queue ${queueName}`);\n this.triggerReconnect(queueName, 'channel closed');\n });\n\n // Process one message at a time per consumer to avoid parallel work on the same subscriber instance.\n await channel.prefetch(prefetch);\n\n // Use a direct exchange with a stable routing key so retry DLX can route back to the main queue.\n const exchangeName = `${queueName}.exchange`;\n const routingKey = `${queueName}.routing-key`;\n const retryQueue = `${queueName}.retry`;\n const failedQueue = `${queueName}.failed`;\n\n await channel.assertExchange(exchangeName, 'direct', {});\n await channel.assertQueue(queueName, {});\n await channel.bindQueue(queueName, exchangeName, routingKey);\n\n // Retry queue uses DLX to route expired messages back to the main exchange/routing key.\n await channel.assertQueue(retryQueue, {\n arguments: {\n 'x-dead-letter-exchange': exchangeName,\n 'x-dead-letter-routing-key': routingKey,\n }\n });\n\n await channel.assertQueue(failedQueue, {});\n\n const consumeResult = await channel.consume(\n queueName,\n async (rawMessage) => {\n if (!rawMessage) {\n return;\n }\n\n let message: QueueMessage<T> = null;\n\n try {\n const messageContentString = rawMessage.content.toString();\n message = JSON.parse(messageContentString) as QueueMessage<T>;\n this.logger.debug(`rabbitmq subscriber received message with id: ${message.messageId} for queue ${queueName}`);\n } catch (error) {\n this.logger.error(`Invalid JSON message on queue ${queueName}: ${(error as Error).message}`);\n await this.publishToFailedQueue(queueName, rawMessage.content, channel, error);\n channel.ack(rawMessage);\n return;\n }\n\n if (!message.retryCount) message.retryCount = 0;\n if (!message.retryInterval) message.retryInterval = 1000;\n if (!message.currentRetry) message.currentRetry = 0;\n\n try {\n await this.processMessage(message, rawMessage, channel);\n } catch (error) {\n await this.handleProcessingError(message, rawMessage, channel, error, queueName);\n }\n },\n // Explicit ack enables reliable processing and retry routing.\n { noAck: false },\n );\n\n this.consumerTag = consumeResult.consumerTag;\n }\n\n // Retry flow: update DB -> increment retry -> send to retry queue with per-message expiration -> ack original.\n private async handleProcessingError(message: QueueMessage<T>, rawMessage: amqp.ConsumeMessage, channel: amqp.Channel, error: any, queueName: string): Promise<void> {\n const errorMessage = (error as Error)?.message || String(error);\n this.logger.error(`Error processing message on queue ${queueName}: ${errorMessage}`);\n\n if (message.currentRetry < message.retryCount) {\n await this.updateStatusInDatabase('retrying', message);\n\n message.currentRetry++;\n const retryQueue = `${queueName}.retry`;\n const payload = Buffer.from(JSON.stringify(message));\n\n // Per-message expiration keeps the message in the retry queue until TTL, then DLX routes it back.\n channel.sendToQueue(retryQueue, payload, {\n expiration: String(message.retryInterval || 1000),\n headers: {\n 'x-error': errorMessage,\n }\n });\n\n channel.ack(rawMessage);\n this.logger.warn(`Retrying message (${message.currentRetry}/${message.retryCount}) after ${message.retryInterval}ms on queue ${queueName}`);\n return;\n }\n\n await this.updateStatusInDatabase('failed', message, errorMessage, '');\n channel.ack(rawMessage);\n await this.publishToFailedQueue(queueName, Buffer.from(JSON.stringify(message)), channel, error);\n this.logger.error(`Message failed after ${message.retryCount} attempts on queue ${queueName}: ${errorMessage}`);\n }\n\n private async publishToFailedQueue(queueName: string, payload: Buffer | string, channel: amqp.Channel, error?: any): Promise<void> {\n const failedQueue = `${queueName}.failed`;\n const body = Buffer.isBuffer(payload) ? payload : Buffer.from(payload);\n const errorMessage = (error as Error)?.message || String(error || '');\n\n try {\n channel.sendToQueue(failedQueue, body, errorMessage ? {\n headers: { 'x-error': errorMessage }\n } : undefined);\n } catch (err) {\n this.logger.error(`Failed to publish to failed queue ${failedQueue}: ${(err as Error).message}`);\n }\n }\n\n private triggerReconnect(queueName: string, reason: string) {\n if (this.stopping) return;\n if (this.reconnectPromise) return;\n\n this.reconnectPromise = this.reconnectLoop(queueName, reason)\n .finally(() => {\n this.reconnectPromise = null;\n });\n }\n\n // Reconnect with backoff to avoid hammering the broker during outages.\n private async reconnectLoop(queueName: string, reason: string): Promise<void> {\n this.logger.warn(`RabbitMqSubscriber reconnecting for queue ${queueName}: ${reason}`);\n\n while (!this.stopping) {\n try {\n await this.connectAndConsume(queueName);\n this.reconnectAttempt = 0;\n this.logger.log(`RabbitMqSubscriber reconnected for queue ${queueName}`);\n return;\n } catch (err) {\n this.reconnectAttempt += 1;\n const delay = this.backoff();\n this.logger.warn(`RabbitMqSubscriber reconnect failed for queue ${queueName}; retrying in ${delay}ms`);\n await this.sleep(delay);\n }\n }\n }\n\n private async cleanup(): Promise<void> {\n const channel = this.channel;\n const connection = this.connection;\n const consumerTag = this.consumerTag;\n\n this.channel = null;\n this.connection = null;\n this.consumerTag = null;\n\n if (channel) {\n try {\n if (consumerTag) {\n await channel.cancel(consumerTag);\n }\n } catch (_) {\n // ignore\n }\n\n try {\n await channel.close();\n } catch (_) {\n // ignore\n }\n }\n\n if (connection) {\n try {\n await connection.close();\n } catch (_) {\n // ignore\n }\n }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n }\n\n // Exponential backoff with jitter, capped to 30s.\n private backoff(): number {\n const baseMs = 1000;\n const maxMs = 30_000;\n const exp = Math.min(maxMs, baseMs * Math.pow(2, this.reconnectAttempt));\n const jitter = Math.floor(Math.random() * (exp * 0.2));\n return Math.min(maxMs, exp + jitter);\n }\n\n /**\n * Abstract method for message processing logic.\n */\n protected async processMessage(message: QueueMessage<T>, rawMessage, channel): Promise<void> {\n await this.updateStatusInDatabase('started', message);\n\n // Capture the results of handling the task.\n const result = await this.subscribe(message);\n\n // Ack the message. \n channel.ack(rawMessage);\n\n // Persist success output and timing.\n await this.updateStatusInDatabase('succeeded', message, '', result ? JSON.stringify(result, null, 2) : '');\n\n }\n\n private async updateStatusInDatabase(stage: string, message: QueueMessage<T>, error: string = '', result: string = '') {\n\n // Update the existing message record by messageId; creation happens upstream.\n try {\n // 1. resolve the queue first\n const mqMessage = await this.mqMessageService.repo.findOne({\n where: {\n messageId: message.messageId,\n }\n });\n\n if (mqMessage) {\n const updatedFields = {\n stage: stage\n };\n if (stage === 'failed' || stage === 'succeeded') {\n updatedFields['finishedAt'] = new Date();\n updatedFields['elapsedMillis'] = updatedFields['finishedAt'].getTime() - mqMessage.startedAt.getTime();\n }\n if (stage === 'succeeded') {\n updatedFields['output'] = result;\n }\n if (stage === 'failed') {\n updatedFields['error'] = error;\n }\n await this.mqMessageService.repo.update(mqMessage.id, updatedFields);\n }\n }\n catch (error) {\n this.logger.error(error.message, error.stack);\n }\n\n }\n\n}\n"]}
|
|
1
|
+
{"version":3,"file":"rabbitmq-subscriber.service.js","sourceRoot":"","sources":["../../../src/services/queues/rabbitmq-subscriber.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAsD;AACtD,8CAAgC;AAKhC,qCAAoD;AAEpD,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AAK,CAC1B,CAAC;YACF,MAAM,KAAK,CAAC;QAChB,CAAC;gBAAS,CAAC;YAEP,IAAI,aAAa,EAAE,CAAC;gBAChB,YAAY,CAAC,aAAa,CAAC,CAAC;YAChC,CAAC;QACL,CAAC;IACL,CAAC;CAEJ;AArdD,gDAqdC","sourcesContent":["import { Logger, OnModuleInit } from '@nestjs/common';\nimport * as amqp from 'amqplib';\nimport { QueuesModuleOptions } from \"../../interfaces\";\nimport { QueueMessage, QueueSubscriber } from '../../interfaces/mq';\nimport { MqMessageQueueService } from '../mq-message-queue.service';\nimport { MqMessageService } from '../mq-message.service';\nimport { buildNamespacedQueueName } from './common';\n\nclass ConsumerProcessingTimeoutError extends Error {\n constructor(\n readonly queueName: string,\n readonly messageId: string,\n readonly timeoutMs: number,\n ) {\n super(`Subscriber processing timed out after ${timeoutMs}ms for queue ${queueName} and messageId ${messageId}`);\n this.name = 'ConsumerProcessingTimeoutError';\n }\n}\n\n\nexport abstract class RabbitMqSubscriber<T> implements OnModuleInit, QueueSubscriber<T> { // TODO This can be made a generic type for better type visibility\n private _loggerInstance?: Logger;\n private readonly url: string;\n private readonly serviceRole: string;\n private connection: amqp.Connection | null = null;\n private channel: amqp.Channel | null = null;\n private consumerTag: string | null = null;\n private reconnectPromise: Promise<void> | null = null;\n private reconnectAttempt = 0;\n private stopping = false;\n\n constructor(protected readonly mqMessageService: MqMessageService, protected readonly mqMessageQueueService: MqMessageQueueService) {\n this.url = process.env.QUEUES_RABBIT_MQ_URL;\n this.serviceRole = process.env.QUEUES_SERVICE_ROLE;\n if (!this.url) {\n this.logger.debug('RabbitMqPublisher url is not defined in the environment variables');\n }\n if (!this.serviceRole) {\n this.logger.debug('Queue service Role is not defined in the environment variables');\n }\n // this.logger.debug(`RabbitMqSubscriber instance created with options: ${JSON.stringify(this.options())} and url: ${this.url}`);\n }\n\n protected get loggerContext(): string {\n return this.constructor.name;\n }\n\n protected get logger(): Logger {\n if (!this._loggerInstance) {\n this._loggerInstance = new Logger(this.loggerContext);\n }\n return this._loggerInstance;\n }\n\n abstract subscribe(message: QueueMessage<T>);\n\n abstract options(): QueuesModuleOptions;\n\n async establishConnection(): Promise<amqp.Connection> {\n\n const url = new URL(this.url);\n\n // this.logger.debug(`user: ${url.username}`);\n // // just for local debug, don’t log in prod\n // this.logger.debug(`pass: ${url.password}`);\n // this.logger.debug(`path (vhost): ${url.pathname}`);\n\n const connection = await amqp.connect({\n protocol: url.protocol.replace(':', ''),\n hostname: url.hostname,\n port: parseInt(url.port),\n username: url.username,\n password: decodeURIComponent(url.password),\n frameMax: 131072,\n heartbeat: 30,\n });\n\n return connection\n }\n\n async onModuleInit(): Promise<void> {\n // Not using SettingService here as that will necessitate all implementors of RabbitMqSubscriber to also inject SettingService which is not ideal. \n // Instead we directly read the environment variables here.\n const defaultBroker = process.env.QUEUES_DEFAULT_BROKER || 'rabbitmq';\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n const queueNameRegex = (process.env.QUEUES_QUEUE_NAME_REGEX_TO_ENABLE || '').trim();\n const roleAllowed = ['both', 'subscriber'].includes(this.serviceRole);\n\n if (!roleAllowed) {\n this.logger.log(`RabbitMqSubscriber is disabled because QUEUES_SERVICE_ROLE is \"${this.serviceRole}\". Expected \"both\" or \"subscriber\".`);\n return;\n }\n\n // we will start subscriber only if the current service role is subscriber. \n if (this.url && solidCliRunning === \"false\" && defaultBroker === 'rabbitmq') {\n const options = this.options();\n const queueName = options.queueName;\n\n if (queueNameRegex && queueNameRegex !== \"all\") {\n try {\n const regex = new RegExp(queueNameRegex);\n if (!regex.test(queueName)) {\n this.logger.log(`RabbitMqSubscriber for queue ${queueName} is disabled because it does not match QUEUES_QUEUE_NAME_REGEX_TO_ENABLE=${queueNameRegex}`);\n return;\n }\n } catch (error) {\n this.logger.error(`Invalid QUEUES_QUEUE_NAME_REGEX_TO_ENABLE regex \"${queueNameRegex}\". Subscriber for queue ${queueName} will not start.`);\n return;\n }\n }\n\n const namespacedQueueName = buildNamespacedQueueName(queueName);\n try {\n await this.connectAndConsume(namespacedQueueName);\n } catch (err) {\n this.logger.error(`Failed to connect to RabbitMQ for queue ${namespacedQueueName}: ${(err as Error).message}`, (err as Error).stack);\n this.triggerReconnect(namespacedQueueName, 'initial connection failure');\n }\n\n this.logger.log(`RabbitMqSubscriber ready to consume messages: ${JSON.stringify(options)} and url: ${this.url}`);\n }\n }\n\n private async connectAndConsume(queueName: string): Promise<void> {\n await this.cleanup();\n this.logger.log(`RabbitMqSubscriber in connectAndConsume for queue: ${queueName} and url: ${this.url}`);\n\n const options = this.options();\n const prefetch = options.prefetch ?? 1;\n if (prefetch < 1) {\n throw new Error(`RabbitMqSubscriber prefetch must be >= 1 for queue ${queueName}`);\n }\n const processingTimeoutMs = this.resolveProcessingTimeoutMs();\n if (processingTimeoutMs > 0) {\n this.logger.log(`RabbitMqSubscriber using processing timeout ${processingTimeoutMs}ms for queue ${queueName}`);\n }\n\n let connection: amqp.Connection;\n try {\n connection = await this.establishConnection();\n } catch (err) {\n this.logger.error(`Failed to connect to RabbitMQ for queue ${queueName}: ${(err as Error).message}`, (err as Error).stack);\n throw err;\n }\n\n this.connection = connection;\n\n connection.on('error', (err) => {\n if (connection !== this.connection) return;\n this.logger.error(`RabbitMqSubscriber connection error for queue ${queueName}: ${(err as Error).message}`);\n });\n\n connection.on('close', () => {\n if (connection !== this.connection) return;\n this.logger.warn(`RabbitMqSubscriber connection closed for queue ${queueName}`);\n this.triggerReconnect(queueName, 'connection closed');\n });\n\n const channel = await connection.createChannel();\n this.channel = channel;\n\n channel.on('error', (err) => {\n if (channel !== this.channel) return;\n this.logger.error(`RabbitMqSubscriber channel error for queue ${queueName}: ${(err as Error).message}`);\n });\n\n channel.on('close', () => {\n if (channel !== this.channel) return;\n this.logger.warn(`RabbitMqSubscriber channel closed for queue ${queueName}`);\n this.triggerReconnect(queueName, 'channel closed');\n });\n\n // Process one message at a time per consumer to avoid parallel work on the same subscriber instance.\n await channel.prefetch(prefetch);\n\n // Use a direct exchange with a stable routing key so retry DLX can route back to the main queue.\n const exchangeName = `${queueName}.exchange`;\n const routingKey = `${queueName}.routing-key`;\n const retryQueue = `${queueName}.retry`;\n const failedQueue = `${queueName}.failed`;\n\n await channel.assertExchange(exchangeName, 'direct', {});\n await channel.assertQueue(queueName, {});\n await channel.bindQueue(queueName, exchangeName, routingKey);\n\n // Retry queue uses DLX to route expired messages back to the main exchange/routing key.\n await channel.assertQueue(retryQueue, {\n arguments: {\n 'x-dead-letter-exchange': exchangeName,\n 'x-dead-letter-routing-key': routingKey,\n }\n });\n\n await channel.assertQueue(failedQueue, {});\n\n const consumeResult = await channel.consume(\n queueName,\n async (rawMessage) => {\n if (!rawMessage) {\n return;\n }\n\n let message: QueueMessage<T> = null;\n\n try {\n const messageContentString = rawMessage.content.toString();\n message = JSON.parse(messageContentString) as QueueMessage<T>;\n this.logger.debug(`rabbitmq subscriber received message with id: ${message.messageId} for queue ${queueName}`);\n } catch (error) {\n this.logger.error(`Invalid JSON message on queue ${queueName}: ${(error as Error).message}`);\n await this.publishToFailedQueue(queueName, rawMessage.content, channel, error);\n channel.ack(rawMessage);\n return;\n }\n\n if (!message.retryCount) message.retryCount = 0;\n if (!message.retryInterval) message.retryInterval = 1000;\n if (!message.currentRetry) message.currentRetry = 0;\n\n try {\n await this.processMessage(message, rawMessage, channel, queueName);\n } catch (error) {\n await this.handleProcessingError(message, rawMessage, channel, error, queueName);\n }\n },\n // Explicit ack enables reliable processing and retry routing.\n { noAck: false },\n );\n\n this.consumerTag = consumeResult.consumerTag;\n }\n\n // Retry flow: update DB -> increment retry -> send to retry queue with per-message expiration -> ack original.\n private async handleProcessingError(message: QueueMessage<T>, rawMessage: amqp.ConsumeMessage, channel: amqp.Channel, error: any, queueName: string): Promise<void> {\n const errorMessage = (error as Error)?.message || String(error);\n this.logger.error(`Error processing message on queue ${queueName}: ${errorMessage}`, (error as Error)?.stack);\n\n if (message.currentRetry < message.retryCount) {\n await this.updateStatusInDatabase('retrying', message);\n\n message.currentRetry++;\n const retryQueue = `${queueName}.retry`;\n const payload = Buffer.from(JSON.stringify(message));\n\n // Per-message expiration keeps the message in the retry queue until TTL, then DLX routes it back.\n channel.sendToQueue(retryQueue, payload, {\n expiration: String(message.retryInterval || 1000),\n headers: {\n 'x-error': errorMessage,\n }\n });\n\n channel.ack(rawMessage);\n this.logger.warn(`Retrying message (${message.currentRetry}/${message.retryCount}) after ${message.retryInterval}ms on queue ${queueName}`);\n return;\n }\n\n await this.updateStatusInDatabase('failed', message, errorMessage, '');\n channel.ack(rawMessage);\n await this.publishToFailedQueue(queueName, Buffer.from(JSON.stringify(message)), channel, error);\n this.logger.error(`Message failed after ${message.retryCount} attempts on queue ${queueName}: ${errorMessage}`);\n }\n\n private async publishToFailedQueue(queueName: string, payload: Buffer | string, channel: amqp.Channel, error?: any): Promise<void> {\n const failedQueue = `${queueName}.failed`;\n const body = Buffer.isBuffer(payload) ? payload : Buffer.from(payload);\n const errorMessage = (error as Error)?.message || String(error || '');\n\n try {\n channel.sendToQueue(failedQueue, body, errorMessage ? {\n headers: { 'x-error': errorMessage }\n } : undefined);\n } catch (err) {\n this.logger.error(`Failed to publish to failed queue ${failedQueue}: ${(err as Error).message}`);\n }\n }\n\n private triggerReconnect(queueName: string, reason: string) {\n if (this.stopping) return;\n if (this.reconnectPromise) return;\n\n this.reconnectPromise = this.reconnectLoop(queueName, reason)\n .finally(() => {\n this.reconnectPromise = null;\n });\n }\n\n // Reconnect with backoff to avoid hammering the broker during outages.\n private async reconnectLoop(queueName: string, reason: string): Promise<void> {\n this.logger.warn(`RabbitMqSubscriber reconnecting for queue ${queueName}: ${reason}`);\n\n while (!this.stopping) {\n try {\n await this.connectAndConsume(queueName);\n this.reconnectAttempt = 0;\n this.logger.log(`RabbitMqSubscriber reconnected for queue ${queueName}`);\n return;\n } catch (err) {\n this.reconnectAttempt += 1;\n const delay = this.backoff();\n this.logger.warn(`RabbitMqSubscriber reconnect failed for queue ${queueName}; retrying in ${delay}ms`);\n await this.sleep(delay);\n }\n }\n }\n\n private async cleanup(): Promise<void> {\n const channel = this.channel;\n const connection = this.connection;\n const consumerTag = this.consumerTag;\n\n this.channel = null;\n this.connection = null;\n this.consumerTag = null;\n\n if (channel) {\n try {\n if (consumerTag) {\n await channel.cancel(consumerTag);\n }\n } catch (_) {\n // ignore\n }\n\n try {\n await channel.close();\n } catch (_) {\n // ignore\n }\n }\n\n if (connection) {\n try {\n await connection.close();\n } catch (_) {\n // ignore\n }\n }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n }\n\n // Exponential backoff with jitter, capped to 30s.\n private backoff(): number {\n const baseMs = 1000;\n const maxMs = 30_000;\n const exp = Math.min(maxMs, baseMs * Math.pow(2, this.reconnectAttempt));\n const jitter = Math.floor(Math.random() * (exp * 0.2));\n return Math.min(maxMs, exp + jitter);\n }\n\n /**\n * Abstract method for message processing logic.\n */\n protected async processMessage(message: QueueMessage<T>, rawMessage, channel, queueName: string): Promise<void> {\n await this.updateStatusInDatabase('started', message);\n\n // Capture the results of handling the task.\n const result = await this.subscribeWithTimeout(message, queueName);\n\n // Ack the message. \n channel.ack(rawMessage);\n\n // Persist success output and timing.\n await this.updateStatusInDatabase('succeeded', message, '', result ? JSON.stringify(result, null, 2) : '');\n\n }\n\n private async updateStatusInDatabase(stage: string, message: QueueMessage<T>, error: string = '', result: string = '') {\n\n // Update the existing message record by messageId; creation happens upstream.\n try {\n // 1. resolve the queue first\n const mqMessage = await this.mqMessageService.repo.findOne({\n where: {\n messageId: message.messageId,\n }\n });\n\n if (mqMessage) {\n const updatedFields = {\n stage: stage\n };\n if (stage === 'failed' || stage === 'succeeded') {\n updatedFields['finishedAt'] = new Date();\n updatedFields['elapsedMillis'] = updatedFields['finishedAt'].getTime() - mqMessage.startedAt.getTime();\n }\n if (stage === 'succeeded') {\n updatedFields['output'] = result;\n }\n if (stage === 'failed') {\n updatedFields['error'] = error;\n }\n await this.mqMessageService.repo.update(mqMessage.id, updatedFields);\n }\n }\n catch (error) {\n this.logger.error(error.message, error.stack);\n }\n\n }\n\n private resolveProcessingTimeoutMs(): number {\n // Broker-side delivery-ack timeout (ms). If not provided, assume RabbitMQ default\n // behavior used in this project: 30 minutes.\n // Example (RabbitMQ broker):\n // - Broker ack timeout: 30m => 1,800,000ms (QUEUES_RABBITMQ_CONSUMER_ACK_TIMEOUT_MS)\n // - App soft timeout should be slightly lower, e.g. 29m30s => 1,770,000ms\n // (QUEUES_RABBITMQ_SUBSCRIBER_PROCESSING_TIMEOUT_MS), so application code fails first,\n // records DB state/error, and avoids broker-forced channel close as primary failure signal.\n const brokerTimeoutMs = this.parsePositiveInt(process.env.QUEUES_RABBITMQ_CONSUMER_ACK_TIMEOUT_MS, 30 * 60 * 1000);\n\n // Soft timeout should fire *before* broker timeout so we can fail explicitly,\n // persist status/error, and avoid broker-forced channel closure as primary signal.\n // Keep at least 1s to avoid zero/negative values when broker timeout is very small.\n const defaultSoftTimeoutMs = Math.max(1_000, brokerTimeoutMs - 30_000);\n\n // Final timeout precedence:\n // 1) QUEUES_RABBITMQ_SUBSCRIBER_PROCESSING_TIMEOUT_MS (if valid positive int)\n // 2) Derived defaultSoftTimeoutMs (broker timeout - 30s)\n return this.parsePositiveInt(process.env.QUEUES_RABBITMQ_SUBSCRIBER_PROCESSING_TIMEOUT_MS, defaultSoftTimeoutMs);\n }\n\n private parsePositiveInt(value: string | undefined, fallback: number): number {\n // Shared env parsing helper:\n // - missing/invalid/non-positive => fallback\n // - valid positive integer => parsed value\n if (!value) return fallback;\n const parsed = Number.parseInt(value, 10);\n return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;\n }\n\n private async subscribeWithTimeout(message: QueueMessage<T>, queueName: string): Promise<any> {\n const timeoutMs = this.resolveProcessingTimeoutMs();\n const messageId = message?.messageId || 'unknown';\n\n // Allow an escape hatch: non-positive timeout means run without a soft timeout.\n if (timeoutMs <= 0) {\n return this.subscribe(message);\n }\n\n let timedOut = false;\n let timeoutHandle: NodeJS.Timeout | null = null;\n\n // Main subscriber work promise.\n // If timeout has already fired, suppress rethrow to avoid unhandled rejection noise\n // (the timeout error is already the authoritative failure we track).\n const subscribePromise = this.subscribe(message).catch((error) => {\n if (timedOut) {\n this.logger.error(\n `Subscriber promise rejected after timeout for queue ${queueName} and messageId ${messageId}: ${(error as Error)?.message || String(error)}`,\n (error as Error)?.stack,\n );\n return undefined;\n }\n throw error;\n });\n\n // Timeout promise rejects after timeoutMs with an explicit domain-specific error.\n const timeoutPromise = new Promise<never>((_, reject) => {\n timeoutHandle = setTimeout(() => {\n timedOut = true;\n reject(new ConsumerProcessingTimeoutError(queueName, messageId, timeoutMs));\n }, timeoutMs);\n });\n\n try {\n // Promise.race settles as soon as the *first* promise settles.\n // - If subscribePromise resolves/rejects first, we use that outcome.\n // - If timeoutPromise rejects first, we fail fast with timeout error.\n // This ensures we mark DB status via normal error handling before broker ack-timeout.\n return await Promise.race([subscribePromise, timeoutPromise]);\n } catch (error) {\n const errorMessage = (error as Error)?.message || String(error);\n this.logger.error(\n `Subscriber execution failed for queue ${queueName} and messageId ${messageId}: ${errorMessage}`,\n (error as Error)?.stack,\n );\n throw error;\n } finally {\n // Always clear timer once race settles to avoid timer leaks.\n if (timeoutHandle) {\n clearTimeout(timeoutHandle);\n }\n }\n }\n\n}\n"]}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { ModuleRef } from "@nestjs/core";
|
|
2
2
|
import { ScheduledJob } from 'src/entities/scheduled-job.entity';
|
|
3
|
+
import { SolidRegistry } from 'src/helpers/solid-registry';
|
|
3
4
|
import { ScheduledJobRepository } from 'src/repository/scheduled-job.repository';
|
|
4
5
|
import { EntityManager } from 'typeorm';
|
|
5
6
|
import { CRUDService } from './crud.service';
|
|
7
|
+
import { SchedulerServiceImpl } from './scheduled-jobs/scheduler.service';
|
|
6
8
|
export declare class ScheduledJobService extends CRUDService<ScheduledJob> {
|
|
7
9
|
readonly entityManager: EntityManager;
|
|
8
10
|
readonly repo: ScheduledJobRepository;
|
|
9
11
|
readonly moduleRef: ModuleRef;
|
|
12
|
+
private readonly solidRegistry;
|
|
13
|
+
private readonly schedulerService;
|
|
10
14
|
private readonly logger;
|
|
11
|
-
constructor(entityManager: EntityManager, repo: ScheduledJobRepository, moduleRef: ModuleRef);
|
|
15
|
+
constructor(entityManager: EntityManager, repo: ScheduledJobRepository, moduleRef: ModuleRef, solidRegistry: SolidRegistry, schedulerService: SchedulerServiceImpl);
|
|
16
|
+
triggerRun(id: number): Promise<ScheduledJob>;
|
|
12
17
|
}
|
|
13
18
|
//# sourceMappingURL=scheduled-job.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduled-job.service.d.ts","sourceRoot":"","sources":["../../src/services/scheduled-job.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"scheduled-job.service.d.ts","sourceRoot":"","sources":["../../src/services/scheduled-job.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E,qBACa,mBAAoB,SAAQ,WAAW,CAAC,YAAY,CAAC;IAK9D,QAAQ,CAAC,aAAa,EAAE,aAAa;IAGrC,QAAQ,CAAC,IAAI,EAAE,sBAAsB;IACrC,QAAQ,CAAC,SAAS,EAAE,SAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAVnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;gBAIpD,aAAa,EAAE,aAAa,EAG5B,IAAI,EAAE,sBAAsB,EAC5B,SAAS,EAAE,SAAS,EACZ,aAAa,EAAE,aAAa,EAC5B,gBAAgB,EAAE,oBAAoB;IAMnD,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAwBpD"}
|
|
@@ -17,17 +17,39 @@ exports.ScheduledJobService = void 0;
|
|
|
17
17
|
const common_1 = require("@nestjs/common");
|
|
18
18
|
const core_1 = require("@nestjs/core");
|
|
19
19
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
20
|
+
const solid_registry_1 = require("../helpers/solid-registry");
|
|
20
21
|
const scheduled_job_repository_1 = require("../repository/scheduled-job.repository");
|
|
21
22
|
const typeorm_2 = require("typeorm");
|
|
22
23
|
const crud_service_1 = require("./crud.service");
|
|
24
|
+
const scheduler_service_1 = require("./scheduled-jobs/scheduler.service");
|
|
23
25
|
let ScheduledJobService = ScheduledJobService_1 = class ScheduledJobService extends crud_service_1.CRUDService {
|
|
24
|
-
constructor(entityManager, repo, moduleRef) {
|
|
26
|
+
constructor(entityManager, repo, moduleRef, solidRegistry, schedulerService) {
|
|
25
27
|
super(entityManager, repo, 'scheduledJob', 'solid-core', moduleRef);
|
|
26
28
|
this.entityManager = entityManager;
|
|
27
29
|
this.repo = repo;
|
|
28
30
|
this.moduleRef = moduleRef;
|
|
31
|
+
this.solidRegistry = solidRegistry;
|
|
32
|
+
this.schedulerService = schedulerService;
|
|
29
33
|
this.logger = new common_1.Logger(ScheduledJobService_1.name);
|
|
30
34
|
}
|
|
35
|
+
async triggerRun(id) {
|
|
36
|
+
const job = await this.repo.findOne({ where: { id } });
|
|
37
|
+
if (!job) {
|
|
38
|
+
throw new common_1.NotFoundException(`Scheduled job with id ${id} not found`);
|
|
39
|
+
}
|
|
40
|
+
const handler = this.solidRegistry.getScheduledJobProviderInstance(job.job);
|
|
41
|
+
if (!handler) {
|
|
42
|
+
throw new common_1.BadRequestException(`Scheduled job handler not found: ${job.job}`);
|
|
43
|
+
}
|
|
44
|
+
this.logger.log(`Manually triggering scheduled job id=${job.id}, job=${job.job}`);
|
|
45
|
+
await handler.execute(job);
|
|
46
|
+
const finishedAt = new Date();
|
|
47
|
+
job.lastRunAt = finishedAt;
|
|
48
|
+
job.nextRunAt = this.schedulerService.computeNextRunAt(job, finishedAt);
|
|
49
|
+
await this.repo.save(job);
|
|
50
|
+
this.logger.log(`Completed manual trigger for scheduled job id=${job.id}, nextRunAt=${job.nextRunAt?.toISOString?.()}`);
|
|
51
|
+
return job;
|
|
52
|
+
}
|
|
31
53
|
};
|
|
32
54
|
exports.ScheduledJobService = ScheduledJobService;
|
|
33
55
|
exports.ScheduledJobService = ScheduledJobService = ScheduledJobService_1 = __decorate([
|
|
@@ -35,6 +57,8 @@ exports.ScheduledJobService = ScheduledJobService = ScheduledJobService_1 = __de
|
|
|
35
57
|
__param(0, (0, typeorm_1.InjectEntityManager)()),
|
|
36
58
|
__metadata("design:paramtypes", [typeorm_2.EntityManager,
|
|
37
59
|
scheduled_job_repository_1.ScheduledJobRepository,
|
|
38
|
-
core_1.ModuleRef
|
|
60
|
+
core_1.ModuleRef,
|
|
61
|
+
solid_registry_1.SolidRegistry,
|
|
62
|
+
scheduler_service_1.SchedulerServiceImpl])
|
|
39
63
|
], ScheduledJobService);
|
|
40
64
|
//# sourceMappingURL=scheduled-job.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduled-job.service.js","sourceRoot":"","sources":["../../src/services/scheduled-job.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"scheduled-job.service.js","sourceRoot":"","sources":["../../src/services/scheduled-job.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA4F;AAC5F,uCAAyC;AACzC,6CAAsD;AAEtD,8DAA2D;AAC3D,qFAAiF;AACjF,qCAAwC;AACxC,iDAA6C;AAC7C,0EAA0E;AAGnE,IAAM,mBAAmB,2BAAzB,MAAM,mBAAoB,SAAQ,0BAAyB;IAGhE,YAEE,aAAqC,EAG5B,IAA4B,EAC5B,SAAoB,EACZ,aAA4B,EAC5B,gBAAsC;QAGvD,KAAK,CAAC,aAAa,EAAE,IAAI,EAAE,cAAc,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;QAT3D,kBAAa,GAAb,aAAa,CAAe;QAG5B,SAAI,GAAJ,IAAI,CAAwB;QAC5B,cAAS,GAAT,SAAS,CAAW;QACZ,kBAAa,GAAb,aAAa,CAAe;QAC5B,qBAAgB,GAAhB,gBAAgB,CAAsB;QAVxC,WAAM,GAAG,IAAI,eAAM,CAAC,qBAAmB,CAAC,IAAI,CAAC,CAAC;IAc/D,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QACvD,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,0BAAiB,CAAC,yBAAyB,EAAE,YAAY,CAAC,CAAC;QACvE,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,+BAA+B,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5E,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,4BAAmB,CAAC,oCAAoC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;QAC/E,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,wCAAwC,GAAG,CAAC,EAAE,SAAS,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;QAElF,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAE3B,MAAM,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC;QAC9B,GAAG,CAAC,SAAS,GAAG,UAAU,CAAC;QAC3B,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QACxE,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE1B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,iDAAiD,GAAG,CAAC,EAAE,eAAe,GAAG,CAAC,SAAS,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;QAExH,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAA;AAzCY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,6BAAmB,GAAE,CAAA;qCACE,uBAAa;QAGtB,iDAAsB;QACjB,gBAAS;QACG,8BAAa;QACV,wCAAoB;GAX9C,mBAAmB,CAyC/B","sourcesContent":["import { BadRequestException, Injectable, Logger, NotFoundException } from '@nestjs/common';\nimport { ModuleRef } from \"@nestjs/core\";\nimport { InjectEntityManager } from '@nestjs/typeorm';\nimport { ScheduledJob } from 'src/entities/scheduled-job.entity';\nimport { SolidRegistry } from 'src/helpers/solid-registry';\nimport { ScheduledJobRepository } from 'src/repository/scheduled-job.repository';\nimport { EntityManager } from 'typeorm';\nimport { CRUDService } from './crud.service';\nimport { SchedulerServiceImpl } from './scheduled-jobs/scheduler.service';\n\n@Injectable()\nexport class ScheduledJobService extends CRUDService<ScheduledJob> {\n private readonly logger = new Logger(ScheduledJobService.name);\n\n constructor(\n @InjectEntityManager()\n readonly entityManager: EntityManager,\n // @InjectRepository(ScheduledJob)\n // readonly repo: Repository<ScheduledJob>,\n readonly repo: ScheduledJobRepository,\n readonly moduleRef: ModuleRef,\n private readonly solidRegistry: SolidRegistry,\n private readonly schedulerService: SchedulerServiceImpl,\n\n ) {\n super(entityManager, repo, 'scheduledJob', 'solid-core', moduleRef);\n }\n\n async triggerRun(id: number): Promise<ScheduledJob> {\n const job = await this.repo.findOne({ where: { id } });\n if (!job) {\n throw new NotFoundException(`Scheduled job with id ${id} not found`);\n }\n\n const handler = this.solidRegistry.getScheduledJobProviderInstance(job.job);\n if (!handler) {\n throw new BadRequestException(`Scheduled job handler not found: ${job.job}`);\n }\n\n this.logger.log(`Manually triggering scheduled job id=${job.id}, job=${job.job}`);\n\n await handler.execute(job);\n\n const finishedAt = new Date();\n job.lastRunAt = finishedAt;\n job.nextRunAt = this.schedulerService.computeNextRunAt(job, finishedAt);\n await this.repo.save(job);\n\n this.logger.log(`Completed manual trigger for scheduled job id=${job.id}, nextRunAt=${job.nextRunAt?.toISOString?.()}`);\n\n return job;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.interface.d.ts","sourceRoot":"","sources":["../../../src/services/scheduled-jobs/scheduler.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAC9B,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"scheduler.interface.d.ts","sourceRoot":"","sources":["../../../src/services/scheduled-jobs/scheduler.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAEjE,MAAM,WAAW,iBAAiB;IAC9B,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,gBAAgB,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;CACzD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.interface.js","sourceRoot":"","sources":["../../../src/services/scheduled-jobs/scheduler.interface.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"scheduler.interface.js","sourceRoot":"","sources":["../../../src/services/scheduled-jobs/scheduler.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { ScheduledJob } from \"src/entities/scheduled-job.entity\";\n\nexport interface ISchedulerService {\n runScheduledJobs(): Promise<void>;\n computeNextRunAt(job: ScheduledJob, from: Date): Date;\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ScheduledJob } from 'src/entities/scheduled-job.entity';
|
|
1
2
|
import { SolidRegistry } from 'src/helpers/solid-registry';
|
|
2
3
|
import { ScheduledJobRepository } from 'src/repository/scheduled-job.repository';
|
|
3
4
|
import { ISchedulerService } from './scheduler.interface';
|
|
@@ -9,7 +10,10 @@ export declare class SchedulerServiceImpl implements ISchedulerService {
|
|
|
9
10
|
constructor(scheduledJobRepo: ScheduledJobRepository, solidRegistry: SolidRegistry);
|
|
10
11
|
runScheduledJobs(): Promise<void>;
|
|
11
12
|
private shouldRunNow;
|
|
12
|
-
private
|
|
13
|
-
private
|
|
13
|
+
private parseDayOfWeek;
|
|
14
|
+
private toDateOnly;
|
|
15
|
+
private toHHMM;
|
|
16
|
+
computeNextRunForCustomCron(job: ScheduledJob, from: Date): Date;
|
|
17
|
+
computeNextRunAt(job: ScheduledJob, from: Date): Date;
|
|
14
18
|
}
|
|
15
19
|
//# sourceMappingURL=scheduler.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.service.d.ts","sourceRoot":"","sources":["../../../src/services/scheduled-jobs/scheduler.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scheduler.service.d.ts","sourceRoot":"","sources":["../../../src/services/scheduled-jobs/scheduler.service.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG1D,qBACa,oBAAqB,YAAW,iBAAiB;IAOtD,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,aAAa;IAPlC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyC;IAChE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;gBAK5B,gBAAgB,EAAE,sBAAsB,EACxC,aAAa,EAAE,aAAa;IAI3C,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAwFvC,OAAO,CAAC,YAAY;IAwCpB,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,UAAU;IAgBlB,OAAO,CAAC,MAAM;IAoBP,2BAA2B,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI;IAgChE,gBAAgB,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI;CAwB/D"}
|
|
@@ -27,12 +27,24 @@ let SchedulerServiceImpl = SchedulerServiceImpl_1 = class SchedulerServiceImpl {
|
|
|
27
27
|
async runScheduledJobs() {
|
|
28
28
|
const solidSchedulerEnabled = process.env.SOLID_SCHEDULER_ENABLED || "true";
|
|
29
29
|
if (solidSchedulerEnabled.toLowerCase() !== "true") {
|
|
30
|
+
this.logger.debug('Solid scheduler is disabled via environment variable');
|
|
30
31
|
return;
|
|
31
32
|
}
|
|
32
33
|
const solidCliRunning = process.env.SOLID_CLI_RUNNING || "false";
|
|
33
34
|
if (solidCliRunning === "true") {
|
|
34
35
|
return;
|
|
35
36
|
}
|
|
37
|
+
const jobsRegexToEnable = (process.env.SOLID_SCHEDULER_JOBS_REGEX_TO_ENABLE || '').trim();
|
|
38
|
+
let jobsRegex = null;
|
|
39
|
+
if (jobsRegexToEnable && jobsRegexToEnable !== "all") {
|
|
40
|
+
try {
|
|
41
|
+
jobsRegex = new RegExp(jobsRegexToEnable);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
this.logger.error(`Invalid SOLID_SCHEDULER_JOBS_REGEX_TO_ENABLE regex "${jobsRegexToEnable}". Scheduler loop will skip this run.`);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
36
48
|
const now = new Date();
|
|
37
49
|
const dueJobs = await this.scheduledJobRepo.find({
|
|
38
50
|
where: [
|
|
@@ -48,6 +60,11 @@ let SchedulerServiceImpl = SchedulerServiceImpl_1 = class SchedulerServiceImpl {
|
|
|
48
60
|
});
|
|
49
61
|
for (const job of dueJobs) {
|
|
50
62
|
const jobKey = String(job.id ?? job.scheduleName ?? job.job);
|
|
63
|
+
const jobName = String(job.job ?? '');
|
|
64
|
+
if (jobsRegex && !jobsRegex.test(jobName)) {
|
|
65
|
+
this.logger.log(`[${now.getTime()}]: scheduler service skipping job ${jobName} because it does not match SOLID_SCHEDULER_JOBS_REGEX_TO_ENABLE=${jobsRegexToEnable}`);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
51
68
|
if (this.runningJobs.has(jobKey)) {
|
|
52
69
|
this.logger.log(`[${now.getTime()}]: scheduler service skipping job ${job.job} because a run is already in progress`);
|
|
53
70
|
continue;
|
|
@@ -82,28 +99,27 @@ let SchedulerServiceImpl = SchedulerServiceImpl_1 = class SchedulerServiceImpl {
|
|
|
82
99
|
}
|
|
83
100
|
}
|
|
84
101
|
shouldRunNow(job, now) {
|
|
85
|
-
const today = now
|
|
86
|
-
|
|
87
|
-
|
|
102
|
+
const today = new Date(now);
|
|
103
|
+
today.setHours(0, 0, 0, 0);
|
|
104
|
+
const timeNow = this.toHHMM(now);
|
|
105
|
+
const startDate = this.toDateOnly(job.startDate);
|
|
106
|
+
const endDate = this.toDateOnly(job.endDate);
|
|
107
|
+
if (startDate && today < startDate)
|
|
88
108
|
return false;
|
|
89
|
-
if (
|
|
109
|
+
if (endDate && today > endDate)
|
|
110
|
+
return false;
|
|
111
|
+
const jobStart = this.toHHMM(job.startTime);
|
|
112
|
+
const jobEnd = this.toHHMM(job.endTime);
|
|
113
|
+
if (jobStart && timeNow < jobStart)
|
|
114
|
+
return false;
|
|
115
|
+
if (jobEnd && timeNow > jobEnd)
|
|
90
116
|
return false;
|
|
91
|
-
if (job.startTime) {
|
|
92
|
-
const jobStart = job.startTime.toTimeString().slice(0, 5);
|
|
93
|
-
if (timeNow < jobStart)
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
if (job.endTime) {
|
|
97
|
-
const jobEnd = job.endTime.toTimeString().slice(0, 5);
|
|
98
|
-
if (timeNow > jobEnd)
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
117
|
if (job.frequency.toLowerCase() === 'custom') {
|
|
102
118
|
return true;
|
|
103
119
|
}
|
|
104
120
|
if (job.frequency.toLowerCase() === 'weekly' && job.dayOfWeek) {
|
|
105
121
|
const todayName = now.toLocaleString('en-US', { weekday: 'long' });
|
|
106
|
-
const days =
|
|
122
|
+
const days = this.parseDayOfWeek(job.dayOfWeek);
|
|
107
123
|
if (!days.includes(todayName))
|
|
108
124
|
return false;
|
|
109
125
|
}
|
|
@@ -114,6 +130,47 @@ let SchedulerServiceImpl = SchedulerServiceImpl_1 = class SchedulerServiceImpl {
|
|
|
114
130
|
}
|
|
115
131
|
return true;
|
|
116
132
|
}
|
|
133
|
+
parseDayOfWeek(dayOfWeek) {
|
|
134
|
+
try {
|
|
135
|
+
const parsed = JSON.parse(dayOfWeek);
|
|
136
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
this.logger.warn(`Invalid dayOfWeek JSON '${dayOfWeek}'`, error);
|
|
140
|
+
return [];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
toDateOnly(value) {
|
|
144
|
+
if (!value)
|
|
145
|
+
return null;
|
|
146
|
+
if (value instanceof Date) {
|
|
147
|
+
const d = new Date(value);
|
|
148
|
+
d.setHours(0, 0, 0, 0);
|
|
149
|
+
return d;
|
|
150
|
+
}
|
|
151
|
+
const parsed = new Date(value);
|
|
152
|
+
if (Number.isNaN(parsed.getTime()))
|
|
153
|
+
return null;
|
|
154
|
+
parsed.setHours(0, 0, 0, 0);
|
|
155
|
+
return parsed;
|
|
156
|
+
}
|
|
157
|
+
toHHMM(value) {
|
|
158
|
+
if (!value)
|
|
159
|
+
return null;
|
|
160
|
+
if (value instanceof Date) {
|
|
161
|
+
return value.toTimeString().slice(0, 5);
|
|
162
|
+
}
|
|
163
|
+
if (typeof value === 'string') {
|
|
164
|
+
const match = value.match(/^(\d{2}):(\d{2})/);
|
|
165
|
+
if (match)
|
|
166
|
+
return `${match[1]}:${match[2]}`;
|
|
167
|
+
const parsed = new Date(value);
|
|
168
|
+
if (!Number.isNaN(parsed.getTime())) {
|
|
169
|
+
return parsed.toTimeString().slice(0, 5);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
117
174
|
computeNextRunForCustomCron(job, from) {
|
|
118
175
|
const base = new Date(from);
|
|
119
176
|
if (!job.cronExpression) {
|
|
@@ -126,14 +183,15 @@ let SchedulerServiceImpl = SchedulerServiceImpl_1 = class SchedulerServiceImpl {
|
|
|
126
183
|
tz: 'UTC'
|
|
127
184
|
});
|
|
128
185
|
const nextRun = interval.next().toDate();
|
|
129
|
-
|
|
186
|
+
const runAfterNext = interval.next().toDate();
|
|
187
|
+
if (runAfterNext.getTime() - nextRun.getTime() < 60000) {
|
|
130
188
|
throw new Error('Cron expression interval must be at least 1 minute');
|
|
131
189
|
}
|
|
132
190
|
this.logger.log(`Custom cron '${job.cronExpression}' next run: ${nextRun}`);
|
|
133
191
|
return nextRun;
|
|
134
192
|
}
|
|
135
193
|
catch (error) {
|
|
136
|
-
this.logger.error(`Invalid cron expression for job ${job.scheduleName}: ${job.cronExpression}
|
|
194
|
+
this.logger.error(`Invalid cron expression for job ${job.scheduleName}: ${job.cronExpression}. Reason: ${error.message}`);
|
|
137
195
|
return new Date(base.getTime() + 24 * 60 * 60 * 1000);
|
|
138
196
|
}
|
|
139
197
|
}
|