@codefresh-io/eventbus 2.3.0 → 2.4.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.
Files changed (2) hide show
  1. package/lib/Store.js +27 -0
  2. package/package.json +1 -1
package/lib/Store.js CHANGED
@@ -30,6 +30,7 @@ class Store extends EventEmitter {
30
30
  this.ssl = 'POSTGRES_SSL_ENABLE' in process.env
31
31
  ? process.env.POSTGRES_SSL_ENABLE === 'true'
32
32
  : options.ssl;
33
+ this.disablePostgresForEventbus = process.env.DISABLE_POSTGRES_FOR_EVENTBUS === 'true';
33
34
  this.readyPromise = new Promise((resolve, reject) => {
34
35
  this.readyDeferred = {
35
36
  resolve: () => {
@@ -43,6 +44,9 @@ class Store extends EventEmitter {
43
44
  }
44
45
 
45
46
  async quit() {
47
+ if (this.disablePostgresForEventbus) {
48
+ return;
49
+ }
46
50
  debug(`Pool client state before closing. total: ${this.pool.totalCount}. idle: ${this.pool.idleCount}. active: ${this.pool.activeCount}`);
47
51
  await this.pool.end();
48
52
  debug(`Pool client state after closing. total: ${this.pool.totalCount}. idle: ${this.pool.idleCount}. active: ${this.pool.activeCount}`);
@@ -50,6 +54,10 @@ class Store extends EventEmitter {
50
54
  }
51
55
 
52
56
  init() {
57
+ if (this.disablePostgresForEventbus) {
58
+ debug(`Store is disabled. Skipping initialization of it`);
59
+ return;
60
+ }
53
61
  const config = {
54
62
  user: this.user,
55
63
  database: this.database,
@@ -120,7 +128,18 @@ class Store extends EventEmitter {
120
128
  }
121
129
  }
122
130
 
131
+ _emptyPgCursor() {
132
+ return {
133
+ count: () => 0,
134
+ next: () => false,
135
+ close: () => {},
136
+ };
137
+ }
138
+
123
139
  async save(eventName, event) {
140
+ if (this.disablePostgresForEventbus) {
141
+ return;
142
+ }
124
143
  let data = [
125
144
  { field: 'event', value: eventName },
126
145
  { field: 'props', value: _.get(event, 'props', {}) },
@@ -156,6 +175,10 @@ class Store extends EventEmitter {
156
175
  }
157
176
 
158
177
  async getAllAggregateEvents(aggregateId, fromIndex) {
178
+ if (this.disablePostgresForEventbus) {
179
+ debug('getAllAggregateEvents: return _emptyPgCursor');
180
+ return this._emptyPgCursor();
181
+ }
159
182
  try {
160
183
  const queryCondition = `WHERE id >= ${fromIndex} AND aggregate_id = '${aggregateId}'`;
161
184
 
@@ -176,6 +199,10 @@ class Store extends EventEmitter {
176
199
  }
177
200
 
178
201
  async getAllEventsByName(name, fromIndex) {
202
+ if (this.disablePostgresForEventbus) {
203
+ debug('getAllEventsByName: return _emptyPgCursor');
204
+ return this._emptyPgCursor();
205
+ }
179
206
  try {
180
207
  const queryCondition = `WHERE id >= ${fromIndex} AND event LIKE '${name}%'`;
181
208
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codefresh-io/eventbus",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {