@rvoh/psychic-workers 0.4.0 → 0.4.1

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.
@@ -138,7 +138,8 @@ class Background {
138
138
  * Shuts down workers, closes all redis connections
139
139
  */
140
140
  async shutdown() {
141
- index_js_1.default.getOrFail().psychicApp.logger.info(`[psychic-workers] shutdown`);
141
+ if (!EnvInternal_js_1.default.isTest)
142
+ psychic_1.PsychicApp.log(`[psychic-workers] shutdown`);
142
143
  const psychicWorkersApp = index_js_1.default.getOrFail();
143
144
  for (const hook of psychicWorkersApp.hooks.workerShutdown) {
144
145
  await hook();
@@ -150,12 +151,19 @@ class Background {
150
151
  * closes all redis connections for workers and queues
151
152
  */
152
153
  async closeAllRedisConnections() {
153
- index_js_1.default.getOrFail().psychicApp.logger.info(`[psychic-workers] closeAllRedisConnections`);
154
+ if (!EnvInternal_js_1.default.isTest)
155
+ psychic_1.PsychicApp.log(`[psychic-workers] closeAllRedisConnections`);
154
156
  for (const worker of this.workers) {
155
157
  await worker.close();
156
158
  }
157
159
  for (const connection of this.redisConnections) {
158
- await connection.quit();
160
+ try {
161
+ await connection.quit();
162
+ }
163
+ catch (error) {
164
+ if (!EnvInternal_js_1.default.isTest)
165
+ psychic_1.PsychicApp.logWithLevel('error', `[psychic-workers] error quitting Redis:`, error);
166
+ }
159
167
  }
160
168
  }
161
169
  /**
@@ -366,13 +374,15 @@ class Background {
366
374
  work() {
367
375
  this.connect({ activateWorkers: true });
368
376
  process.on('SIGTERM', () => {
369
- index_js_1.default.getOrFail().psychicApp.logger.info('[psychic-workers] handle SIGTERM');
377
+ if (!EnvInternal_js_1.default.isTest)
378
+ psychic_1.PsychicApp.log('[psychic-workers] handle SIGTERM');
370
379
  void this.shutdownAndExit()
371
380
  .then(() => { })
372
381
  .catch(() => { });
373
382
  });
374
383
  process.on('SIGINT', () => {
375
- index_js_1.default.getOrFail().psychicApp.logger.info('[psychic-workers] handle SIGINT');
384
+ if (!EnvInternal_js_1.default.isTest)
385
+ psychic_1.PsychicApp.log('[psychic-workers] handle SIGINT');
376
386
  void this.shutdownAndExit()
377
387
  .then(() => { })
378
388
  .catch(() => { });
@@ -134,7 +134,8 @@ export class Background {
134
134
  * Shuts down workers, closes all redis connections
135
135
  */
136
136
  async shutdown() {
137
- PsychicAppWorkers.getOrFail().psychicApp.logger.info(`[psychic-workers] shutdown`);
137
+ if (!EnvInternal.isTest)
138
+ PsychicApp.log(`[psychic-workers] shutdown`);
138
139
  const psychicWorkersApp = PsychicAppWorkers.getOrFail();
139
140
  for (const hook of psychicWorkersApp.hooks.workerShutdown) {
140
141
  await hook();
@@ -146,12 +147,19 @@ export class Background {
146
147
  * closes all redis connections for workers and queues
147
148
  */
148
149
  async closeAllRedisConnections() {
149
- PsychicAppWorkers.getOrFail().psychicApp.logger.info(`[psychic-workers] closeAllRedisConnections`);
150
+ if (!EnvInternal.isTest)
151
+ PsychicApp.log(`[psychic-workers] closeAllRedisConnections`);
150
152
  for (const worker of this.workers) {
151
153
  await worker.close();
152
154
  }
153
155
  for (const connection of this.redisConnections) {
154
- await connection.quit();
156
+ try {
157
+ await connection.quit();
158
+ }
159
+ catch (error) {
160
+ if (!EnvInternal.isTest)
161
+ PsychicApp.logWithLevel('error', `[psychic-workers] error quitting Redis:`, error);
162
+ }
155
163
  }
156
164
  }
157
165
  /**
@@ -362,13 +370,15 @@ export class Background {
362
370
  work() {
363
371
  this.connect({ activateWorkers: true });
364
372
  process.on('SIGTERM', () => {
365
- PsychicAppWorkers.getOrFail().psychicApp.logger.info('[psychic-workers] handle SIGTERM');
373
+ if (!EnvInternal.isTest)
374
+ PsychicApp.log('[psychic-workers] handle SIGTERM');
366
375
  void this.shutdownAndExit()
367
376
  .then(() => { })
368
377
  .catch(() => { });
369
378
  });
370
379
  process.on('SIGINT', () => {
371
- PsychicAppWorkers.getOrFail().psychicApp.logger.info('[psychic-workers] handle SIGINT');
380
+ if (!EnvInternal.isTest)
381
+ PsychicApp.log('[psychic-workers] handle SIGINT');
372
382
  void this.shutdownAndExit()
373
383
  .then(() => { })
374
384
  .catch(() => { });
@@ -1,6 +1,6 @@
1
1
  import { Env } from '@rvoh/dream';
2
2
  declare const EnvInternal: Env<{
3
3
  string: "NODE_ENV" | "PSYCHIC_CORE_DEVELOPMENT";
4
- boolean: "DEBUG" | "PSYCHIC_CORE_DEVELOPMENT" | "REALLY_TEST_BACKGROUND_QUEUE";
5
- }, "NODE_ENV" | "PSYCHIC_CORE_DEVELOPMENT", never, "PSYCHIC_CORE_DEVELOPMENT" | "DEBUG" | "REALLY_TEST_BACKGROUND_QUEUE">;
4
+ boolean: "REALLY_TEST_BACKGROUND_QUEUE";
5
+ }, "NODE_ENV" | "PSYCHIC_CORE_DEVELOPMENT", never, "REALLY_TEST_BACKGROUND_QUEUE">;
6
6
  export default EnvInternal;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "type": "module",
3
3
  "name": "@rvoh/psychic-workers",
4
4
  "description": "Background job system for Psychic applications",
5
- "version": "0.4.0",
5
+ "version": "0.4.1",
6
6
  "author": "RVO Health",
7
7
  "repository": {
8
8
  "type": "git",
@@ -73,4 +73,4 @@
73
73
  "vitest": "^3.1.1"
74
74
  },
75
75
  "packageManager": "yarn@4.7.0"
76
- }
76
+ }