wsp-ms-core 1.0.78-beta-2 → 1.0.78-beta-4

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/index.cjs CHANGED
@@ -36,6 +36,7 @@ __export(src_exports, {
36
36
  Country: () => Country,
37
37
  Currency: () => Currency,
38
38
  DateTime: () => DateTime,
39
+ DefaultMysqlOutboxRunner: () => DefaultMysqlOutboxRunner,
39
40
  DomainEntity: () => DomainEntity,
40
41
  DomainError: () => DomainError,
41
42
  DomainEvent: () => DomainEvent,
@@ -1594,7 +1595,7 @@ var _MysqlConnector = class _MysqlConnector {
1594
1595
  password: process.env.DB_PASSWORD,
1595
1596
  database: process.env.DB_DATABASE,
1596
1597
  dateStrings: true,
1597
- connectionLimit: Number(process.env.DB_POOL_SIZE) || _MysqlConnector.DEFAULT_POOL_SIZE,
1598
+ connectionLimit: Number(process.env.DB_POOL_SIZE ?? _MysqlConnector.DEFAULT_POOL_SIZE),
1598
1599
  decimalNumbers: true
1599
1600
  });
1600
1601
  }
@@ -1661,6 +1662,64 @@ var MysqlConnection = class {
1661
1662
  }
1662
1663
  };
1663
1664
 
1665
+ // src/infrastructure/runners/default-mysql-outbox-runner.ts
1666
+ var DefaultMysqlOutboxRunner = class {
1667
+ constructor(uowFactory, eventManager) {
1668
+ this.uowFactory = uowFactory;
1669
+ this.eventManager = eventManager;
1670
+ this.interval = Number(process.env.OUTBOX_RUNNER_INTERVAL_MS || 5e3);
1671
+ this.maxEvents = Number(process.env.OUTBOX_RUNNER_MAX_EVENTS || 20);
1672
+ }
1673
+ addError(error) {
1674
+ this.errors.push(error);
1675
+ }
1676
+ logErrors() {
1677
+ if (this.errors.length > 0) {
1678
+ console.error(this.errors);
1679
+ this.errors = [];
1680
+ }
1681
+ }
1682
+ async sleep() {
1683
+ return new Promise((r) => setTimeout(r, this.maxEvents));
1684
+ }
1685
+ async processOutboxRecord(e, eventBusRepository) {
1686
+ try {
1687
+ e.markProcessing();
1688
+ await eventBusRepository.update(e);
1689
+ await this.eventManager.send(e.topic, e.payload);
1690
+ e.markProcessed();
1691
+ } catch (error) {
1692
+ const type = String(error.type);
1693
+ e.markWithError(type);
1694
+ throw new Error(type);
1695
+ } finally {
1696
+ await eventBusRepository.update(e);
1697
+ }
1698
+ }
1699
+ async process() {
1700
+ const uow = await this.uowFactory.create();
1701
+ const eventBusRepository = new EventBusMysqlRepository(uow.connection);
1702
+ await uow.execute(async () => {
1703
+ const records = await eventBusRepository.listPending(this.maxEvents);
1704
+ for (let record of records) {
1705
+ try {
1706
+ await this.processOutboxRecord(record, eventBusRepository);
1707
+ } catch (error) {
1708
+ this.addError({ eventUuid: record.eventUuid.value, error: error.toString() });
1709
+ }
1710
+ }
1711
+ this.logErrors();
1712
+ });
1713
+ }
1714
+ async start() {
1715
+ console.log("[outbox-runner]: start");
1716
+ for (; ; ) {
1717
+ await this.process();
1718
+ await this.sleep();
1719
+ }
1720
+ }
1721
+ };
1722
+
1664
1723
  // src/utils/ExchangeRates.ts
1665
1724
  var ExchangeRates = class _ExchangeRates extends BaseObject {
1666
1725
  constructor(props) {
@@ -1721,6 +1780,7 @@ var ExchangeRates = class _ExchangeRates extends BaseObject {
1721
1780
  Country,
1722
1781
  Currency,
1723
1782
  DateTime,
1783
+ DefaultMysqlOutboxRunner,
1724
1784
  DomainEntity,
1725
1785
  DomainError,
1726
1786
  DomainEvent,