@rvoh/psychic-workers 0.4.0 → 0.4.2

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
  /**
@@ -317,7 +325,6 @@ class Background {
317
325
  /////////////////////////
318
326
  const namedQueueOptionsMap = nativeBullMQ.namedQueueOptions || {};
319
327
  Object.keys(namedQueueOptionsMap).forEach(queueName => {
320
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
321
328
  const namedQueueOptions = namedQueueOptionsMap[queueName];
322
329
  if (namedQueueOptions.queueConnection)
323
330
  this.redisConnections.push(namedQueueOptions.queueConnection);
@@ -364,19 +371,27 @@ class Background {
364
371
  * starts background workers
365
372
  */
366
373
  work() {
367
- this.connect({ activateWorkers: true });
374
+ process.on('uncaughtException', (error) => {
375
+ psychic_1.PsychicApp.log('[psychic-workers] uncaughtException:', error);
376
+ });
377
+ process.on('unhandledRejection', (error) => {
378
+ psychic_1.PsychicApp.log('[psychic-workers] unhandledRejection:', error);
379
+ });
368
380
  process.on('SIGTERM', () => {
369
- index_js_1.default.getOrFail().psychicApp.logger.info('[psychic-workers] handle SIGTERM');
381
+ if (!EnvInternal_js_1.default.isTest)
382
+ psychic_1.PsychicApp.log('[psychic-workers] handle SIGTERM');
370
383
  void this.shutdownAndExit()
371
384
  .then(() => { })
372
385
  .catch(() => { });
373
386
  });
374
387
  process.on('SIGINT', () => {
375
- index_js_1.default.getOrFail().psychicApp.logger.info('[psychic-workers] handle SIGINT');
388
+ if (!EnvInternal_js_1.default.isTest)
389
+ psychic_1.PsychicApp.log('[psychic-workers] handle SIGINT');
376
390
  void this.shutdownAndExit()
377
391
  .then(() => { })
378
392
  .catch(() => { });
379
393
  });
394
+ this.connect({ activateWorkers: true });
380
395
  }
381
396
  /**
382
397
  * adds the static method of a provided class to BullMQ
@@ -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
  /**
@@ -313,7 +321,6 @@ export class Background {
313
321
  /////////////////////////
314
322
  const namedQueueOptionsMap = nativeBullMQ.namedQueueOptions || {};
315
323
  Object.keys(namedQueueOptionsMap).forEach(queueName => {
316
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
317
324
  const namedQueueOptions = namedQueueOptionsMap[queueName];
318
325
  if (namedQueueOptions.queueConnection)
319
326
  this.redisConnections.push(namedQueueOptions.queueConnection);
@@ -360,19 +367,27 @@ export class Background {
360
367
  * starts background workers
361
368
  */
362
369
  work() {
363
- this.connect({ activateWorkers: true });
370
+ process.on('uncaughtException', (error) => {
371
+ PsychicApp.log('[psychic-workers] uncaughtException:', error);
372
+ });
373
+ process.on('unhandledRejection', (error) => {
374
+ PsychicApp.log('[psychic-workers] unhandledRejection:', error);
375
+ });
364
376
  process.on('SIGTERM', () => {
365
- PsychicAppWorkers.getOrFail().psychicApp.logger.info('[psychic-workers] handle SIGTERM');
377
+ if (!EnvInternal.isTest)
378
+ PsychicApp.log('[psychic-workers] handle SIGTERM');
366
379
  void this.shutdownAndExit()
367
380
  .then(() => { })
368
381
  .catch(() => { });
369
382
  });
370
383
  process.on('SIGINT', () => {
371
- PsychicAppWorkers.getOrFail().psychicApp.logger.info('[psychic-workers] handle SIGINT');
384
+ if (!EnvInternal.isTest)
385
+ PsychicApp.log('[psychic-workers] handle SIGINT');
372
386
  void this.shutdownAndExit()
373
387
  .then(() => { })
374
388
  .catch(() => { });
375
389
  });
390
+ this.connect({ activateWorkers: true });
376
391
  }
377
392
  /**
378
393
  * adds the static method of a provided class to BullMQ
@@ -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.2",
6
6
  "author": "RVO Health",
7
7
  "repository": {
8
8
  "type": "git",
@@ -53,7 +53,7 @@
53
53
  "@types/node": "^22.5.1",
54
54
  "@types/pg": "^8",
55
55
  "@types/supertest": "^6.0.2",
56
- "bullmq": "^5.49.1",
56
+ "bullmq": "^5.52.0",
57
57
  "eslint": "^9.9.1",
58
58
  "express": "^4.21.2",
59
59
  "ioredis": "^5.4.1",
@@ -73,4 +73,4 @@
73
73
  "vitest": "^3.1.1"
74
74
  },
75
75
  "packageManager": "yarn@4.7.0"
76
- }
76
+ }