wsp-ms-core 1.0.86 → 1.0.87-beta-1.0
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 +85 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +85 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -645,9 +645,15 @@ declare class DefaultMysqlInboxRunner {
|
|
|
645
645
|
private readonly eventManager;
|
|
646
646
|
private readonly interval;
|
|
647
647
|
private readonly maxEvents;
|
|
648
|
+
private topics;
|
|
648
649
|
private errors;
|
|
649
650
|
constructor(uowFactory: BasicUnitOfWorkFactory, eventManager: EventManager);
|
|
651
|
+
private addError;
|
|
652
|
+
private logErrors;
|
|
650
653
|
private saveEvent;
|
|
654
|
+
subscribeTo(topic: string): void;
|
|
655
|
+
process(): Promise<void>;
|
|
656
|
+
start(): Promise<void>;
|
|
651
657
|
}
|
|
652
658
|
|
|
653
659
|
interface ExchangeRatesProps {
|
package/dist/index.d.ts
CHANGED
|
@@ -645,9 +645,15 @@ declare class DefaultMysqlInboxRunner {
|
|
|
645
645
|
private readonly eventManager;
|
|
646
646
|
private readonly interval;
|
|
647
647
|
private readonly maxEvents;
|
|
648
|
+
private topics;
|
|
648
649
|
private errors;
|
|
649
650
|
constructor(uowFactory: BasicUnitOfWorkFactory, eventManager: EventManager);
|
|
651
|
+
private addError;
|
|
652
|
+
private logErrors;
|
|
650
653
|
private saveEvent;
|
|
654
|
+
subscribeTo(topic: string): void;
|
|
655
|
+
process(): Promise<void>;
|
|
656
|
+
start(): Promise<void>;
|
|
651
657
|
}
|
|
652
658
|
|
|
653
659
|
interface ExchangeRatesProps {
|
package/dist/index.js
CHANGED
|
@@ -1609,7 +1609,6 @@ var KafkaManager = class extends EventManager {
|
|
|
1609
1609
|
producer: e.producer,
|
|
1610
1610
|
data: JSON.parse(e.message)
|
|
1611
1611
|
};
|
|
1612
|
-
console.log(evt);
|
|
1613
1612
|
try {
|
|
1614
1613
|
if (!this.producer) {
|
|
1615
1614
|
throw new InternalError(ErrorManager.APP_ERRORS.PROCESS, "Producer not initialized");
|
|
@@ -1740,7 +1739,6 @@ var DefaultMysqlOutboxRunner = class {
|
|
|
1740
1739
|
async sleep() {
|
|
1741
1740
|
return new Promise((r) => setTimeout(r, this.maxEvents));
|
|
1742
1741
|
}
|
|
1743
|
-
// HACER QUE PUEDA MANDAR UN OBJETO NO UN STRING POR KAFKA
|
|
1744
1742
|
async processOutboxRecord(e, eventBusRepository) {
|
|
1745
1743
|
try {
|
|
1746
1744
|
e.markProcessing();
|
|
@@ -1784,15 +1782,76 @@ var DefaultMysqlOutboxRunner = class {
|
|
|
1784
1782
|
}
|
|
1785
1783
|
};
|
|
1786
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
|
+
|
|
1787
1836
|
// src/infrastructure/runners/default-mysql-inbox-runner.ts
|
|
1788
1837
|
var DefaultMysqlInboxRunner = class {
|
|
1789
1838
|
constructor(uowFactory, eventManager) {
|
|
1839
|
+
this.topics = [];
|
|
1790
1840
|
this.errors = [];
|
|
1791
1841
|
this.uowFactory = uowFactory;
|
|
1792
1842
|
this.eventManager = eventManager;
|
|
1793
1843
|
this.interval = Number(process.env.OUTBOX_RUNNER_INTERVAL_MS || 5e3);
|
|
1794
1844
|
this.maxEvents = Number(process.env.OUTBOX_RUNNER_MAX_EVENTS || 20);
|
|
1795
1845
|
}
|
|
1846
|
+
addError(error) {
|
|
1847
|
+
this.errors.push(error);
|
|
1848
|
+
}
|
|
1849
|
+
logErrors() {
|
|
1850
|
+
if (this.errors.length > 0) {
|
|
1851
|
+
console.error(this.errors);
|
|
1852
|
+
this.errors = [];
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1796
1855
|
async saveEvent(e, repository) {
|
|
1797
1856
|
let record = new InboxRecord(
|
|
1798
1857
|
UUID.create(),
|
|
@@ -1812,6 +1871,30 @@ var DefaultMysqlInboxRunner = class {
|
|
|
1812
1871
|
await repository.update(record);
|
|
1813
1872
|
}
|
|
1814
1873
|
}
|
|
1874
|
+
subscribeTo(topic) {
|
|
1875
|
+
this.topics.push(topic);
|
|
1876
|
+
}
|
|
1877
|
+
async process() {
|
|
1878
|
+
const uow = await this.uowFactory.create();
|
|
1879
|
+
const inboxRepository = new InboxMysqlRepository(uow.connection);
|
|
1880
|
+
await uow.execute(async () => {
|
|
1881
|
+
for (let topic of this.topics) {
|
|
1882
|
+
try {
|
|
1883
|
+
this.eventManager.route(topic, async (e) => {
|
|
1884
|
+
await this.saveEvent(e, inboxRepository);
|
|
1885
|
+
});
|
|
1886
|
+
} catch (error) {
|
|
1887
|
+
this.addError(error.toString());
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
});
|
|
1891
|
+
}
|
|
1892
|
+
async start() {
|
|
1893
|
+
console.log("[outbox-runner]: start");
|
|
1894
|
+
for (; ; ) {
|
|
1895
|
+
await this.process();
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1815
1898
|
};
|
|
1816
1899
|
|
|
1817
1900
|
// src/utils/ExchangeRates.ts
|