@rvoh/psychic-workers 1.4.0 → 2.0.0-alpha.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.
Files changed (41) hide show
  1. package/dist/cjs/src/background/BaseBackgroundedModel.js +10 -13
  2. package/dist/cjs/src/background/BaseBackgroundedService.js +8 -11
  3. package/dist/cjs/src/background/BaseScheduledService.js +5 -8
  4. package/dist/cjs/src/background/helpers/nameToRedisQueueName.js +5 -8
  5. package/dist/cjs/src/background/helpers/parallelTestSafeQueueName.js +4 -7
  6. package/dist/cjs/src/background/index.js +62 -68
  7. package/dist/cjs/src/error/background/ActivatingBackgroundWorkersWithoutDefaultWorkerConnection.js +1 -4
  8. package/dist/cjs/src/error/background/ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection.js +1 -4
  9. package/dist/cjs/src/error/background/AttemtedToBackgroundEntireDreamModel.js +3 -6
  10. package/dist/cjs/src/error/background/DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection.js +1 -4
  11. package/dist/cjs/src/error/background/NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection.js +1 -4
  12. package/dist/cjs/src/error/background/NoQueueForSpecifiedQueueName.js +1 -4
  13. package/dist/cjs/src/error/background/NoQueueForSpecifiedWorkstream.js +1 -4
  14. package/dist/cjs/src/helpers/EnvInternal.js +3 -5
  15. package/dist/cjs/src/helpers/durationToSeconds.js +1 -4
  16. package/dist/cjs/src/package-exports/errors.js +2 -0
  17. package/dist/cjs/src/package-exports/index.js +4 -0
  18. package/dist/cjs/src/package-exports/types.js +1 -0
  19. package/dist/cjs/src/package-exports/utils.js +1 -0
  20. package/dist/cjs/src/psychic-app-workers/cache.js +3 -8
  21. package/dist/cjs/src/psychic-app-workers/index.js +13 -16
  22. package/dist/cjs/src/test-utils/WorkerTestUtils.js +18 -21
  23. package/dist/cjs/src/types/background.js +1 -2
  24. package/dist/cjs/src/types/utils.js +1 -2
  25. package/dist/esm/src/background/BaseBackgroundedService.js +1 -1
  26. package/dist/esm/src/background/BaseScheduledService.js +1 -1
  27. package/dist/esm/src/background/index.js +3 -4
  28. package/dist/esm/src/error/background/AttemtedToBackgroundEntireDreamModel.js +1 -1
  29. package/dist/esm/src/package-exports/errors.js +2 -0
  30. package/dist/esm/src/package-exports/index.js +4 -0
  31. package/dist/esm/src/package-exports/types.js +1 -0
  32. package/dist/esm/src/package-exports/utils.js +1 -0
  33. package/dist/types/src/background/index.d.ts +0 -1
  34. package/dist/types/src/package-exports/errors.d.ts +2 -0
  35. package/dist/types/src/package-exports/index.d.ts +4 -0
  36. package/dist/types/src/package-exports/types.d.ts +2 -0
  37. package/dist/types/src/package-exports/utils.d.ts +1 -0
  38. package/package.json +27 -11
  39. package/dist/cjs/src/index.js +0 -21
  40. package/dist/esm/src/index.js +0 -8
  41. package/dist/types/src/index.d.ts +0 -9
