wsp-ms-core 1.0.86 → 1.0.87-beta-1.2
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 +76 -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 +76 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1682,7 +1682,6 @@ var KafkaManager = class extends EventManager {
|
|
|
1682
1682
|
producer: e.producer,
|
|
1683
1683
|
data: JSON.parse(e.message)
|
|
1684
1684
|
};
|
|
1685
|
-
console.log(evt);
|
|
1686
1685
|
try {
|
|
1687
1686
|
if (!this.producer) {
|
|
1688
1687
|
throw new InternalError(ErrorManager.APP_ERRORS.PROCESS, "Producer not initialized");
|
|
@@ -1813,7 +1812,6 @@ var DefaultMysqlOutboxRunner = class {
|
|
|
1813
1812
|
async sleep() {
|
|
1814
1813
|
return new Promise((r) => setTimeout(r, this.maxEvents));
|
|
1815
1814
|
}
|
|
1816
|
-
// HACER QUE PUEDA MANDAR UN OBJETO NO UN STRING POR KAFKA
|
|
1817
1815
|
async processOutboxRecord(e, eventBusRepository) {
|
|
1818
1816
|
try {
|
|
1819
1817
|
e.markProcessing();
|
|
@@ -1857,10 +1855,61 @@ var DefaultMysqlOutboxRunner = class {
|
|
|
1857
1855
|
}
|
|
1858
1856
|
};
|
|
1859
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
|
+
|
|
1860
1909
|
// src/infrastructure/runners/default-mysql-inbox-runner.ts
|
|
1861
1910
|
var DefaultMysqlInboxRunner = class {
|
|
1862
1911
|
constructor(uowFactory, eventManager) {
|
|
1863
|
-
this.
|
|
1912
|
+
this.topics = [];
|
|
1864
1913
|
this.uowFactory = uowFactory;
|
|
1865
1914
|
this.eventManager = eventManager;
|
|
1866
1915
|
this.interval = Number(process.env.OUTBOX_RUNNER_INTERVAL_MS || 5e3);
|
|
@@ -1885,6 +1934,30 @@ var DefaultMysqlInboxRunner = class {
|
|
|
1885
1934
|
await repository.update(record);
|
|
1886
1935
|
}
|
|
1887
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
|
+
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
|
+
});
|
|
1954
|
+
}
|
|
1955
|
+
async start() {
|
|
1956
|
+
console.log("[inbox-runner]: start");
|
|
1957
|
+
for (; ; ) {
|
|
1958
|
+
await this.process();
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1888
1961
|
};
|
|
1889
1962
|
|
|
1890
1963
|
// src/utils/ExchangeRates.ts
|