podverse-mq 5.1.12-alpha.0 → 5.1.12

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.
@@ -1,7 +1,7 @@
1
1
  import { ActiveMQArtemisService } from "@queue/services/activeMQArtemis";
2
- import { MQQueueConfig } from "podverse-helpers";
2
+ import { MQQueueConfigFunctionParams } from "podverse-helpers";
3
3
  import { ParseRSSFeedAndSaveToDatabaseOptions } from "podverse-parser";
4
- type MQRSSAddOptions = MQQueueConfig & {
4
+ type MQRSSAddOptions = MQQueueConfigFunctionParams & {
5
5
  feedUrl: string;
6
6
  podcast_index_id: number;
7
7
  };
@@ -1 +1 @@
1
- {"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../../../../src/functions/mq/rss/add.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,oCAAoC,EAAE,MAAM,iBAAiB,CAAC;AAEvE,KAAK,eAAe,GAAG,aAAa,GAAG;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAA;AAED,eAAO,MAAM,QAAQ,GACnB,wBAAwB,sBAAsB,EAC9C,SAAS,eAAe,EACxB,YAAY,oCAAoC,kBAgBjD,CAAC"}
1
+ {"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../../../../src/functions/mq/rss/add.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,oCAAoC,EAAE,MAAM,iBAAiB,CAAC;AAEvE,KAAK,eAAe,GAAG,2BAA2B,GAAG;IACnD,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAA;AAED,eAAO,MAAM,QAAQ,GACnB,wBAAwB,sBAAsB,EAC9C,SAAS,eAAe,EACxB,YAAY,oCAAoC,kBA0BjD,CAAC"}
@@ -12,16 +12,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.mqRSSAdd = void 0;
13
13
  const mqRSSAdd = (activeMQArtemisService, options, msgOptions) => __awaiter(void 0, void 0, void 0, function* () {
14
14
  yield activeMQArtemisService.initialize();
15
- const message = {
16
- url: options.feedUrl,
17
- podcast_index_id: options.podcast_index_id,
18
- options: msgOptions
19
- };
20
- yield activeMQArtemisService.sendMessage({
21
- queueName: options.queueName,
22
- message,
23
- priority: options.priority,
24
- dedupeCacheTimeMS: options.dedupeCacheTimeMS
25
- });
15
+ try {
16
+ const message = {
17
+ url: options.feedUrl,
18
+ podcast_index_id: options.podcast_index_id,
19
+ options: msgOptions
20
+ };
21
+ yield activeMQArtemisService.sendMessage({
22
+ queueName: options.queueName,
23
+ message,
24
+ priority: options.priority,
25
+ dedupeCacheTimeMS: options.dedupeCacheTimeMS
26
+ });
27
+ }
28
+ finally {
29
+ try {
30
+ if (options.closeAfterSend) {
31
+ yield activeMQArtemisService.close();
32
+ }
33
+ }
34
+ catch (_a) {
35
+ // swallow
36
+ }
37
+ }
26
38
  });
27
39
  exports.mqRSSAdd = mqRSSAdd;
@@ -1,7 +1,7 @@
1
1
  import { ActiveMQArtemisService } from "@queue/services/activeMQArtemis";
2
- import { MQQueueConfig } from "podverse-helpers";
2
+ import { MQQueueConfigFunctionParams } from "podverse-helpers";
3
3
  import { ParseRSSFeedAndSaveToDatabaseOptions } from "podverse-parser";
4
- type MQRSSAddAllConfig = MQQueueConfig;
4
+ type MQRSSAddAllConfig = MQQueueConfigFunctionParams;
5
5
  export declare const mqRSSAddAll: (activeMQArtemisService: ActiveMQArtemisService, options: MQRSSAddAllConfig, msgOptions: ParseRSSFeedAndSaveToDatabaseOptions) => Promise<void>;
6
6
  export {};
7
7
  //# sourceMappingURL=addAll.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"addAll.d.ts","sourceRoot":"","sources":["../../../../src/functions/mq/rss/addAll.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,oCAAoC,EAAE,MAAM,iBAAiB,CAAC;AAEvE,KAAK,iBAAiB,GAAG,aAAa,CAAC;AAEvC,eAAO,MAAM,WAAW,GACtB,wBAAwB,sBAAsB,EAC9C,SAAS,iBAAiB,EAC1B,YAAY,oCAAoC,kBAqBjD,CAAC"}
1
+ {"version":3,"file":"addAll.d.ts","sourceRoot":"","sources":["../../../../src/functions/mq/rss/addAll.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,oCAAoC,EAAE,MAAM,iBAAiB,CAAC;AAEvE,KAAK,iBAAiB,GAAG,2BAA2B,CAAC;AAErD,eAAO,MAAM,WAAW,GACtB,wBAAwB,sBAAsB,EAC9C,SAAS,iBAAiB,EAC1B,YAAY,oCAAoC,kBA+BjD,CAAC"}
@@ -15,18 +15,30 @@ const mqRSSAddAll = (activeMQArtemisService, options, msgOptions) => __awaiter(v
15
15
  const feedService = new podverse_orm_1.FeedService();
16
16
  const feeds = yield feedService.getAll();
17
17
  yield activeMQArtemisService.initialize();
18
- for (const feed of feeds) {
19
- const message = {
20
- url: feed.url,
21
- podcast_index_id: feed.podcast_index_id,
22
- options: msgOptions
23
- };
24
- yield activeMQArtemisService.sendMessage({
25
- queueName: options.queueName,
26
- message,
27
- priority: options.priority,
28
- dedupeCacheTimeMS: options.dedupeCacheTimeMS
29
- });
18
+ try {
19
+ for (const feed of feeds) {
20
+ const message = {
21
+ url: feed.url,
22
+ podcast_index_id: feed.podcast_index_id,
23
+ options: msgOptions
24
+ };
25
+ yield activeMQArtemisService.sendMessage({
26
+ queueName: options.queueName,
27
+ message,
28
+ priority: options.priority,
29
+ dedupeCacheTimeMS: options.dedupeCacheTimeMS
30
+ });
31
+ }
32
+ }
33
+ finally {
34
+ try {
35
+ if (options.closeAfterSend) {
36
+ yield activeMQArtemisService.close();
37
+ }
38
+ }
39
+ catch (_a) {
40
+ // swallow
41
+ }
30
42
  }
31
43
  });
32
44
  exports.mqRSSAddAll = mqRSSAddAll;
@@ -1,8 +1,8 @@
1
1
  import { PodcastIndexService } from 'podverse-external-services';
2
- import { MQQueueConfig } from 'podverse-helpers';
2
+ import { MQQueueConfigFunctionParams } from 'podverse-helpers';
3
3
  import { ActiveMQArtemisService } from "@queue/services/activeMQArtemis";
4
4
  import { ParseRSSFeedAndSaveToDatabaseOptions } from 'podverse-parser';
5
- type MQRSSAddAllRecentlyUpdatedFeedsOptions = MQQueueConfig & {
5
+ type MQRSSAddAllRecentlyUpdatedFeedsOptions = MQQueueConfigFunctionParams & {
6
6
  sinceRange: number;
7
7
  };
8
8
  export declare const mqRSSAddRecentlyUpdatedFeedsFromPodcastIndex: (activeMQArtemisService: ActiveMQArtemisService, podcastIndexService: PodcastIndexService, options: MQRSSAddAllRecentlyUpdatedFeedsOptions, msgOptions: ParseRSSFeedAndSaveToDatabaseOptions) => Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"addRecentlyUpdatedFeedsFromPodcastIndex.d.ts","sourceRoot":"","sources":["../../../../src/functions/mq/rss/addRecentlyUpdatedFeedsFromPodcastIndex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE,OAAO,EAAE,oCAAoC,EAAE,MAAM,iBAAiB,CAAC;AAEvE,KAAK,sCAAsC,GAAG,aAAa,GAAG;IAC5D,UAAU,EAAE,MAAM,CAAC;CACpB,CAAA;AAED,eAAO,MAAM,4CAA4C,GACvD,wBAAwB,sBAAsB,EAC9C,qBAAqB,mBAAmB,EACxC,SAAS,sCAAsC,EAC/C,YAAY,oCAAoC,kBA4BjD,CAAC"}
1
+ {"version":3,"file":"addRecentlyUpdatedFeedsFromPodcastIndex.d.ts","sourceRoot":"","sources":["../../../../src/functions/mq/rss/addRecentlyUpdatedFeedsFromPodcastIndex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAE/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE,OAAO,EAAE,oCAAoC,EAAE,MAAM,iBAAiB,CAAC;AAEvE,KAAK,sCAAsC,GAAG,2BAA2B,GAAG;IAC1E,UAAU,EAAE,MAAM,CAAC;CACpB,CAAA;AAED,eAAO,MAAM,4CAA4C,GACvD,wBAAwB,sBAAsB,EAC9C,qBAAqB,mBAAmB,EACxC,SAAS,sCAAsC,EAC/C,YAAY,oCAAoC,kBAsCjD,CAAC"}
@@ -15,23 +15,35 @@ const mqRSSAddRecentlyUpdatedFeedsFromPodcastIndex = (activeMQArtemisService, po
15
15
  const sinceRange = options.sinceRange;
16
16
  const recentlyUpdatedFeeds = yield podcastIndexService.recentGetData(sinceRange);
17
17
  yield activeMQArtemisService.initialize();
18
- for (const feed of recentlyUpdatedFeeds) {
19
- const feedService = new podverse_orm_1.FeedService();
20
- const podcast_index_id = feed.feedId;
21
- const dbFeed = yield feedService.getByPodcastIndexId(podcast_index_id);
22
- const shouldAddToQueue = !!dbFeed;
23
- if (shouldAddToQueue) {
24
- const message = {
25
- url: feed.feedUrl,
26
- podcast_index_id: feed.feedId,
27
- options: msgOptions
28
- };
29
- yield activeMQArtemisService.sendMessage({
30
- queueName: options.queueName,
31
- message,
32
- priority: options.priority,
33
- dedupeCacheTimeMS: options.dedupeCacheTimeMS
34
- });
18
+ try {
19
+ for (const feed of recentlyUpdatedFeeds) {
20
+ const feedService = new podverse_orm_1.FeedService();
21
+ const podcast_index_id = feed.feedId;
22
+ const dbFeed = yield feedService.getByPodcastIndexId(podcast_index_id);
23
+ const shouldAddToQueue = !!dbFeed;
24
+ if (shouldAddToQueue) {
25
+ const message = {
26
+ url: feed.feedUrl,
27
+ podcast_index_id: feed.feedId,
28
+ options: msgOptions
29
+ };
30
+ yield activeMQArtemisService.sendMessage({
31
+ queueName: options.queueName,
32
+ message,
33
+ priority: options.priority,
34
+ dedupeCacheTimeMS: options.dedupeCacheTimeMS
35
+ });
36
+ }
37
+ }
38
+ }
39
+ finally {
40
+ try {
41
+ if (options.closeAfterSend) {
42
+ yield activeMQArtemisService.close();
43
+ }
44
+ }
45
+ catch (_a) {
46
+ // swallow
35
47
  }
36
48
  }
37
49
  });
@@ -1 +1 @@
1
- {"version":3,"file":"runLiveItemListener.d.ts","sourceRoot":"","sources":["../../../../src/functions/mq/rss/runLiveItemListener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAe,MAAM,iCAAiC,CAAC;AAMtF,eAAO,MAAM,wBAAwB,GACnC,wBAAwB,sBAAsB,SA4I/C,CAAC"}
1
+ {"version":3,"file":"runLiveItemListener.d.ts","sourceRoot":"","sources":["../../../../src/functions/mq/rss/runLiveItemListener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAe,MAAM,iCAAiC,CAAC;AAMtF,eAAO,MAAM,wBAAwB,GACnC,wBAAwB,sBAAsB,SA6I/C,CAAC"}
@@ -89,7 +89,7 @@ const mqRSSRunLiveItemListener = (activeMQArtemisService) => {
89
89
  const queueType = 'rss-live';
90
90
  const mqConstantMessageOptions = podverse_helpers_1.MQ_QUEUES[queueType];
91
91
  for (const addRSSObj of addRSSObjs) {
92
- yield (0, add_1.mqRSSAdd)(activeMQArtemisService, Object.assign(Object.assign({}, mqConstantMessageOptions), { feedUrl: addRSSObj.url, podcast_index_id: addRSSObj.podcast_index_id }), {
92
+ yield (0, add_1.mqRSSAdd)(activeMQArtemisService, Object.assign(Object.assign({}, mqConstantMessageOptions), { feedUrl: addRSSObj.url, podcast_index_id: addRSSObj.podcast_index_id, closeAfterSend: false }), {
93
93
  forceParse: true,
94
94
  onDemandParserEvent: {
95
95
  accountId: null,
@@ -1 +1 @@
1
- {"version":3,"file":"runParser.d.ts","sourceRoot":"","sources":["../../../../src/functions/mq/rss/runParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEtF,eAAO,MAAM,cAAc,GACzB,wBAAwB,sBAAsB,EAC9C,WAAW,WAAW,kBAwBvB,CAAC"}
1
+ {"version":3,"file":"runParser.d.ts","sourceRoot":"","sources":["../../../../src/functions/mq/rss/runParser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAGtF,eAAO,MAAM,cAAc,GACzB,wBAAwB,sBAAsB,EAC9C,WAAW,WAAW,kBAmCvB,CAAC"}
@@ -10,7 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.mqRSSRunParser = void 0;
13
+ const podverse_helpers_1 = require("podverse-helpers");
13
14
  const podverse_parser_1 = require("podverse-parser");
15
+ const add_1 = require("./add");
14
16
  const mqRSSRunParser = (activeMQArtemisService, queueName) => __awaiter(void 0, void 0, void 0, function* () {
15
17
  yield activeMQArtemisService.initialize();
16
18
  yield activeMQArtemisService.consumeMessages(queueName, (context) => __awaiter(void 0, void 0, void 0, function* () {
@@ -20,7 +22,18 @@ const mqRSSRunParser = (activeMQArtemisService, queueName) => __awaiter(void 0,
20
22
  const receivedMessage = JSON.parse(bodyStr);
21
23
  const { url, podcast_index_id, options } = receivedMessage;
22
24
  if (url || podcast_index_id) {
23
- yield (0, podverse_parser_1.parseRSSFeedAndSaveToDatabase)(url, podcast_index_id, options);
25
+ const result = yield (0, podverse_parser_1.parseRSSFeedAndSaveToDatabase)(url, podcast_index_id, options);
26
+ if (result && Array.isArray(result.remoteItemsToParse) && result.remoteItemsToParse.length > 0) {
27
+ const mqConfig = podverse_helpers_1.MQ_QUEUES['rss-slow'];
28
+ for (const item of result.remoteItemsToParse) {
29
+ try {
30
+ yield (0, add_1.mqRSSAdd)(activeMQArtemisService, { queueName: mqConfig.queueName, dedupeCacheTimeMS: mqConfig.dedupeCacheTimeMS, priority: mqConfig.priority, closeAfterSend: false, feedUrl: item.url, podcast_index_id: item.podcast_index_id }, item.options);
31
+ }
32
+ catch (err) {
33
+ console.error('Error enqueueing remote item', err);
34
+ }
35
+ }
36
+ }
24
37
  (_c = context.delivery) === null || _c === void 0 ? void 0 : _c.accept();
25
38
  }
26
39
  else {
package/dist/index.d.ts CHANGED
@@ -6,4 +6,5 @@ export { mqRSSSetupDlqConsumers } from './functions/mq/rss/dlqHandling';
6
6
  export { mqRSSRunParser } from './functions/mq/rss/runParser';
7
7
  export { mqRSSRunLiveItemListener } from './functions/mq/rss/runLiveItemListener';
8
8
  export { ActiveMQArtemisService, ActiveMQArtemisServiceParams } from './services/activeMQArtemis';
9
+ export { createActiveMQShutdown } from './services/activeMQArtemis/shutdown';
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,CAAC;AAE/B,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,4CAA4C,EAAE,MAAM,4DAA4D,CAAC;AAC1H,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAElF,OAAO,EAAE,sBAAsB,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,CAAC;AAE/B,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,4CAA4C,EAAE,MAAM,4DAA4D,CAAC;AAC1H,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAElF,OAAO,EAAE,sBAAsB,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAClG,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ActiveMQArtemisService = exports.mqRSSRunLiveItemListener = exports.mqRSSRunParser = exports.mqRSSSetupDlqConsumers = exports.mqRSSAddRecentlyUpdatedFeedsFromPodcastIndex = exports.mqRSSAddAll = exports.mqRSSAdd = void 0;
3
+ exports.createActiveMQShutdown = exports.ActiveMQArtemisService = exports.mqRSSRunLiveItemListener = exports.mqRSSRunParser = exports.mqRSSSetupDlqConsumers = exports.mqRSSAddRecentlyUpdatedFeedsFromPodcastIndex = exports.mqRSSAddAll = exports.mqRSSAdd = void 0;
4
4
  require("./module-alias-config");
5
5
  var add_1 = require("./functions/mq/rss/add");
6
6
  Object.defineProperty(exports, "mqRSSAdd", { enumerable: true, get: function () { return add_1.mqRSSAdd; } });
@@ -16,3 +16,5 @@ var runLiveItemListener_1 = require("./functions/mq/rss/runLiveItemListener");
16
16
  Object.defineProperty(exports, "mqRSSRunLiveItemListener", { enumerable: true, get: function () { return runLiveItemListener_1.mqRSSRunLiveItemListener; } });
17
17
  var activeMQArtemis_1 = require("./services/activeMQArtemis");
18
18
  Object.defineProperty(exports, "ActiveMQArtemisService", { enumerable: true, get: function () { return activeMQArtemis_1.ActiveMQArtemisService; } });
19
+ var shutdown_1 = require("./services/activeMQArtemis/shutdown");
20
+ Object.defineProperty(exports, "createActiveMQShutdown", { enumerable: true, get: function () { return shutdown_1.createActiveMQShutdown; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/activeMQArtemis/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAgC,YAAY,EAAE,MAAM,MAAM,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAEzE,OAAO,EAAE,oCAAoC,EAAE,MAAM,qCAAqC,CAAC;AAE3F,MAAM,MAAM,WAAW,GACnB,YAAY,GACZ,eAAe,GACf,UAAU,GACV,OAAO,YAAY,GAAG,eAAe,GAAG,UAAU,EAAE,CAAC;AAEzD,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,OAAO,EAAE,oCAAoC,CAAC;CAC/C,CAAC;AAEF,KAAK,OAAO,GAAG,YAAY,CAAC;AAE5B,KAAK,iBAAiB,GAAG;IACvB,SAAS,EAAE,WAAW,CAAA;IACtB,OAAO,EAAE,OAAO,CAAA;IAChB,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAA;IAC3B,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAA;CACjC,CAAA;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAA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AE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IA4B7G,iBAAiB,IAAI,OAAO;IAItB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAkF7B"}
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.ActiveMQArtemisService = void 0;
16
16
  const rhea_1 = __importDefault(require("rhea"));
17
17
  const crypto_1 = __importDefault(require("crypto"));
18
+ const os_1 = require("podverse-helpers/dist/lib/backend/os");
18
19
  class ActiveMQArtemisService {
19
20
  constructor(params, logger) {
20
21
  this.connection = null;
@@ -52,11 +53,20 @@ class ActiveMQArtemisService {
52
53
  this.connecting = false; // allow retry attempts later
53
54
  return reject(err);
54
55
  }
56
+ const idleTimeOut = 30000;
57
+ const baseId = process.env.CONTAINER_ID
58
+ || process.env.HOSTNAME
59
+ || `podverse-mq-${crypto_1.default.randomBytes(4).toString('hex')}`;
60
+ const containerId = `${baseId}${(0, os_1.getContainerIpPart)()}`;
55
61
  const connection = rheaLike.connect({
56
62
  host: this.params.host,
57
63
  port: this.params.port,
58
64
  username: this.params.username,
59
65
  password: this.params.password,
66
+ // send AMQP heartbeats so broker (default 60s TTL) sees activity and stays alive until manually closed
67
+ idle_time_out: idleTimeOut,
68
+ container_id: containerId,
69
+ properties: { product: 'podverse-mq' },
60
70
  reconnect: true,
61
71
  reconnect_limit: -1
62
72
  });
@@ -254,40 +264,91 @@ class ActiveMQArtemisService {
254
264
  }
255
265
  close() {
256
266
  return __awaiter(this, void 0, void 0, function* () {
267
+ if (this.isShuttingDown)
268
+ return;
257
269
  this.isShuttingDown = true;
258
270
  this.logger.info('Closing ActiveMQ Artemis connection...');
259
- // Close all receivers first to stop accepting new messages
260
- for (const [queueName, receiver] of this.receivers.entries()) {
261
- try {
262
- receiver.close();
263
- this.logger.info(`Closed receiver for queue ${queueName}`);
264
- }
265
- catch (error) {
266
- this.logger.logError(`Error closing receiver for ${queueName}`, error);
271
+ const closeTimeoutMs = 10000;
272
+ const doClose = () => __awaiter(this, void 0, void 0, function* () {
273
+ // Close all receivers first to stop accepting new messages
274
+ for (const [queueName, receiver] of this.receivers.entries()) {
275
+ try {
276
+ receiver.close();
277
+ this.logger.info(`Closed receiver for queue ${queueName}`);
278
+ }
279
+ catch (error) {
280
+ this.logger.logError(`Error closing receiver for ${queueName}`, error);
281
+ }
267
282
  }
268
- }
269
- this.receivers.clear();
270
- // Close all senders
271
- for (const [queueName, sender] of this.senders.entries()) {
272
- try {
273
- sender.close();
274
- this.logger.info(`Closed sender for queue ${queueName}`);
283
+ this.receivers.clear();
284
+ // Close all senders
285
+ for (const [queueName, sender] of this.senders.entries()) {
286
+ try {
287
+ sender.close();
288
+ this.logger.info(`Closed sender for queue ${queueName}`);
289
+ }
290
+ catch (error) {
291
+ this.logger.logError(`Error closing sender for ${queueName}`, error);
292
+ }
275
293
  }
276
- catch (error) {
277
- this.logger.logError(`Error closing sender for ${queueName}`, error);
294
+ this.senders.clear();
295
+ // Close the connection
296
+ if (this.connection) {
297
+ try {
298
+ // Prevent reconnect attempts while we're shutting down
299
+ try {
300
+ // Attempt to disable reconnect behavior before closing.
301
+ // rhea doesn't provide a documented toggle here, so remove event listeners
302
+ // and try to flip common internal flags if present to avoid immediate reconnects.
303
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
304
+ const connAny = this.connection;
305
+ if (connAny) {
306
+ if (typeof connAny.removeAllListeners === 'function') {
307
+ connAny.removeAllListeners();
308
+ }
309
+ // some rhea versions expose internal options or flags we can defensively set
310
+ if (connAny.options && typeof connAny.options.reconnect !== 'undefined') {
311
+ try {
312
+ connAny.options.reconnect = false;
313
+ }
314
+ catch (_a) {
315
+ // swallow
316
+ }
317
+ }
318
+ try {
319
+ connAny.reconnect = false;
320
+ }
321
+ catch (_b) {
322
+ // swallow
323
+ }
324
+ }
325
+ }
326
+ catch (_c) {
327
+ // swallow - this is best-effort cleanup prior to close
328
+ }
329
+ this.connection.close();
330
+ this.logger.info('Closed ActiveMQ Artemis connection');
331
+ }
332
+ catch (error) {
333
+ this.logger.logError('Error closing connection', error);
334
+ }
335
+ this.connection = null;
278
336
  }
337
+ });
338
+ // race close against a timeout to avoid hanging shutdown; create timer before starting close
339
+ let timer;
340
+ const timeoutPromise = new Promise((resolve) => {
341
+ timer = setTimeout(() => {
342
+ this.logger.error(`ActiveMQ Artemis close() timed out after ${closeTimeoutMs}ms`);
343
+ resolve();
344
+ }, closeTimeoutMs);
345
+ });
346
+ try {
347
+ yield Promise.race([doClose(), timeoutPromise]);
279
348
  }
280
- this.senders.clear();
281
- // Close the connection
282
- if (this.connection) {
283
- try {
284
- this.connection.close();
285
- this.logger.info('Closed ActiveMQ Artemis connection');
286
- }
287
- catch (error) {
288
- this.logger.logError('Error closing connection', error);
289
- }
290
- this.connection = null;
349
+ finally {
350
+ if (timer)
351
+ clearTimeout(timer);
291
352
  }
292
353
  });
293
354
  }
@@ -0,0 +1,13 @@
1
+ type LoggerLike = {
2
+ info?: (...args: any[]) => void;
3
+ error?: (...args: any[]) => void;
4
+ log?: (...args: any[]) => void;
5
+ };
6
+ export declare const createActiveMQShutdown: (activeMQService: {
7
+ close: () => Promise<void>;
8
+ }, logger?: LoggerLike, onShutdown?: () => void, exitOnShutdown?: boolean) => {
9
+ shutdown: (signal?: string) => Promise<void>;
10
+ unregister: () => void;
11
+ };
12
+ export {};
13
+ //# sourceMappingURL=shutdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shutdown.d.ts","sourceRoot":"","sources":["../../../src/services/activeMQArtemis/shutdown.ts"],"names":[],"mappings":"AAEA,KAAK,UAAU,GAAG;IAChB,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAChC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IACjC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CAChC,CAAC;AAEF,eAAO,MAAM,sBAAsB,GACjC,iBAAiB;IAAE,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,EAC/C,SAAQ,UAAoB,EAC5B,aAAa,MAAM,IAAI,EACvB,wBAAqB;wBAEY,MAAM;;CA8BxC,CAAC"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.createActiveMQShutdown = void 0;
14
+ const createActiveMQShutdown = (activeMQService, logger = console, onShutdown, exitOnShutdown = true) => {
15
+ const shutdown = (signal) => __awaiter(void 0, void 0, void 0, function* () {
16
+ var _a, _b, _c;
17
+ try {
18
+ if (onShutdown)
19
+ onShutdown();
20
+ (_a = logger.info) === null || _a === void 0 ? void 0 : _a.call(logger, `Shutting down${signal ? ` due to ${signal}` : ''}`);
21
+ }
22
+ catch (_d) {
23
+ // ignore errors from onShutdown
24
+ }
25
+ try {
26
+ yield activeMQService.close();
27
+ (_b = logger.info) === null || _b === void 0 ? void 0 : _b.call(logger, 'ActiveMQ Artemis connection closed');
28
+ }
29
+ catch (err) {
30
+ (_c = logger.error) === null || _c === void 0 ? void 0 : _c.call(logger, 'Error during Artemis shutdown', err);
31
+ }
32
+ if (exitOnShutdown)
33
+ process.exit(0);
34
+ });
35
+ const handler = (sig) => void shutdown(sig);
36
+ process.on('SIGINT', handler);
37
+ process.on('SIGTERM', handler);
38
+ return {
39
+ shutdown,
40
+ unregister: () => {
41
+ process.removeListener('SIGINT', handler);
42
+ process.removeListener('SIGTERM', handler);
43
+ },
44
+ };
45
+ };
46
+ exports.createActiveMQShutdown = createActiveMQShutdown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "podverse-mq",
3
- "version": "5.1.12-alpha.0",
3
+ "version": "5.1.12",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -17,10 +17,10 @@
17
17
  "license": "AGPLv3",
18
18
  "dependencies": {
19
19
  "module-alias": "^2.2.3",
20
- "podverse-external-services": "^5.1.12-alpha.0",
21
- "podverse-helpers": "^5.1.12-alpha.0",
22
- "podverse-orm": "^5.1.12-alpha.0",
23
- "podverse-parser": "^5.1.12-alpha.0",
20
+ "podverse-external-services": "^5.1.12",
21
+ "podverse-helpers": "^5.1.12",
22
+ "podverse-orm": "^5.1.12",
23
+ "podverse-parser": "^5.1.12",
24
24
  "rhea": "^2.0.6",
25
25
  "ws": "^8.18.3"
26
26
  },