wsp-ms-core 1.0.86 → 1.0.87-b1
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 +77 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +77 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -645,9 +645,12 @@ declare class DefaultMysqlInboxRunner {
|
|
|
645
645
|
private readonly eventManager;
|
|
646
646
|
private readonly interval;
|
|
647
647
|
private readonly maxEvents;
|
|
648
|
-
private
|
|
648
|
+
private topics;
|
|
649
649
|
constructor(uowFactory: BasicUnitOfWorkFactory, eventManager: EventManager);
|
|
650
650
|
private saveEvent;
|
|
651
|
+
subscribeTo(topic: string): void;
|
|
652
|
+
private process;
|
|
653
|
+
start(): Promise<void>;
|
|
651
654
|
}
|
|
652
655
|
|
|
653
656
|
interface ExchangeRatesProps {
|
package/dist/index.d.ts
CHANGED
|
@@ -645,9 +645,12 @@ declare class DefaultMysqlInboxRunner {
|
|
|
645
645
|
private readonly eventManager;
|
|
646
646
|
private readonly interval;
|
|
647
647
|
private readonly maxEvents;
|
|
648
|
-
private
|
|
648
|
+
private topics;
|
|
649
649
|
constructor(uowFactory: BasicUnitOfWorkFactory, eventManager: EventManager);
|
|
650
650
|
private saveEvent;
|
|
651
|
+
subscribeTo(topic: string): void;
|
|
652
|
+
private process;
|
|
653
|
+
start(): Promise<void>;
|
|
651
654
|
}
|
|
652
655
|
|
|
653
656
|
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,10 +1782,61 @@ 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) {
|
|
1790
|
-
this.
|
|
1839
|
+
this.topics = [];
|
|
1791
1840
|
this.uowFactory = uowFactory;
|
|
1792
1841
|
this.eventManager = eventManager;
|
|
1793
1842
|
this.interval = Number(process.env.OUTBOX_RUNNER_INTERVAL_MS || 5e3);
|
|
@@ -1812,6 +1861,31 @@ var DefaultMysqlInboxRunner = class {
|
|
|
1812
1861
|
await repository.update(record);
|
|
1813
1862
|
}
|
|
1814
1863
|
}
|
|
1864
|
+
subscribeTo(topic) {
|
|
1865
|
+
this.topics.push(topic);
|
|
1866
|
+
}
|
|
1867
|
+
async process() {
|
|
1868
|
+
const uow = await this.uowFactory.create();
|
|
1869
|
+
const inboxRepository = new InboxMysqlRepository(uow.connection);
|
|
1870
|
+
await uow.execute(async () => {
|
|
1871
|
+
for (let topic of this.topics) {
|
|
1872
|
+
try {
|
|
1873
|
+
this.eventManager.route(topic, async (e) => {
|
|
1874
|
+
await this.saveEvent(e, inboxRepository);
|
|
1875
|
+
});
|
|
1876
|
+
} catch (error) {
|
|
1877
|
+
console.log(error.toString());
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
await this.eventManager.start();
|
|
1881
|
+
});
|
|
1882
|
+
}
|
|
1883
|
+
async start() {
|
|
1884
|
+
console.log("[inbox-runner]: start");
|
|
1885
|
+
for (; ; ) {
|
|
1886
|
+
await this.process();
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1815
1889
|
};
|
|
1816
1890
|
|
|
1817
1891
|
// src/utils/ExchangeRates.ts
|