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.d.ts
CHANGED
|
@@ -579,6 +579,22 @@ declare class MysqlConnection implements DatabaseConnection<string, any[], RowDa
|
|
|
579
579
|
close(): Promise<void>;
|
|
580
580
|
}
|
|
581
581
|
|
|
582
|
+
declare class DefaultOutboxRunner {
|
|
583
|
+
private readonly uowFactory;
|
|
584
|
+
private readonly eventBusRepository;
|
|
585
|
+
private readonly eventManager;
|
|
586
|
+
private readonly interval;
|
|
587
|
+
private readonly maxEvents;
|
|
588
|
+
private errors;
|
|
589
|
+
constructor(uowFactory: BasicUnitOfWorkFactory, eventBusRepository: EventBusRepository, eventManager: EventManager);
|
|
590
|
+
private addError;
|
|
591
|
+
private logErrors;
|
|
592
|
+
private sleep;
|
|
593
|
+
private processOutboxRecord;
|
|
594
|
+
private process;
|
|
595
|
+
start(): Promise<void>;
|
|
596
|
+
}
|
|
597
|
+
|
|
582
598
|
interface ExchangeRatesProps {
|
|
583
599
|
base: Currency;
|
|
584
600
|
rates: Record<string, number>;
|
|
@@ -603,4 +619,4 @@ declare class StringVars {
|
|
|
603
619
|
}): string;
|
|
604
620
|
}
|
|
605
621
|
|
|
606
|
-
export { BaseEntity, BaseEvent, BaseObject, BasicUnitOfWork, BasicUnitOfWorkFactory, Country, Currency, DatabaseConnection, DatabaseConnector, DateTime, DomainEntity, DomainError, DomainEvent, Email, ErrorManager, ErrorManagerHandleResult, ErrorTemplate, EventBus, EventBusMysqlRepository, EventBusRepository, EventManager, EventManagerConnection, ExchangeRates, FatalError, HttpController, HttpHealthCheckController, HttpNotFoundController, HttpRequest, HttpResponse, IntegrationEvent, InternalError, KafkaManager, Language, Logger, MysqlConnection, MysqlConnector, OutboxRecord, PaymentGateway, PaymentStatus, Price, ProcessStatus, RouteCallback, RoutesCallbackList, StringVars, UUID, UnitOfWork, UploadedFile, UsageError, ValueObject, adaptExpressErrorHandler, adaptExpressRoute };
|
|
622
|
+
export { BaseEntity, BaseEvent, BaseObject, BasicUnitOfWork, BasicUnitOfWorkFactory, Country, Currency, DatabaseConnection, DatabaseConnector, DateTime, DefaultOutboxRunner, DomainEntity, DomainError, DomainEvent, Email, ErrorManager, ErrorManagerHandleResult, ErrorTemplate, EventBus, EventBusMysqlRepository, EventBusRepository, EventManager, EventManagerConnection, ExchangeRates, FatalError, HttpController, HttpHealthCheckController, HttpNotFoundController, HttpRequest, HttpResponse, IntegrationEvent, InternalError, KafkaManager, Language, Logger, MysqlConnection, MysqlConnector, OutboxRecord, PaymentGateway, PaymentStatus, Price, ProcessStatus, RouteCallback, RoutesCallbackList, StringVars, UUID, UnitOfWork, UploadedFile, UsageError, ValueObject, adaptExpressErrorHandler, adaptExpressRoute };
|
package/dist/index.js
CHANGED
|
@@ -1524,7 +1524,7 @@ var _MysqlConnector = class _MysqlConnector {
|
|
|
1524
1524
|
password: process.env.DB_PASSWORD,
|
|
1525
1525
|
database: process.env.DB_DATABASE,
|
|
1526
1526
|
dateStrings: true,
|
|
1527
|
-
connectionLimit: Number(process.env.DB_POOL_SIZE
|
|
1527
|
+
connectionLimit: Number(process.env.DB_POOL_SIZE ?? _MysqlConnector.DEFAULT_POOL_SIZE),
|
|
1528
1528
|
decimalNumbers: true
|
|
1529
1529
|
});
|
|
1530
1530
|
}
|
|
@@ -1591,6 +1591,64 @@ var MysqlConnection = class {
|
|
|
1591
1591
|
}
|
|
1592
1592
|
};
|
|
1593
1593
|
|
|
1594
|
+
// src/infrastructure/runners/default-outbox-runner.ts
|
|
1595
|
+
var DefaultOutboxRunner = class {
|
|
1596
|
+
constructor(uowFactory, eventBusRepository, eventManager) {
|
|
1597
|
+
this.uowFactory = uowFactory;
|
|
1598
|
+
this.eventBusRepository = eventBusRepository;
|
|
1599
|
+
this.eventManager = eventManager;
|
|
1600
|
+
this.interval = Number(process.env.OUTBOX_RUNNER_INTERVAL_MS || 5e3);
|
|
1601
|
+
this.maxEvents = Number(process.env.OUTBOX_RUNNER_MAX_EVENTS || 20);
|
|
1602
|
+
}
|
|
1603
|
+
addError(error) {
|
|
1604
|
+
this.errors.push(error);
|
|
1605
|
+
}
|
|
1606
|
+
logErrors() {
|
|
1607
|
+
if (this.errors.length > 0) {
|
|
1608
|
+
console.error(this.errors);
|
|
1609
|
+
this.errors = [];
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
async sleep() {
|
|
1613
|
+
return new Promise((r) => setTimeout(r, this.maxEvents));
|
|
1614
|
+
}
|
|
1615
|
+
async processOutboxRecord(e) {
|
|
1616
|
+
try {
|
|
1617
|
+
e.markProcessing();
|
|
1618
|
+
await this.eventBusRepository.update(e);
|
|
1619
|
+
await this.eventManager.send(e.topic, e.payload);
|
|
1620
|
+
e.markProcessed();
|
|
1621
|
+
} catch (error) {
|
|
1622
|
+
const type = String(error.type);
|
|
1623
|
+
e.markWithError(type);
|
|
1624
|
+
throw new Error(type);
|
|
1625
|
+
} finally {
|
|
1626
|
+
await this.eventBusRepository.update(e);
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
async process() {
|
|
1630
|
+
const uow = await this.uowFactory.create();
|
|
1631
|
+
await uow.execute(async () => {
|
|
1632
|
+
const records = await this.eventBusRepository.listPending(this.maxEvents);
|
|
1633
|
+
for (let record of records) {
|
|
1634
|
+
try {
|
|
1635
|
+
await this.processOutboxRecord(record);
|
|
1636
|
+
} catch (error) {
|
|
1637
|
+
this.addError({ eventUuid: record.eventUuid.value, error: error.toString() });
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
this.logErrors();
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
async start() {
|
|
1644
|
+
console.log("[outbox-runner]: start");
|
|
1645
|
+
for (; ; ) {
|
|
1646
|
+
await this.process();
|
|
1647
|
+
await this.sleep();
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
};
|
|
1651
|
+
|
|
1594
1652
|
// src/utils/ExchangeRates.ts
|
|
1595
1653
|
var ExchangeRates = class _ExchangeRates extends BaseObject {
|
|
1596
1654
|
constructor(props) {
|
|
@@ -1650,6 +1708,7 @@ export {
|
|
|
1650
1708
|
Country,
|
|
1651
1709
|
Currency,
|
|
1652
1710
|
DateTime,
|
|
1711
|
+
DefaultOutboxRunner,
|
|
1653
1712
|
DomainEntity,
|
|
1654
1713
|
DomainError,
|
|
1655
1714
|
DomainEvent,
|