@@ -1,9 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const dream_1 = require("@rvoh/dream");
4
- const index_js_1 = require("./index.js");
5
- const durationToSeconds_js_1 = require("../helpers/durationToSeconds.js");
6
- class BaseBackgroundedModel extends dream_1.Dream {
1
+ import { Dream } from '@rvoh/dream';
2
+ import background from './index.js';
3
+ import durationToSeconds from '../helpers/durationToSeconds.js';
4
+ export default class BaseBackgroundedModel extends Dream {
7
5
  /**
8
6
  * A getter meant to be overridden in child classes. This does
9
7
  * not have to be explicitly provided, but if so, it would allow
@@ -50,7 +48,7 @@ class BaseBackgroundedModel extends dream_1.Dream {
50
48
  */
51
49
  static async background(methodName, ...args) {
52
50
  const safeThis = this;
53
- return await index_js_1.default.staticMethod(safeThis, methodName, {
51
+ return await background.staticMethod(safeThis, methodName, {
54
52
  globalName: safeThis.globalName,
55
53
  args,
56
54
  jobConfig: safeThis.backgroundJobConfig,
@@ -79,9 +77,9 @@ class BaseBackgroundedModel extends dream_1.Dream {
79
77
  */
80
78
  static async backgroundWithDelay(delay, methodName, ...args) {
81
79
  const safeThis = this;
82
- return await index_js_1.default.staticMethod(safeThis, methodName, {
80
+ return await background.staticMethod(safeThis, methodName, {
83
81
  globalName: safeThis.globalName,
84
- delaySeconds: (0, durationToSeconds_js_1.default)(delay),
82
+ delaySeconds: durationToSeconds(delay),
85
83
  jobId: delay.jobId,
86
84
  args,
87
85
  jobConfig: safeThis.backgroundJobConfig,
@@ -118,7 +116,7 @@ class BaseBackgroundedModel extends dream_1.Dream {
118
116
  */
119
117
  async background(methodName, ...args) {
120
118
  const safeThis = this;
121
- return await index_js_1.default.modelInstanceMethod(safeThis, methodName, {
119
+ return await background.modelInstanceMethod(safeThis, methodName, {
122
120
  args,
123
121
  jobConfig: safeThis.backgroundJobConfig,
124
122
  });
@@ -147,12 +145,11 @@ class BaseBackgroundedModel extends dream_1.Dream {
147
145
  */
148
146
  async backgroundWithDelay(delay, methodName, ...args) {
149
147
  const safeThis = this;
150
- return await index_js_1.default.modelInstanceMethod(safeThis, methodName, {
148
+ return await background.modelInstanceMethod(safeThis, methodName, {
151
149
  args,
152
- delaySeconds: (0, durationToSeconds_js_1.default)(delay),
150
+ delaySeconds: durationToSeconds(delay),
153
151
  jobId: delay.jobId,
154
152
  jobConfig: safeThis.backgroundJobConfig,
155
153
  });
156
154
  }
157
155
  }
158
- exports.default = BaseBackgroundedModel;
@@ -1,9 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const dream_1 = require("@rvoh/dream");
4
- const durationToSeconds_js_1 = require("../helpers/durationToSeconds.js");
5
- const index_js_1 = require("./index.js");
6
- class BaseBackgroundedService {
1
+ import { GlobalNameNotSet } from '@rvoh/dream/errors';
2
+ import durationToSeconds from '../helpers/durationToSeconds.js';
3
+ import background from './index.js';
4
+ export default class BaseBackgroundedService {
7
5
  /**
8
6
  * A getter meant to be overridden in child classes. This does
9
7
  * not have to be explicitly provided, but if so, it would allow
@@ -28,7 +26,7 @@ class BaseBackgroundedService {
28
26
  */
29
27
  static get globalName() {
30
28
  if (!this._globalName)
31
- throw new dream_1.GlobalNameNotSet(this);
29
+ throw new GlobalNameNotSet(this);
32
30
  return this._globalName;
33
31
  }
34
32
  /**
@@ -62,7 +60,7 @@ class BaseBackgroundedService {
62
60
  */
63
61
  static async background(methodName, ...args) {
64
62
  const safeThis = this;
65
- return await index_js_1.default.staticMethod(safeThis, methodName, {
63
+ return await background.staticMethod(safeThis, methodName, {
66
64
  globalName: safeThis.globalName,
67
65
  args,
68
66
  jobConfig: safeThis.backgroundJobConfig,
@@ -91,9 +89,9 @@ class BaseBackgroundedService {
91
89
  */
92
90
  static async backgroundWithDelay(delay, methodName, ...args) {
93
91
  const safeThis = this;
94
- return await index_js_1.default.staticMethod(safeThis, methodName, {
92
+ return await background.staticMethod(safeThis, methodName, {
95
93
  globalName: safeThis.globalName,
96
- delaySeconds: (0, durationToSeconds_js_1.default)(delay),
94
+ delaySeconds: durationToSeconds(delay),
97
95
  jobId: delay.jobId,
98
96
  args,
99
97
  jobConfig: safeThis.backgroundJobConfig,
@@ -110,4 +108,3 @@ class BaseBackgroundedService {
110
108
  throw new Error('Must define psychicTypes getter in BackgroundedService class within your application');
111
109
  }
112
110
  }
113
- exports.default = BaseBackgroundedService;
@@ -1,8 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const dream_1 = require("@rvoh/dream");
4
- const index_js_1 = require("./index.js");
5
- class BaseScheduledService {
1
+ import { GlobalNameNotSet } from '@rvoh/dream/errors';
2
+ import background from './index.js';
3
+ export default class BaseScheduledService {
6
4
  /**
7
5
  * A getter meant to be overridden in child classes. This does
8
6
  * not have to be explicitly provided, but if so, it would allow
@@ -27,7 +25,7 @@ class BaseScheduledService {
27
25
  */
28
26
  static get globalName() {
29
27
  if (!this._globalName)
30
- throw new dream_1.GlobalNameNotSet(this);
28
+ throw new GlobalNameNotSet(this);
31
29
  return this._globalName;
32
30
  }
33
31
  /**
@@ -62,7 +60,7 @@ class BaseScheduledService {
62
60
  */
63
61
  static async schedule(pattern, methodName, ...args) {
64
62
  const safeThis = this;
65
- return await index_js_1.default.scheduledMethod(safeThis, pattern, methodName, {
63
+ return await background.scheduledMethod(safeThis, pattern, methodName, {
66
64
  globalName: safeThis.globalName,
67
65
  args,
68
66
  jobConfig: safeThis.backgroundJobConfig,
@@ -79,4 +77,3 @@ class BaseScheduledService {
79
77
  throw new Error('Must define psychicTypes getter in BackgroundedService class within your application');
80
78
  }
81
79
  }
82
- exports.default = BaseScheduledService;
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = nameToRedisQueueName;
4
- const ioredis_1 = require("ioredis");
5
- const parallelTestSafeQueueName_js_1 = require("./parallelTestSafeQueueName.js");
6
- function nameToRedisQueueName(queueName, redis) {
1
+ import { Cluster } from 'ioredis';
2
+ import parallelTestSafeQueueName from './parallelTestSafeQueueName.js';
3
+ export default function nameToRedisQueueName(queueName, redis) {
7
4
  queueName = queueName.replace(/\{|\}/g, '');
8
- if (redis instanceof ioredis_1.Cluster)
5
+ if (redis instanceof Cluster)
9
6
  return `{${queueName}}`;
10
- return (0, parallelTestSafeQueueName_js_1.default)(queueName);
7
+ return parallelTestSafeQueueName(queueName);
11
8
  }
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = parallelTestSafeQueueName;
4
- const EnvInternal_js_1 = require("../../helpers/EnvInternal.js");
5
- function parallelTestSafeQueueName(queueName) {
6
- if (EnvInternal_js_1.default.isTest && (EnvInternal_js_1.default.integer('VITEST_POOL_ID', { optional: true }) || 0) > 1) {
7
- queueName = `${queueName}-${EnvInternal_js_1.default.integer('VITEST_POOL_ID')}`;
1
+ import EnvInternal from '../../helpers/EnvInternal.js';
2
+ export default function parallelTestSafeQueueName(queueName) {
3
+ if (EnvInternal.isTest && (EnvInternal.integer('VITEST_POOL_ID', { optional: true }) || 0) > 1) {
4
+ queueName = `${queueName}-${EnvInternal.integer('VITEST_POOL_ID')}`;
8
5
  }
9
6
  return queueName;
10
7
  }
@@ -1,32 +1,30 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Background = void 0;
4
- exports.stopBackgroundWorkers = stopBackgroundWorkers;
5
- const dream_1 = require("@rvoh/dream");
6
- const psychic_1 = require("@rvoh/psychic");
7
- const bullmq_1 = require("bullmq");
8
- const ActivatingBackgroundWorkersWithoutDefaultWorkerConnection_js_1 = require("../error/background/ActivatingBackgroundWorkersWithoutDefaultWorkerConnection.js");
9
- const ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection_js_1 = require("../error/background/ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection.js");
10
- const DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection_js_1 = require("../error/background/DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection.js");
11
- const NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection_js_1 = require("../error/background/NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection.js");
12
- const NoQueueForSpecifiedQueueName_js_1 = require("../error/background/NoQueueForSpecifiedQueueName.js");
13
- const NoQueueForSpecifiedWorkstream_js_1 = require("../error/background/NoQueueForSpecifiedWorkstream.js");
14
- const EnvInternal_js_1 = require("../helpers/EnvInternal.js");
15
- const index_js_1 = require("../psychic-app-workers/index.js");
16
- const AttemtedToBackgroundEntireDreamModel_js_1 = require("../error/background/AttemtedToBackgroundEntireDreamModel.js");
17
- const nameToRedisQueueName_js_1 = require("./helpers/nameToRedisQueueName.js");
1
+ import { Dream } from '@rvoh/dream';
2
+ import { closeAllDbConnections } from '@rvoh/dream/db';
3
+ import { compact, pascalize } from '@rvoh/dream/utils';
4
+ import { PsychicApp } from '@rvoh/psychic';
5
+ import { Job, Queue, Worker, } from 'bullmq';
6
+ import ActivatingBackgroundWorkersWithoutDefaultWorkerConnection from '../error/background/ActivatingBackgroundWorkersWithoutDefaultWorkerConnection.js';
7
+ import ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection from '../error/background/ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection.js';
8
+ import DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection from '../error/background/DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection.js';
9
+ import NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection from '../error/background/NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection.js';
10
+ import NoQueueForSpecifiedQueueName from '../error/background/NoQueueForSpecifiedQueueName.js';
11
+ import NoQueueForSpecifiedWorkstream from '../error/background/NoQueueForSpecifiedWorkstream.js';
12
+ import EnvInternal from '../helpers/EnvInternal.js';
13
+ import PsychicAppWorkers from '../psychic-app-workers/index.js';
14
+ import AttemtedToBackgroundEntireDreamModel from '../error/background/AttemtedToBackgroundEntireDreamModel.js';
15
+ import nameToRedisQueueName from './helpers/nameToRedisQueueName.js';
18
16
  const DEFAULT_CONCURRENCY = 10;
19
17
  /**
20
18
  * the underlying class driving the `background` singleton,
21
19
  * available as an import from `psychic-workers`.
22
20
  */
23
- class Background {
21
+ export class Background {
24
22
  /**
25
23
  * returns the default queue name for your app
26
24
  */
27
25
  static get defaultQueueName() {
28
- const psychicWorkersApp = index_js_1.default.getOrFail();
29
- return `${(0, dream_1.pascalize)(psychicWorkersApp.psychicApp.appName)}BackgroundJobQueue`;
26
+ const psychicWorkersApp = PsychicAppWorkers.getOrFail();
27
+ return `${pascalize(psychicWorkersApp.psychicApp.appName)}BackgroundJobQueue`;
30
28
  }
31
29
  /**
32
30
  * @internal
@@ -36,8 +34,8 @@ class Background {
36
34
  * offers a pro version, which requires you to provide custom classes.
37
35
  */
38
36
  static get Worker() {
39
- const psychicWorkersApp = index_js_1.default.getOrFail();
40
- return (psychicWorkersApp.backgroundOptions.providers?.Worker || bullmq_1.Worker);
37
+ const psychicWorkersApp = PsychicAppWorkers.getOrFail();
38
+ return (psychicWorkersApp.backgroundOptions.providers?.Worker || Worker);
41
39
  }
42
40
  /**
43
41
  * @internal
@@ -47,8 +45,8 @@ class Background {
47
45
  * offers a pro version, which requires you to provide custom classes.
48
46
  */
49
47
  static get Queue() {
50
- const psychicWorkersApp = index_js_1.default.getOrFail();
51
- return (psychicWorkersApp.backgroundOptions.providers?.Queue || bullmq_1.Queue);
48
+ const psychicWorkersApp = PsychicAppWorkers.getOrFail();
49
+ return (psychicWorkersApp.backgroundOptions.providers?.Queue || Queue);
52
50
  }
53
51
  /**
54
52
  * @internal
@@ -104,7 +102,7 @@ class Background {
104
102
  connect({ activateWorkers = false, } = {}) {
105
103
  if (this.defaultQueue)
106
104
  return;
107
- const psychicWorkersApp = index_js_1.default.getOrFail();
105
+ const psychicWorkersApp = PsychicAppWorkers.getOrFail();
108
106
  const defaultBullMQQueueOptions = psychicWorkersApp.backgroundOptions.defaultBullMQQueueOptions || {};
109
107
  if (psychicWorkersApp.backgroundOptions.nativeBullMQ) {
110
108
  this.nativeBullMQConnect(defaultBullMQQueueOptions, psychicWorkersApp.backgroundOptions, { activateWorkers });
@@ -117,7 +115,7 @@ class Background {
117
115
  * Returns all the queues in your application
118
116
  */
119
117
  get queues() {
120
- return (0, dream_1.compact)([
118
+ return compact([
121
119
  this.defaultQueue,
122
120
  ...Object.values(this.namedQueues).map(queue => queue),
123
121
  this.defaultTransitionalQueue,
@@ -139,21 +137,21 @@ class Background {
139
137
  * Shuts down workers, closes all redis connections
140
138
  */
141
139
  async shutdown() {
142
- if (!EnvInternal_js_1.default.isTest)
143
- psychic_1.PsychicApp.log(`[psychic-workers] shutdown`);
144
- const psychicWorkersApp = index_js_1.default.getOrFail();
140
+ if (!EnvInternal.isTest)
141
+ PsychicApp.log(`[psychic-workers] shutdown`);
142
+ const psychicWorkersApp = PsychicAppWorkers.getOrFail();
145
143
  for (const hook of psychicWorkersApp.hooks.workerShutdown) {
146
144
  await hook();
147
145
  }
148
- await (0, dream_1.closeAllDbConnections)();
146
+ await closeAllDbConnections();
149
147
  await this.closeAllRedisConnections();
150
148
  }
151
149
  /**
152
150
  * closes all redis connections for workers and queues
153
151
  */
154
152
  async closeAllRedisConnections() {
155
- if (!EnvInternal_js_1.default.isTest)
156
- psychic_1.PsychicApp.log(`[psychic-workers] closeAllRedisConnections`);
153
+ if (!EnvInternal.isTest)
154
+ PsychicApp.log(`[psychic-workers] closeAllRedisConnections`);
157
155
  for (const worker of this.workers) {
158
156
  await worker.close();
159
157
  }
@@ -162,8 +160,8 @@ class Background {
162
160
  await connection.quit();
163
161
  }
164
162
  catch (error) {
165
- if (!EnvInternal_js_1.default.isTest)
166
- psychic_1.PsychicApp.logWithLevel('error', `[psychic-workers] error quitting Redis:`, error);
163
+ if (!EnvInternal.isTest)
164
+ PsychicApp.logWithLevel('error', `[psychic-workers] error quitting Redis:`, error);
167
165
  }
168
166
  }
169
167
  }
@@ -182,7 +180,7 @@ class Background {
182
180
  // transitional queues must have the same names they had prior to making them
183
181
  // transitional since the name is what identifies the queues and enables the
184
182
  // queues to be worked off
185
- const formattedQueueName = (0, nameToRedisQueueName_js_1.default)(Background.defaultQueueName, defaultQueueConnection);
183
+ const formattedQueueName = nameToRedisQueueName(Background.defaultQueueName, defaultQueueConnection);
186
184
  ///////////////////////////////
187
185
  // create default workstream //
188
186
  ///////////////////////////////
@@ -204,11 +202,11 @@ class Background {
204
202
  /////////////////////////////
205
203
  if (activateWorkers) {
206
204
  if (!defaultWorkerConnection)
207
- throw new ActivatingBackgroundWorkersWithoutDefaultWorkerConnection_js_1.default();
205
+ throw new ActivatingBackgroundWorkersWithoutDefaultWorkerConnection();
208
206
  const workerCount = backgroundOptions.defaultWorkstream?.workerCount ?? 1;
209
207
  for (let i = 0; i < workerCount; i++) {
210
208
  this._workers.push(new Background.Worker(formattedQueueName, async (job) => await this.doWork(job), {
211
- autorun: !EnvInternal_js_1.default.isTest,
209
+ autorun: !EnvInternal.isTest,
212
210
  connection: defaultWorkerConnection,
213
211
  concurrency: backgroundOptions.defaultWorkstream?.concurrency || DEFAULT_CONCURRENCY,
214
212
  }));
@@ -231,7 +229,7 @@ class Background {
231
229
  // transitional queues must have the same names they had prior to making them
232
230
  // transitional since the name is what identifies the queues and enables the
233
231
  // queues to be worked off
234
- const namedWorkstreamFormattedQueueName = (0, nameToRedisQueueName_js_1.default)(namedWorkstream.name, namedWorkstreamQueueConnection);
232
+ const namedWorkstreamFormattedQueueName = nameToRedisQueueName(namedWorkstream.name, namedWorkstreamQueueConnection);
235
233
  const namedQueue = new Background.Queue(namedWorkstreamFormattedQueueName, {
236
234
  ...defaultBullMQQueueOptions,
237
235
  connection: namedWorkstreamQueueConnection,
@@ -248,11 +246,11 @@ class Background {
248
246
  //////////////////////////
249
247
  if (activateWorkers) {
250
248
  if (!namedWorkstreamWorkerConnection)
251
- throw new ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection_js_1.default(namedWorkstream.name);
249
+ throw new ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection(namedWorkstream.name);
252
250
  const workerCount = namedWorkstream.workerCount ?? 1;
253
251
  for (let i = 0; i < workerCount; i++) {
254
252
  this._workers.push(new Background.Worker(namedWorkstreamFormattedQueueName, async (job) => await this.doWork(job), {
255
- autorun: !EnvInternal_js_1.default.isTest,
253
+ autorun: !EnvInternal.isTest,
256
254
  group: {
257
255
  id: namedWorkstream.name,
258
256
  limit: namedWorkstream.rateLimit,
@@ -293,8 +291,8 @@ class Background {
293
291
  if (defaultWorkerConnection)
294
292
  this.redisConnections.push(defaultWorkerConnection);
295
293
  if (!defaultQueueConnection)
296
- throw new DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection_js_1.default();
297
- const formattedQueueName = (0, nameToRedisQueueName_js_1.default)(Background.defaultQueueName, defaultQueueConnection);
294
+ throw new DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection();
295
+ const formattedQueueName = nameToRedisQueueName(Background.defaultQueueName, defaultQueueConnection);
298
296
  //////////////////////////
299
297
  // create default queue //
300
298
  //////////////////////////
@@ -311,11 +309,11 @@ class Background {
311
309
  /////////////////////////////
312
310
  if (activateWorkers) {
313
311
  if (!defaultWorkerConnection)
314
- throw new ActivatingBackgroundWorkersWithoutDefaultWorkerConnection_js_1.default();
312
+ throw new ActivatingBackgroundWorkersWithoutDefaultWorkerConnection();
315
313
  const workerCount = nativeBullMQ.defaultWorkerCount ?? 1;
316
314
  for (let i = 0; i < workerCount; i++) {
317
315
  this._workers.push(new Background.Worker(formattedQueueName, async (job) => await this.doWork(job), {
318
- autorun: !EnvInternal_js_1.default.isTest,
316
+ autorun: !EnvInternal.isTest,
319
317
  ...(backgroundOptions.nativeBullMQ.defaultWorkerOptions || {}),
320
318
  connection: defaultWorkerConnection,
321
319
  }));
@@ -337,8 +335,8 @@ class Background {
337
335
  const namedQueueConnection = namedQueueOptions.queueConnection || defaultQueueConnection;
338
336
  const namedWorkerConnection = namedQueueOptions.workerConnection || defaultWorkerConnection;
339
337
  if (!namedQueueConnection)
340
- throw new NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection_js_1.default(queueName);
341
- const formattedQueuename = (0, nameToRedisQueueName_js_1.default)(queueName, namedQueueConnection);
338
+ throw new NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection(queueName);
339
+ const formattedQueuename = nameToRedisQueueName(queueName, namedQueueConnection);
342
340
  this.namedQueues[queueName] = new Background.Queue(formattedQueuename, {
343
341
  ...defaultBullMQQueueOptions,
344
342
  ...namedQueueOptions,
@@ -355,10 +353,10 @@ class Background {
355
353
  this.groupNames[queueName].push(extraWorkerOptions.group.id);
356
354
  if (activateWorkers) {
357
355
  if (!namedWorkerConnection)
358
- throw new ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection_js_1.default(queueName);
356
+ throw new ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection(queueName);
359
357
  for (let i = 0; i < extraWorkerCount; i++) {
360
358
  this._workers.push(new Background.Worker(formattedQueuename, async (job) => await this.doWork(job), {
361
- autorun: !EnvInternal_js_1.default.isTest,
359
+ autorun: !EnvInternal.isTest,
362
360
  ...extraWorkerOptions,
363
361
  connection: namedWorkerConnection,
364
362
  }));
@@ -377,21 +375,21 @@ class Background {
377
375
  */
378
376
  work() {
379
377
  process.on('uncaughtException', (error) => {
380
- psychic_1.PsychicApp.log('[psychic-workers] uncaughtException:', error);
378
+ PsychicApp.log('[psychic-workers] uncaughtException:', error);
381
379
  });
382
380
  process.on('unhandledRejection', (error) => {
383
- psychic_1.PsychicApp.log('[psychic-workers] unhandledRejection:', error);
381
+ PsychicApp.log('[psychic-workers] unhandledRejection:', error);
384
382
  });
385
383
  process.on('SIGTERM', () => {
386
- if (!EnvInternal_js_1.default.isTest)
387
- psychic_1.PsychicApp.log('[psychic-workers] handle SIGTERM');
384
+ if (!EnvInternal.isTest)
385
+ PsychicApp.log('[psychic-workers] handle SIGTERM');
388
386
  void this.shutdownAndExit()
389
387
  .then(() => { })
390
388
  .catch(() => { });
391
389
  });
392
390
  process.on('SIGINT', () => {
393
- if (!EnvInternal_js_1.default.isTest)
394
- psychic_1.PsychicApp.log('[psychic-workers] handle SIGINT');
391
+ if (!EnvInternal.isTest)
392
+ PsychicApp.log('[psychic-workers] handle SIGINT');
395
393
  void this.shutdownAndExit()
396
394
  .then(() => { })
397
395
  .catch(() => { });
@@ -470,9 +468,9 @@ class Background {
470
468
  : this.defaultQueue;
471
469
  if (!queueInstance) {
472
470
  if (typeof workstreamConfig.workstream === 'string')
473
- throw new NoQueueForSpecifiedWorkstream_js_1.default(workstreamConfig.workstream);
471
+ throw new NoQueueForSpecifiedWorkstream(workstreamConfig.workstream);
474
472
  if (typeof queueConfig.queue === 'string')
475
- throw new NoQueueForSpecifiedQueueName_js_1.default(queueConfig.queue);
473
+ throw new NoQueueForSpecifiedQueueName(queueConfig.queue);
476
474
  }
477
475
  return queueInstance;
478
476
  }
@@ -505,8 +503,8 @@ class Background {
505
503
  async _addToQueue(jobType, jobData, { delaySeconds, jobId, jobConfig, priority, groupId, }) {
506
504
  ;
507
505
  jobData.args.forEach(arg => {
508
- if (arg instanceof dream_1.Dream)
509
- throw new AttemtedToBackgroundEntireDreamModel_js_1.default(jobData.method, arg);
506
+ if (arg instanceof Dream)
507
+ throw new AttemtedToBackgroundEntireDreamModel(jobData.method, arg);
510
508
  });
511
509
  // set this variable out side of the conditional so that
512
510
  // mismatches will raise exceptions even in tests
@@ -514,13 +512,13 @@ class Background {
514
512
  // if delaySeconds is 0, we will intentionally treat
515
513
  // this as `undefined`
516
514
  const delay = delaySeconds ? delaySeconds * 1000 : undefined;
517
- const workersApp = index_js_1.default.getOrFail();
515
+ const workersApp = PsychicAppWorkers.getOrFail();
518
516
  // in test environments, this block will short-circuit adding to the queue,
519
517
  // causing the job to immediately invoke instead. This behavior can be bypassed
520
518
  // by setting `testInvocation=manual` in the workers config.
521
- if (EnvInternal_js_1.default.isTest && workersApp.testInvocation === 'automatic') {
519
+ if (EnvInternal.isTest && workersApp.testInvocation === 'automatic') {
522
520
  const queue = new Background.Queue('TestQueue', { connection: {} });
523
- const job = new bullmq_1.Job(queue, jobType, jobData, {});
521
+ const job = new Job(queue, jobType, jobData, {});
524
522
  await this.doWork(job);
525
523
  return;
526
524
  //
@@ -603,7 +601,7 @@ class Background {
603
601
  case 'BackgroundJobQueueStaticJob':
604
602
  if (globalName) {
605
603
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
606
- objectClass = psychic_1.PsychicApp.lookupClassByGlobalName(globalName);
604
+ objectClass = PsychicApp.lookupClassByGlobalName(globalName);
607
605
  }
608
606
  if (!objectClass)
609
607
  return;
@@ -612,7 +610,7 @@ class Background {
612
610
  break;
613
611
  case 'BackgroundJobQueueModelInstanceJob':
614
612
  if (globalName) {
615
- dreamClass = psychic_1.PsychicApp.lookupClassByGlobalName(globalName);
613
+ dreamClass = PsychicApp.lookupClassByGlobalName(globalName);
616
614
  }
617
615
  if (dreamClass) {
618
616
  const modelInstance = await dreamClass.connection('primary').find(id);
@@ -625,9 +623,5 @@ class Background {
625
623
  }
626
624
  }
627
625
  }
628
- exports.Background = Background;
629
626
  const background = new Background();
630
- exports.default = background;
631
- async function stopBackgroundWorkers() {
632
- await background.shutdown();
633
- }
627
+ export default background;
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class ActivatingBackgroundWorkersWithoutDefaultWorkerConnection extends Error {
1
+ export default class ActivatingBackgroundWorkersWithoutDefaultWorkerConnection extends Error {
4
2
  get message() {
5
3
  return `
6
4
  defaultWorkerConnection is required when activating workers. For example,
@@ -8,4 +6,3 @@ it may be omitted on webserver instances, but is required on worker instances.
8
6
  `;
9
7
  }
10
8
  }
11
- exports.default = ActivatingBackgroundWorkersWithoutDefaultWorkerConnection;
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection extends Error {
1
+ export default class ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection extends Error {
4
2
  queueName;
5
3
  constructor(queueName) {
6
4
  super();
@@ -14,4 +12,3 @@ For example, it may be omitted on webserver instances, but is required on worker
14
12
  `;
15
13
  }
16
14
  }
17
- exports.default = ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection;
@@ -1,7 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const dream_1 = require("@rvoh/dream");
4
- class AttemtedToBackgroundEntireDreamModel extends Error {
1
+ import { camelize } from '@rvoh/dream/utils';
2
+ export default class AttemtedToBackgroundEntireDreamModel extends Error {
5
3
  method;
6
4
  dream;
7
5
  constructor(method, dream) {
@@ -14,7 +12,7 @@ class AttemtedToBackgroundEntireDreamModel extends Error {
14
12
  const primaryKey = dreamClass.primaryKey;
15
13
  const sanitizedMethodName = (this.method ?? 'myMethod').replace(/^_/, '');
16
14
  const className = this.dream.sanitizedConstructorName;
17
- const instanceName = (0, dream_1.camelize)(className);
15
+ const instanceName = camelize(className);
18
16
  return `
19
17
  Background \`${instanceName}.${primaryKey}\` (and \`${instanceName}.sanitizedConstructorName\`, if
20
18
  the use case is polymorphic), not the entire Dream model. Then, in the
@@ -41,4 +39,3 @@ This serves several purposes:
41
39
  `;
42
40
  }
43
41
  }
44
- exports.default = AttemtedToBackgroundEntireDreamModel;
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection extends Error {
1
+ export default class DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection extends Error {
4
2
  get message() {
5
3
  return `
6
4
  Native BullMQ options don't include a default queue connection, and the
@@ -8,4 +6,3 @@ default config does not include a queue connection
8
6
  `;
9
7
  }
10
8
  }
11
- exports.default = DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection;
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection extends Error {
1
+ export default class NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection extends Error {
4
2
  queueName;
5
3
  constructor(queueName) {
6
4
  super();
@@ -13,4 +11,3 @@ ${this.queueName} queue does not include a queue connection
13
11
  `;
14
12
  }
15
13
  }
16
- exports.default = NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection;
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class NoQueueForSpecifiedQueueName extends Error {
1
+ export default class NoQueueForSpecifiedQueueName extends Error {
4
2
  queue;
5
3
  constructor(queue) {
6
4
  super();
@@ -12,4 +10,3 @@ No queue matches "${this.queue}"
12
10
  `;
13
11
  }
14
12
  }
15
- exports.default = NoQueueForSpecifiedQueueName;
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class NoQueueForSpecifiedWorkstream extends Error {
1
+ export default class NoQueueForSpecifiedWorkstream extends Error {
4
2
  workstream;
5
3
  constructor(workstream) {
6
4
  super();
@@ -12,4 +10,3 @@ No queue found for workstream "${this.workstream}"
12
10
  `;
13
11
  }
14
12
  }
15
- exports.default = NoQueueForSpecifiedWorkstream;
@@ -1,5 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const dream_1 = require("@rvoh/dream");
4
- const EnvInternal = new dream_1.Env();
5
- exports.default = EnvInternal;
1
+ import { Env } from '@rvoh/dream';
2
+ const EnvInternal = new Env();
3
+ export default EnvInternal;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = durationToSeconds;
4
- function durationToSeconds(duration) {
1
+ export default function durationToSeconds(duration) {
5
2
  return ((duration.seconds ? duration.seconds : 0) +
6
3
  (duration.minutes ? duration.minutes * 60 : 0) +
7
4
  (duration.hours ? duration.hours * 60 * 60 : 0) +
@@ -0,0 +1,2 @@
1
+ export { default as NoQueueForSpecifiedQueueName } from '../error/background/NoQueueForSpecifiedQueueName.js';
2
+ export { default as NoQueueForSpecifiedWorkstream } from '../error/background/NoQueueForSpecifiedWorkstream.js';
@@ -0,0 +1,4 @@
1
+ export { default as background, Background } from '../background/index.js';
2
+ export { default as BaseBackgroundedModel } from '../background/BaseBackgroundedModel.js';
3
+ export { default as BaseBackgroundedService } from '../background/BaseBackgroundedService.js';
4
+ export { default as BaseScheduledService } from '../background/BaseScheduledService.js';
@@ -0,0 +1 @@
1
+ export { default as PsychicAppWorkers, } from '../psychic-app-workers/index.js';
@@ -0,0 +1 @@
1
+ export { default as WorkerTestUtils } from '../test-utils/WorkerTestUtils.js';
@@ -1,16 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cachePsychicWorkersApp = cachePsychicWorkersApp;
4
- exports.getCachedPsychicWorkersApp = getCachedPsychicWorkersApp;
5
- exports.getCachedPsychicWorkersAppOrFail = getCachedPsychicWorkersAppOrFail;
6
1
  let _psychicWorkersApp = undefined;
7
- function cachePsychicWorkersApp(psychicWorkersApp) {
2
+ export function cachePsychicWorkersApp(psychicWorkersApp) {
8
3
  _psychicWorkersApp = psychicWorkersApp;
9
4
  }
10
- function getCachedPsychicWorkersApp() {
5
+ export function getCachedPsychicWorkersApp() {
11
6
  return _psychicWorkersApp;
12
7
  }
13
- function getCachedPsychicWorkersAppOrFail() {
8
+ export function getCachedPsychicWorkersAppOrFail() {
14
9
  if (!_psychicWorkersApp)
15
10
  throw new Error('must call `cachePsychicWorkersApp` before loading cached psychic application workers');
16
11
  return _psychicWorkersApp;
@@ -1,27 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const bullmq_1 = require("bullmq");
4
- const cache_js_1 = require("./cache.js");
5
- const index_js_1 = require("../background/index.js");
6
- class PsychicAppWorkers {
1
+ import { Queue, Worker } from 'bullmq';
2
+ import { cachePsychicWorkersApp, getCachedPsychicWorkersAppOrFail } from './cache.js';
3
+ import background from '../background/index.js';
4
+ export default class PsychicAppWorkers {
7
5
  static async init(psychicApp, cb) {
8
6
  const psychicWorkersApp = new PsychicAppWorkers(psychicApp);
9
7
  await cb(psychicWorkersApp);
10
8
  psychicApp.on('cli:sync', () => {
11
- index_js_1.default.connect();
9
+ background.connect();
12
10
  const output = {
13
- workstreamNames: [...index_js_1.default['workstreamNames']],
14
- queueGroupMap: { ...index_js_1.default['groupNames'] },
11
+ workstreamNames: [...background['workstreamNames']],
12
+ queueGroupMap: { ...background['groupNames'] },
15
13
  };
16
14
  return output;
17
15
  });
18
16
  psychicApp.on('server:shutdown', async () => {
19
- await index_js_1.default.closeAllRedisConnections();
17
+ await background.closeAllRedisConnections();
20
18
  });
21
19
  psychicApp.on('server:init:after-routes', () => {
22
- index_js_1.default.connect();
20
+ background.connect();
23
21
  });
24
- (0, cache_js_1.cachePsychicWorkersApp)(psychicWorkersApp);
22
+ cachePsychicWorkersApp(psychicWorkersApp);
25
23
  return psychicWorkersApp;
26
24
  }
27
25
  /**
@@ -31,7 +29,7 @@ class PsychicAppWorkers {
31
29
  * The psychic application can be set by calling PsychicApp#init
32
30
  */
33
31
  static getOrFail() {
34
- return (0, cache_js_1.getCachedPsychicWorkersAppOrFail)();
32
+ return getCachedPsychicWorkersAppOrFail();
35
33
  }
36
34
  psychicApp;
37
35
  constructor(psychicApp) {
@@ -79,8 +77,8 @@ class PsychicAppWorkers {
79
77
  this._backgroundOptions = {
80
78
  ...{
81
79
  providers: {
82
- Queue: bullmq_1.Queue,
83
- Worker: bullmq_1.Worker,
80
+ Queue,
81
+ Worker,
84
82
  },
85
83
  },
86
84
  ...value,
@@ -94,4 +92,3 @@ class PsychicAppWorkers {
94
92
  }
95
93
  }
96
94
  }
97
- exports.default = PsychicAppWorkers;
@@ -1,16 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const index_js_1 = require("../background/index.js");
4
- const parallelTestSafeQueueName_js_1 = require("../background/helpers/parallelTestSafeQueueName.js");
1
+ import background, { Background } from '../background/index.js';
2
+ import parallelTestSafeQueueName from '../background/helpers/parallelTestSafeQueueName.js';
5
3
  const LOCK_TOKEN = 'psychic-test-worker';
6
- class WorkerTestUtils {
4
+ export default class WorkerTestUtils {
7
5
  /*
8
6
  * Safely encapsulate's a queue name in parallel test runs,
9
7
  * capturing the VITEST_POOL_ID and appending it to the
10
8
  * end of the queue name if VITEST_POOL_ID > 1
11
9
  */
12
10
  static parallelTestSafeQueueName(queueName) {
13
- return (0, parallelTestSafeQueueName_js_1.default)(queueName);
11
+ return parallelTestSafeQueueName(queueName);
14
12
  }
15
13
  /*
16
14
  * Works off all of the jobs in all queues. The jobs
@@ -28,8 +26,8 @@ class WorkerTestUtils {
28
26
  * so that jobs are successfully commited to the queue and can be worked off.
29
27
  */
30
28
  static async work(opts = {}) {
31
- index_js_1.default.connect();
32
- const queues = index_js_1.default.queues;
29
+ background.connect();
30
+ const queues = background.queues;
33
31
  let workWasDone = true;
34
32
  do {
35
33
  workWasDone = false;
@@ -41,23 +39,23 @@ class WorkerTestUtils {
41
39
  } while (workWasDone);
42
40
  }
43
41
  static async workScheduled(opts = {}) {
44
- index_js_1.default.connect();
42
+ background.connect();
45
43
  const queues = opts.queue
46
- ? index_js_1.default.queues.filter(queue => queue.name === opts.queue)
47
- : index_js_1.default.queues;
44
+ ? background.queues.filter(queue => queue.name === opts.queue)
45
+ : background.queues;
48
46
  if (opts.queue && !queues.length)
49
- throw new Error(`Expected to find queue with name: ${opts.queue}, but none were found by that name. The queue names available are: ${index_js_1.default.queues.map(queue => queue.name).join(', ')}`);
47
+ throw new Error(`Expected to find queue with name: ${opts.queue}, but none were found by that name. The queue names available are: ${background.queues.map(queue => queue.name).join(', ')}`);
50
48
  for (const queue of queues) {
51
49
  const jobs = (await queue.getDelayed());
52
50
  for (const job of jobs) {
53
51
  const data = job.data;
54
52
  if (opts.for) {
55
53
  if (data.globalName === opts.for.globalName) {
56
- await index_js_1.default.doWork(job);
54
+ await background.doWork(job);
57
55
  }
58
56
  }
59
57
  else {
60
- await index_js_1.default.doWork(job);
58
+ await background.doWork(job);
61
59
  }
62
60
  }
63
61
  }
@@ -79,8 +77,8 @@ class WorkerTestUtils {
79
77
  * ```
80
78
  */
81
79
  static async clean() {
82
- index_js_1.default.connect();
83
- for (const queue of index_js_1.default.queues) {
80
+ background.connect();
81
+ for (const queue of background.queues) {
84
82
  // clears all non-scheduled, non-completed, and non-failed jobs
85
83
  await queue.drain();
86
84
  // clear out completed and failed jobs
@@ -94,7 +92,7 @@ class WorkerTestUtils {
94
92
  }
95
93
  }
96
94
  static async workOne(queue) {
97
- const worker = new index_js_1.Background.Worker(queue.name, async (job) => await index_js_1.default.doWork(job), {
95
+ const worker = new Background.Worker(queue.name, async (job) => await background.doWork(job), {
98
96
  autorun: false,
99
97
  connection: queue.client,
100
98
  concurrency: 1,
@@ -108,12 +106,12 @@ class WorkerTestUtils {
108
106
  return true;
109
107
  }
110
108
  static queueNamesMatch(queue, compareQueueName) {
111
- return (queue.name === (0, parallelTestSafeQueueName_js_1.default)(compareQueueName) ||
112
- queue.name === `{${(0, parallelTestSafeQueueName_js_1.default)(compareQueueName)}`);
109
+ return (queue.name === parallelTestSafeQueueName(compareQueueName) ||
110
+ queue.name === `{${parallelTestSafeQueueName(compareQueueName)}`);
113
111
  }
114
112
  static async processJob(job) {
115
113
  try {
116
- const res = await index_js_1.default.doWork(job);
114
+ const res = await background.doWork(job);
117
115
  await job.moveToCompleted(res, LOCK_TOKEN, false);
118
116
  }
119
117
  catch (err) {
@@ -121,4 +119,3 @@ class WorkerTestUtils {
121
119
  }
122
120
  }
123
121
  }
124
- exports.default = WorkerTestUtils;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,4 +1,4 @@
1
- import { GlobalNameNotSet } from '@rvoh/dream';
1
+ import { GlobalNameNotSet } from '@rvoh/dream/errors';
2
2
  import durationToSeconds from '../helpers/durationToSeconds.js';
3
3
  import background from './index.js';
4
4
  export default class BaseBackgroundedService {
@@ -1,4 +1,4 @@
1
- import { GlobalNameNotSet } from '@rvoh/dream';
1
+ import { GlobalNameNotSet } from '@rvoh/dream/errors';
2
2
  import background from './index.js';
3
3
  export default class BaseScheduledService {
4
4
  /**
@@ -1,4 +1,6 @@
1
- import { closeAllDbConnections, compact, Dream, pascalize } from '@rvoh/dream';
1
+ import { Dream } from '@rvoh/dream';
2
+ import { closeAllDbConnections } from '@rvoh/dream/db';
3
+ import { compact, pascalize } from '@rvoh/dream/utils';
2
4
  import { PsychicApp } from '@rvoh/psychic';
3
5
  import { Job, Queue, Worker, } from 'bullmq';
4
6
  import ActivatingBackgroundWorkersWithoutDefaultWorkerConnection from '../error/background/ActivatingBackgroundWorkersWithoutDefaultWorkerConnection.js';
@@ -623,6 +625,3 @@ export class Background {
623
625
  }
624
626
  const background = new Background();
625
627
  export default background;
626
- export async function stopBackgroundWorkers() {
627
- await background.shutdown();
628
- }
@@ -1,4 +1,4 @@
1
- import { camelize } from '@rvoh/dream';
1
+ import { camelize } from '@rvoh/dream/utils';
2
2
  export default class AttemtedToBackgroundEntireDreamModel extends Error {
3
3
  method;
4
4
  dream;
@@ -0,0 +1,2 @@
1
+ export { default as NoQueueForSpecifiedQueueName } from '../error/background/NoQueueForSpecifiedQueueName.js';
2
+ export { default as NoQueueForSpecifiedWorkstream } from '../error/background/NoQueueForSpecifiedWorkstream.js';
@@ -0,0 +1,4 @@
1
+ export { default as background, Background } from '../background/index.js';
2
+ export { default as BaseBackgroundedModel } from '../background/BaseBackgroundedModel.js';
3
+ export { default as BaseBackgroundedService } from '../background/BaseBackgroundedService.js';
4
+ export { default as BaseScheduledService } from '../background/BaseScheduledService.js';
@@ -0,0 +1 @@
1
+ export { default as PsychicAppWorkers, } from '../psychic-app-workers/index.js';
@@ -0,0 +1 @@
1
+ export { default as WorkerTestUtils } from '../test-utils/WorkerTestUtils.js';
@@ -185,4 +185,3 @@ export declare class Background {
185
185
  }
186
186
  declare const background: Background;
187
187
  export default background;
188
- export declare function stopBackgroundWorkers(): Promise<void>;
@@ -0,0 +1,2 @@
1
+ export { default as NoQueueForSpecifiedQueueName } from '../error/background/NoQueueForSpecifiedQueueName.js';
2
+ export { default as NoQueueForSpecifiedWorkstream } from '../error/background/NoQueueForSpecifiedWorkstream.js';
@@ -0,0 +1,4 @@
1
+ export { default as background, Background } from '../background/index.js';
2
+ export { default as BaseBackgroundedModel } from '../background/BaseBackgroundedModel.js';
3
+ export { default as BaseBackgroundedService } from '../background/BaseBackgroundedService.js';
4
+ export { default as BaseScheduledService } from '../background/BaseScheduledService.js';
@@ -0,0 +1,2 @@
1
+ export { default as PsychicAppWorkers, type BullMQNativeWorkerOptions, type PsychicBackgroundNativeBullMQOptions, type PsychicBackgroundSimpleOptions, type PsychicBackgroundWorkstreamOptions, type QueueOptionsWithConnectionInstance, type RedisOrRedisClusterConnection, type TransitionalPsychicBackgroundSimpleOptions, } from '../psychic-app-workers/index.js';
2
+ export { type BackgroundJobConfig, type BackgroundQueuePriority } from '../types/background.js';
@@ -0,0 +1 @@
1
+ export { default as WorkerTestUtils } from '../test-utils/WorkerTestUtils.js';
package/package.json CHANGED
@@ -2,21 +2,36 @@
2
2
  "type": "module",
3
3
  "name": "@rvoh/psychic-workers",
4
4
  "description": "Background job system for Psychic applications",
5
- "version": "1.4.0",
5
+ "version": "2.0.0-alpha.2",
6
6
  "author": "RVO Health",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/rvohealth/psychic-workers.git"
10
10
  },
11
11
  "license": "MIT",
12
- "main": "./dist/cjs/src/index.js",
13
- "module": "./dist/esm/src/index.js",
14
- "types": "./dist/types/src/index.d.ts",
12
+ "main": "./dist/cjs/src/package-exports/index.js",
13
+ "module": "./dist/esm/src/package-exports/index.js",
14
+ "types": "./dist/types/src/package-exports/index.d.ts",
15
15
  "exports": {
16
16
  ".": {
17
- "types": "./dist/types/src/index.d.ts",
18
- "import": "./dist/esm/src/index.js",
19
- "require": "./dist/cjs/src/index.js"
17
+ "types": "./dist/types/src/package-exports/index.d.ts",
18
+ "import": "./dist/esm/src/package-exports/index.js",
19
+ "require": "./dist/cjs/src/package-exports/index.js"
20
+ },
21
+ "./errors": {
22
+ "types": "./dist/types/src/package-exports/errors.d.ts",
23
+ "import": "./dist/esm/src/package-exports/errors.js",
24
+ "require": "./dist/cjs/src/package-exports/errors.js"
25
+ },
26
+ "./types": {
27
+ "types": "./dist/types/src/package-exports/types.d.ts",
28
+ "import": "./dist/esm/src/package-exports/types.js",
29
+ "require": "./dist/cjs/src/package-exports/types.js"
30
+ },
31
+ "./utils": {
32
+ "types": "./dist/types/src/package-exports/utils.d.ts",
33
+ "import": "./dist/esm/src/package-exports/utils.js",
34
+ "require": "./dist/cjs/src/package-exports/utils.js"
20
35
  }
21
36
  },
22
37
  "files": [
@@ -27,6 +42,7 @@
27
42
  "psy:js": "node ./dist/test-app/src/cli/index.js",
28
43
  "psy:ts": "tsx ./test-app/src/cli/index.ts",
29
44
  "build": "echo \"building cjs...\" && rm -rf dist && npx tsc -p ./tsconfig.cjs.build.json && echo \"building esm...\" && npx tsc -p ./tsconfig.esm.build.json",
45
+ "build:test-app": "rm -rf dist && echo \"building test app to esm...\" && npx tsc -p ./tsconfig.esm.build.test-app.json && echo \"building test app to cjs...\" && npx tsc -p ./tsconfig.cjs.build.test-app.json",
30
46
  "uspec": "vitest --config ./spec/unit/vite.config.ts",
31
47
  "format": "yarn run prettier . --write",
32
48
  "lint": "yarn run eslint --no-warn-ignored \"src/**/*.ts\" && yarn run prettier . --check",
@@ -36,16 +52,16 @@
36
52
  "dev-worker": "NODE_ENV=development WORKER_COUNT=1 tsx ./test-app/worker.ts"
37
53
  },
38
54
  "peerDependencies": {
39
- "@rvoh/dream": "*",
40
- "@rvoh/psychic": "*",
55
+ "@rvoh/dream": "^2.0.0-alpha.3",
56
+ "@rvoh/psychic": "^2.0.0-alpha.2",
41
57
  "bullmq": "*",
42
58
  "ioredis": "*"
43
59
  },
44
60
  "devDependencies": {
45
61
  "@eslint/js": "=9.0.0",
46
- "@rvoh/dream": "^1.10.1",
62
+ "@rvoh/dream": "^2.0.0-alpha.3",
47
63
  "@rvoh/dream-spec-helpers": "^1.2.1",
48
- "@rvoh/psychic": "^1.11.1",
64
+ "@rvoh/psychic": "^2.0.0-alpha.2",
49
65
  "@rvoh/psychic-spec-helpers": "^1.1.3",
50
66
  "@socket.io/redis-adapter": "^8.3.0",
51
67
  "@socket.io/redis-emitter": "^5.1.0",
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WorkerTestUtils = exports.NoQueueForSpecifiedWorkstream = exports.NoQueueForSpecifiedQueueName = exports.PsychicAppWorkers = exports.BaseScheduledService = exports.BaseBackgroundedService = exports.BaseBackgroundedModel = exports.stopBackgroundWorkers = exports.Background = exports.background = void 0;
4
- var index_js_1 = require("./background/index.js");
5
- Object.defineProperty(exports, "background", { enumerable: true, get: function () { return index_js_1.default; } });
6
- Object.defineProperty(exports, "Background", { enumerable: true, get: function () { return index_js_1.Background; } });
7
- Object.defineProperty(exports, "stopBackgroundWorkers", { enumerable: true, get: function () { return index_js_1.stopBackgroundWorkers; } });
8
- var BaseBackgroundedModel_js_1 = require("./background/BaseBackgroundedModel.js");
9
- Object.defineProperty(exports, "BaseBackgroundedModel", { enumerable: true, get: function () { return BaseBackgroundedModel_js_1.default; } });
10
- var BaseBackgroundedService_js_1 = require("./background/BaseBackgroundedService.js");
11
- Object.defineProperty(exports, "BaseBackgroundedService", { enumerable: true, get: function () { return BaseBackgroundedService_js_1.default; } });
12
- var BaseScheduledService_js_1 = require("./background/BaseScheduledService.js");
13
- Object.defineProperty(exports, "BaseScheduledService", { enumerable: true, get: function () { return BaseScheduledService_js_1.default; } });
14
- var index_js_2 = require("./psychic-app-workers/index.js");
15
- Object.defineProperty(exports, "PsychicAppWorkers", { enumerable: true, get: function () { return index_js_2.default; } });
16
- var NoQueueForSpecifiedQueueName_js_1 = require("./error/background/NoQueueForSpecifiedQueueName.js");
17
- Object.defineProperty(exports, "NoQueueForSpecifiedQueueName", { enumerable: true, get: function () { return NoQueueForSpecifiedQueueName_js_1.default; } });
18
- var NoQueueForSpecifiedWorkstream_js_1 = require("./error/background/NoQueueForSpecifiedWorkstream.js");
19
- Object.defineProperty(exports, "NoQueueForSpecifiedWorkstream", { enumerable: true, get: function () { return NoQueueForSpecifiedWorkstream_js_1.default; } });
20
- var WorkerTestUtils_js_1 = require("./test-utils/WorkerTestUtils.js");
21
- Object.defineProperty(exports, "WorkerTestUtils", { enumerable: true, get: function () { return WorkerTestUtils_js_1.default; } });
@@ -1,8 +0,0 @@
1
- export { default as background, Background, stopBackgroundWorkers } from './background/index.js';
2
- export { default as BaseBackgroundedModel } from './background/BaseBackgroundedModel.js';
3
- export { default as BaseBackgroundedService } from './background/BaseBackgroundedService.js';
4
- export { default as BaseScheduledService } from './background/BaseScheduledService.js';
5
- export { default as PsychicAppWorkers, } from './psychic-app-workers/index.js';
6
- export { default as NoQueueForSpecifiedQueueName } from './error/background/NoQueueForSpecifiedQueueName.js';
7
- export { default as NoQueueForSpecifiedWorkstream } from './error/background/NoQueueForSpecifiedWorkstream.js';
8
- export { default as WorkerTestUtils } from './test-utils/WorkerTestUtils.js';
@@ -1,9 +0,0 @@
1
- export { default as background, Background, stopBackgroundWorkers } from './background/index.js';
2
- export { type BackgroundJobConfig, type BackgroundQueuePriority } from './types/background.js';
3
- export { default as BaseBackgroundedModel } from './background/BaseBackgroundedModel.js';
4
- export { default as BaseBackgroundedService } from './background/BaseBackgroundedService.js';
5
- export { default as BaseScheduledService } from './background/BaseScheduledService.js';
6
- export { default as PsychicAppWorkers, type BullMQNativeWorkerOptions, type PsychicBackgroundNativeBullMQOptions, type PsychicBackgroundSimpleOptions, type PsychicBackgroundWorkstreamOptions, type QueueOptionsWithConnectionInstance, type RedisOrRedisClusterConnection, type TransitionalPsychicBackgroundSimpleOptions, } from './psychic-app-workers/index.js';
7
- export { default as NoQueueForSpecifiedQueueName } from './error/background/NoQueueForSpecifiedQueueName.js';
8
- export { default as NoQueueForSpecifiedWorkstream } from './error/background/NoQueueForSpecifiedWorkstream.js';
9
- export { default as WorkerTestUtils } from './test-utils/WorkerTestUtils.js';