wsp-ms-core 1.0.85 → 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.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 errors;
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 errors;
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
@@ -1739,7 +1739,6 @@ var DefaultMysqlOutboxRunner = class {
1739
1739
  async sleep() {
1740
1740
  return new Promise((r) => setTimeout(r, this.maxEvents));
1741
1741
  }
1742
- // HACER QUE PUEDA MANDAR UN OBJETO NO UN STRING POR KAFKA
1743
1742
  async processOutboxRecord(e, eventBusRepository) {
1744
1743
  try {
1745
1744
  e.markProcessing();
@@ -1783,10 +1782,61 @@ var DefaultMysqlOutboxRunner = class {
1783
1782
  }
1784
1783
  };
1785
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
+
1786
1836
  // src/infrastructure/runners/default-mysql-inbox-runner.ts
1787
1837
  var DefaultMysqlInboxRunner = class {
1788
1838
  constructor(uowFactory, eventManager) {
1789
- this.errors = [];
1839
+ this.topics = [];
1790
1840
  this.uowFactory = uowFactory;
1791
1841
  this.eventManager = eventManager;
1792
1842
  this.interval = Number(process.env.OUTBOX_RUNNER_INTERVAL_MS || 5e3);
@@ -1811,6 +1861,31 @@ var DefaultMysqlInboxRunner = class {
1811
1861
  await repository.update(record);
1812
1862
  }
1813
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
+ }
1814
1889
  };
1815
1890
 
1816
1891
  // src/utils/ExchangeRates.ts