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.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,15 +1855,76 @@ 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) {
|
|
1912
|
+
this.topics = [];
|
|
1863
1913
|
this.errors = [];
|
|
1864
1914
|
this.uowFactory = uowFactory;
|
|
1865
1915
|
this.eventManager = eventManager;
|
|
1866
1916
|
this.interval = Number(process.env.OUTBOX_RUNNER_INTERVAL_MS || 5e3);
|
|
1867
1917
|
this.maxEvents = Number(process.env.OUTBOX_RUNNER_MAX_EVENTS || 20);
|
|
1868
1918
|
}
|
|
1919
|
+
addError(error) {
|
|
1920
|
+
this.errors.push(error);
|
|
1921
|
+
}
|
|
1922
|
+
logErrors() {
|
|
1923
|
+
if (this.errors.length > 0) {
|
|
1924
|
+
console.error(this.errors);
|
|
1925
|
+
this.errors = [];
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1869
1928
|
async saveEvent(e, repository) {
|
|
1870
1929
|
let record = new InboxRecord(
|
|
1871
1930
|
UUID.create(),
|
|
@@ -1885,6 +1944,30 @@ var DefaultMysqlInboxRunner = class {
|
|
|
1885
1944
|
await repository.update(record);
|
|
1886
1945
|
}
|
|
1887
1946
|
}
|
|
1947
|
+
subscribeTo(topic) {
|
|
1948
|
+
this.topics.push(topic);
|
|
1949
|
+
}
|
|
1950
|
+
async process() {
|
|
1951
|
+
const uow = await this.uowFactory.create();
|
|
1952
|
+
const inboxRepository = new InboxMysqlRepository(uow.connection);
|
|
1953
|
+
await uow.execute(async () => {
|
|
1954
|
+
for (let topic of this.topics) {
|
|
1955
|
+
try {
|
|
1956
|
+
this.eventManager.route(topic, async (e) => {
|
|
1957
|
+
await this.saveEvent(e, inboxRepository);
|
|
1958
|
+
});
|
|
1959
|
+
} catch (error) {
|
|
1960
|
+
this.addError(error.toString());
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
});
|
|
1964
|
+
}
|
|
1965
|
+
async start() {
|
|
1966
|
+
console.log("[outbox-runner]: start");
|
|
1967
|
+
for (; ; ) {
|
|
1968
|
+
await this.process();
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1888
1971
|
};
|
|
1889
1972
|
|
|
1890
1973
|
// src/utils/ExchangeRates.ts
|