wsp-ms-core 1.0.78-beta-2 → 1.0.78-beta-3
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 +61 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +60 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
+
DefaultOutboxRunner: () => DefaultOutboxRunner,
|
|
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
|
|
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-outbox-runner.ts
|
|
1666
|
+
var DefaultOutboxRunner = class {
|
|
1667
|
+
constructor(uowFactory, eventBusRepository, eventManager) {
|
|
1668
|
+
this.uowFactory = uowFactory;
|
|
1669
|
+
this.eventBusRepository = eventBusRepository;
|
|
1670
|
+
this.eventManager = eventManager;
|
|
1671
|
+
this.interval = Number(process.env.OUTBOX_RUNNER_INTERVAL_MS || 5e3);
|
|
1672
|
+
this.maxEvents = Number(process.env.OUTBOX_RUNNER_MAX_EVENTS || 20);
|
|
1673
|
+
}
|
|
1674
|
+
addError(error) {
|
|
1675
|
+
this.errors.push(error);
|
|
1676
|
+
}
|
|
1677
|
+
logErrors() {
|
|
1678
|
+
if (this.errors.length > 0) {
|
|
1679
|
+
console.error(this.errors);
|
|
1680
|
+
this.errors = [];
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
async sleep() {
|
|
1684
|
+
return new Promise((r) => setTimeout(r, this.maxEvents));
|
|
1685
|
+
}
|
|
1686
|
+
async processOutboxRecord(e) {
|
|
1687
|
+
try {
|
|
1688
|
+
e.markProcessing();
|
|
1689
|
+
await this.eventBusRepository.update(e);
|
|
1690
|
+
await this.eventManager.send(e.topic, e.payload);
|
|
1691
|
+
e.markProcessed();
|
|
1692
|
+
} catch (error) {
|
|
1693
|
+
const type = String(error.type);
|
|
1694
|
+
e.markWithError(type);
|
|
1695
|
+
throw new Error(type);
|
|
1696
|
+
} finally {
|
|
1697
|
+
await this.eventBusRepository.update(e);
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
async process() {
|
|
1701
|
+
const uow = await this.uowFactory.create();
|
|
1702
|
+
await uow.execute(async () => {
|
|
1703
|
+
const records = await this.eventBusRepository.listPending(this.maxEvents);
|
|
1704
|
+
for (let record of records) {
|
|
1705
|
+
try {
|
|
1706
|
+
await this.processOutboxRecord(record);
|
|
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
|
+
DefaultOutboxRunner,
|
|
1724
1784
|
DomainEntity,
|
|
1725
1785
|
DomainError,
|
|
1726
1786
|
DomainEvent,
|