wsp-ms-core 1.0.88 → 1.0.90

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 CHANGED
@@ -1908,56 +1908,53 @@ var InboxMysqlRepository = class {
1908
1908
 
1909
1909
  // src/infrastructure/runners/default-mysql-inbox-runner.ts
1910
1910
  var DefaultMysqlInboxRunner = class {
1911
- constructor(uowFactory, eventManager) {
1911
+ constructor(databaseConnector, eventManager) {
1912
1912
  this.topics = [];
1913
- this.uowFactory = uowFactory;
1913
+ this.databaseConnector = databaseConnector;
1914
1914
  this.eventManager = eventManager;
1915
- this.interval = Number(process.env.OUTBOX_RUNNER_INTERVAL_MS || 5e3);
1916
- this.maxEvents = Number(process.env.OUTBOX_RUNNER_MAX_EVENTS || 20);
1917
1915
  }
1918
1916
  async saveEvent(e, repository) {
1919
- let record = new InboxRecord(
1920
- UUID.create(),
1921
- e.tenant,
1922
- e.topic,
1923
- e.producer,
1924
- JSON.stringify(e.message),
1925
- ProcessStatus.PENDING
1926
- );
1927
1917
  try {
1918
+ let record = new InboxRecord(
1919
+ UUID.create(),
1920
+ e.tenant,
1921
+ e.topic,
1922
+ e.producer,
1923
+ JSON.stringify(e.message),
1924
+ ProcessStatus.PENDING
1925
+ );
1928
1926
  await repository.create(record);
1929
1927
  } catch (error) {
1930
- const type = String(error.type);
1931
- record.markWithError(type);
1932
- throw new Error(type);
1933
- } finally {
1934
- await repository.update(record);
1928
+ throw new Error(String(error.type));
1935
1929
  }
1936
1930
  }
1937
1931
  subscribeTo(topic) {
1938
1932
  this.topics.push(topic);
1939
1933
  }
1940
1934
  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
- }
1935
+ for (let topic of this.topics) {
1936
+ try {
1937
+ this.eventManager.onSubscribe((data) => {
1938
+ console.log(data);
1939
+ });
1940
+ this.eventManager.onMessage((data) => {
1941
+ console.log(data);
1942
+ });
1943
+ this.eventManager.onError((data) => {
1944
+ console.log(data);
1945
+ });
1946
+ this.eventManager.route(topic, async (e) => {
1947
+ await this.saveEvent(e, new InboxMysqlRepository(await this.databaseConnector.getConnection()));
1948
+ });
1949
+ } catch (error) {
1950
+ console.log(error.toString());
1952
1951
  }
1953
- await this.eventManager.start();
1954
- });
1952
+ }
1953
+ await this.eventManager.start();
1955
1954
  }
1956
1955
  async start() {
1957
1956
  console.log("[inbox-runner]: start");
1958
- for (; ; ) {
1959
- await this.process();
1960
- }
1957
+ await this.process();
1961
1958
  }
1962
1959
  };
1963
1960