wsp-ms-core 1.0.87 → 1.0.88
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 -2
- 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 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1812,7 +1812,6 @@ var DefaultMysqlOutboxRunner = class {
|
|
|
1812
1812
|
async sleep() {
|
|
1813
1813
|
return new Promise((r) => setTimeout(r, this.maxEvents));
|
|
1814
1814
|
}
|
|
1815
|
-
// HACER QUE PUEDA MANDAR UN OBJETO NO UN STRING POR KAFKA
|
|
1816
1815
|
async processOutboxRecord(e, eventBusRepository) {
|
|
1817
1816
|
try {
|
|
1818
1817
|
e.markProcessing();
|
|
@@ -1856,10 +1855,61 @@ var DefaultMysqlOutboxRunner = class {
|
|
|
1856
1855
|
}
|
|
1857
1856
|
};
|
|
1858
1857
|
|
|
1858
|
+
// src/infrastructure/inbox/InboxMysqlRepository.ts
|
|
1859
|
+
var InboxMysqlRepository = class {
|
|
1860
|
+
constructor(connection) {
|
|
1861
|
+
this.connection = connection;
|
|
1862
|
+
}
|
|
1863
|
+
recordToRowValues(record) {
|
|
1864
|
+
return [
|
|
1865
|
+
record.eventUuid.value,
|
|
1866
|
+
record.tenantUuid.value,
|
|
1867
|
+
record.topic,
|
|
1868
|
+
record.producer,
|
|
1869
|
+
record.payload,
|
|
1870
|
+
record.status.value,
|
|
1871
|
+
record.attempts,
|
|
1872
|
+
record.errorMessage,
|
|
1873
|
+
record.lastAttempt?.value ?? null,
|
|
1874
|
+
record.processedAt?.value ?? null,
|
|
1875
|
+
record.createdAt.value
|
|
1876
|
+
];
|
|
1877
|
+
}
|
|
1878
|
+
async create(record) {
|
|
1879
|
+
const values = this.recordToRowValues(record);
|
|
1880
|
+
await this.connection.query(
|
|
1881
|
+
`INSERT INTO events_inbox (event_uuid, tenant_uuid, topic, producer,
|
|
1882
|
+
payload, status, attempts, error_message, last_attempt, processed_at, created_at)
|
|
1883
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
1884
|
+
values
|
|
1885
|
+
);
|
|
1886
|
+
}
|
|
1887
|
+
async update(record) {
|
|
1888
|
+
const values = [record.status.value, record.attempts, record.errorMessage, record.processedAt?.value, record.lastAttempt?.value, record.eventUuid.value];
|
|
1889
|
+
await this.connection.query(
|
|
1890
|
+
`UPDATE events_inbox
|
|
1891
|
+
SET status = ?,
|
|
1892
|
+
attempts = ?,
|
|
1893
|
+
error_message = ?,
|
|
1894
|
+
processed_at = ?,
|
|
1895
|
+
last_attempt = ?
|
|
1896
|
+
WHERE event_uuid = ?`,
|
|
1897
|
+
values
|
|
1898
|
+
);
|
|
1899
|
+
}
|
|
1900
|
+
async listPending(limit) {
|
|
1901
|
+
const result = await this.connection.query(
|
|
1902
|
+
`SELECT * FROM events_inbox WHERE status IN ('PENDING','FAILED') AND events_inbox.processed_at IS NULL LIMIT ${limit}`,
|
|
1903
|
+
[]
|
|
1904
|
+
);
|
|
1905
|
+
return result.length > 0 ? result.map((r) => InboxRecord.reconstitute(r)) : [];
|
|
1906
|
+
}
|
|
1907
|
+
};
|
|
1908
|
+
|
|
1859
1909
|
// src/infrastructure/runners/default-mysql-inbox-runner.ts
|
|
1860
1910
|
var DefaultMysqlInboxRunner = class {
|
|
1861
1911
|
constructor(uowFactory, eventManager) {
|
|
1862
|
-
this.
|
|
1912
|
+
this.topics = [];
|
|
1863
1913
|
this.uowFactory = uowFactory;
|
|
1864
1914
|
this.eventManager = eventManager;
|
|
1865
1915
|
this.interval = Number(process.env.OUTBOX_RUNNER_INTERVAL_MS || 5e3);
|
|
@@ -1884,6 +1934,31 @@ var DefaultMysqlInboxRunner = class {
|
|
|
1884
1934
|
await repository.update(record);
|
|
1885
1935
|
}
|
|
1886
1936
|
}
|
|
1937
|
+
subscribeTo(topic) {
|
|
1938
|
+
this.topics.push(topic);
|
|
1939
|
+
}
|
|
1940
|
+
async process() {
|
|
1941
|
+
const uow = await this.uowFactory.create();
|
|
1942
|
+
const inboxRepository = new InboxMysqlRepository(uow.connection);
|
|
1943
|
+
return await uow.execute(async () => {
|
|
1944
|
+
for (let topic of this.topics) {
|
|
1945
|
+
try {
|
|
1946
|
+
this.eventManager.route(topic, async (e) => {
|
|
1947
|
+
await this.saveEvent(e, inboxRepository);
|
|
1948
|
+
});
|
|
1949
|
+
} catch (error) {
|
|
1950
|
+
console.log(error.toString());
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
await this.eventManager.start();
|
|
1954
|
+
});
|
|
1955
|
+
}
|
|
1956
|
+
async start() {
|
|
1957
|
+
console.log("[inbox-runner]: start");
|
|
1958
|
+
for (; ; ) {
|
|
1959
|
+
await this.process();
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1887
1962
|
};
|
|
1888
1963
|
|
|
1889
1964
|
// src/utils/ExchangeRates.ts
|