wsp-ms-core 1.0.87 → 1.0.89
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 +79 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +79 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -641,13 +641,14 @@ declare class DefaultMysqlOutboxRunner {
|
|
|
641
641
|
}
|
|
642
642
|
|
|
643
643
|
declare class DefaultMysqlInboxRunner {
|
|
644
|
-
private readonly
|
|
644
|
+
private readonly databaseConnector;
|
|
645
645
|
private readonly eventManager;
|
|
646
|
-
private
|
|
647
|
-
|
|
648
|
-
private errors;
|
|
649
|
-
constructor(uowFactory: BasicUnitOfWorkFactory, eventManager: EventManager);
|
|
646
|
+
private topics;
|
|
647
|
+
constructor(databaseConnector: DatabaseConnector, eventManager: EventManager);
|
|
650
648
|
private saveEvent;
|
|
649
|
+
subscribeTo(topic: string): void;
|
|
650
|
+
private process;
|
|
651
|
+
start(): Promise<void>;
|
|
651
652
|
}
|
|
652
653
|
|
|
653
654
|
interface ExchangeRatesProps {
|
package/dist/index.d.ts
CHANGED
|
@@ -641,13 +641,14 @@ declare class DefaultMysqlOutboxRunner {
|
|
|
641
641
|
}
|
|
642
642
|
|
|
643
643
|
declare class DefaultMysqlInboxRunner {
|
|
644
|
-
private readonly
|
|
644
|
+
private readonly databaseConnector;
|
|
645
645
|
private readonly eventManager;
|
|
646
|
-
private
|
|
647
|
-
|
|
648
|
-
private errors;
|
|
649
|
-
constructor(uowFactory: BasicUnitOfWorkFactory, eventManager: EventManager);
|
|
646
|
+
private topics;
|
|
647
|
+
constructor(databaseConnector: DatabaseConnector, eventManager: EventManager);
|
|
650
648
|
private saveEvent;
|
|
649
|
+
subscribeTo(topic: string): void;
|
|
650
|
+
private process;
|
|
651
|
+
start(): Promise<void>;
|
|
651
652
|
}
|
|
652
653
|
|
|
653
654
|
interface ExchangeRatesProps {
|
package/dist/index.js
CHANGED
|
@@ -1739,7 +1739,6 @@ var DefaultMysqlOutboxRunner = class {
|
|
|
1739
1739
|
async sleep() {
|
|
1740
1740
|
return new Promise((r) => setTimeout(r, this.maxEvents));
|
|
1741
1741
|
}
|
|
1742
|
-
// HACER QUE PUEDA MANDAR UN OBJETO NO UN STRING POR KAFKA
|
|
1743
1742
|
async processOutboxRecord(e, eventBusRepository) {
|
|
1744
1743
|
try {
|
|
1745
1744
|
e.markProcessing();
|
|
@@ -1783,14 +1782,63 @@ var DefaultMysqlOutboxRunner = class {
|
|
|
1783
1782
|
}
|
|
1784
1783
|
};
|
|
1785
1784
|
|
|
1785
|
+
// src/infrastructure/inbox/InboxMysqlRepository.ts
|
|
1786
|
+
var InboxMysqlRepository = class {
|
|
1787
|
+
constructor(connection) {
|
|
1788
|
+
this.connection = connection;
|
|
1789
|
+
}
|
|
1790
|
+
recordToRowValues(record) {
|
|
1791
|
+
return [
|
|
1792
|
+
record.eventUuid.value,
|
|
1793
|
+
record.tenantUuid.value,
|
|
1794
|
+
record.topic,
|
|
1795
|
+
record.producer,
|
|
1796
|
+
record.payload,
|
|
1797
|
+
record.status.value,
|
|
1798
|
+
record.attempts,
|
|
1799
|
+
record.errorMessage,
|
|
1800
|
+
record.lastAttempt?.value ?? null,
|
|
1801
|
+
record.processedAt?.value ?? null,
|
|
1802
|
+
record.createdAt.value
|
|
1803
|
+
];
|
|
1804
|
+
}
|
|
1805
|
+
async create(record) {
|
|
1806
|
+
const values = this.recordToRowValues(record);
|
|
1807
|
+
await this.connection.query(
|
|
1808
|
+
`INSERT INTO events_inbox (event_uuid, tenant_uuid, topic, producer,
|
|
1809
|
+
payload, status, attempts, error_message, last_attempt, processed_at, created_at)
|
|
1810
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
1811
|
+
values
|
|
1812
|
+
);
|
|
1813
|
+
}
|
|
1814
|
+
async update(record) {
|
|
1815
|
+
const values = [record.status.value, record.attempts, record.errorMessage, record.processedAt?.value, record.lastAttempt?.value, record.eventUuid.value];
|
|
1816
|
+
await this.connection.query(
|
|
1817
|
+
`UPDATE events_inbox
|
|
1818
|
+
SET status = ?,
|
|
1819
|
+
attempts = ?,
|
|
1820
|
+
error_message = ?,
|
|
1821
|
+
processed_at = ?,
|
|
1822
|
+
last_attempt = ?
|
|
1823
|
+
WHERE event_uuid = ?`,
|
|
1824
|
+
values
|
|
1825
|
+
);
|
|
1826
|
+
}
|
|
1827
|
+
async listPending(limit) {
|
|
1828
|
+
const result = await this.connection.query(
|
|
1829
|
+
`SELECT * FROM events_inbox WHERE status IN ('PENDING','FAILED') AND events_inbox.processed_at IS NULL LIMIT ${limit}`,
|
|
1830
|
+
[]
|
|
1831
|
+
);
|
|
1832
|
+
return result.length > 0 ? result.map((r) => InboxRecord.reconstitute(r)) : [];
|
|
1833
|
+
}
|
|
1834
|
+
};
|
|
1835
|
+
|
|
1786
1836
|
// src/infrastructure/runners/default-mysql-inbox-runner.ts
|
|
1787
1837
|
var DefaultMysqlInboxRunner = class {
|
|
1788
|
-
constructor(
|
|
1789
|
-
this.
|
|
1790
|
-
this.
|
|
1838
|
+
constructor(databaseConnector, eventManager) {
|
|
1839
|
+
this.topics = [];
|
|
1840
|
+
this.databaseConnector = databaseConnector;
|
|
1791
1841
|
this.eventManager = eventManager;
|
|
1792
|
-
this.interval = Number(process.env.OUTBOX_RUNNER_INTERVAL_MS || 5e3);
|
|
1793
|
-
this.maxEvents = Number(process.env.OUTBOX_RUNNER_MAX_EVENTS || 20);
|
|
1794
1842
|
}
|
|
1795
1843
|
async saveEvent(e, repository) {
|
|
1796
1844
|
let record = new InboxRecord(
|
|
@@ -1811,6 +1859,31 @@ var DefaultMysqlInboxRunner = class {
|
|
|
1811
1859
|
await repository.update(record);
|
|
1812
1860
|
}
|
|
1813
1861
|
}
|
|
1862
|
+
subscribeTo(topic) {
|
|
1863
|
+
this.topics.push(topic);
|
|
1864
|
+
}
|
|
1865
|
+
async process() {
|
|
1866
|
+
for (let topic of this.topics) {
|
|
1867
|
+
try {
|
|
1868
|
+
this.eventManager.onSubscribe((data) => {
|
|
1869
|
+
console.log(data);
|
|
1870
|
+
});
|
|
1871
|
+
this.eventManager.onMessage((data) => {
|
|
1872
|
+
console.log(data);
|
|
1873
|
+
});
|
|
1874
|
+
this.eventManager.route(topic, async (e) => {
|
|
1875
|
+
await this.saveEvent(e, new InboxMysqlRepository(await this.databaseConnector.getConnection()));
|
|
1876
|
+
});
|
|
1877
|
+
} catch (error) {
|
|
1878
|
+
console.log(error.toString());
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
await this.eventManager.start();
|
|
1882
|
+
}
|
|
1883
|
+
async start() {
|
|
1884
|
+
console.log("[inbox-runner]: start");
|
|
1885
|
+
await this.process();
|
|
1886
|
+
}
|
|
1814
1887
|
};
|
|
1815
1888
|
|
|
1816
1889
|
// src/utils/ExchangeRates.ts
|