@rvoh/psychic-workers 0.2.9 → 0.3.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.
Files changed (46) hide show
  1. package/dist/cjs/src/background/BaseBackgroundedModel.js +105 -0
  2. package/dist/cjs/src/background/BaseBackgroundedService.js +71 -0
  3. package/dist/cjs/src/background/BaseScheduledService.js +51 -0
  4. package/dist/cjs/src/background/helpers/nameToRedisQueueName.js +10 -0
  5. package/dist/cjs/src/background/index.js +137 -68
  6. package/dist/cjs/src/error/background/ActivatingBackgroundWorkersWithoutDefaultWorkerConnection.js +11 -0
  7. package/dist/cjs/src/error/background/ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection.js +17 -0
  8. package/dist/cjs/src/error/background/DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection.js +11 -0
  9. package/dist/cjs/src/error/background/NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection.js +16 -0
  10. package/dist/cjs/src/index.js +3 -3
  11. package/dist/cjs/src/psychic-app-workers/cache.js +17 -0
  12. package/dist/cjs/src/{psychic-application-workers → psychic-app-workers}/index.js +9 -9
  13. package/dist/cjs/src/types/utils.js +2 -0
  14. package/dist/esm/src/background/BaseBackgroundedModel.js +105 -0
  15. package/dist/esm/src/background/BaseBackgroundedService.js +71 -0
  16. package/dist/esm/src/background/BaseScheduledService.js +51 -0
  17. package/dist/esm/src/background/helpers/nameToRedisQueueName.js +7 -0
  18. package/dist/esm/src/background/index.js +133 -64
  19. package/dist/esm/src/error/background/ActivatingBackgroundWorkersWithoutDefaultWorkerConnection.js +8 -0
  20. package/dist/esm/src/error/background/ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection.js +14 -0
  21. package/dist/esm/src/error/background/DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection.js +8 -0
  22. package/dist/esm/src/error/background/NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection.js +13 -0
  23. package/dist/esm/src/index.js +2 -2
  24. package/dist/esm/src/psychic-app-workers/cache.js +12 -0
  25. package/dist/esm/src/{psychic-application-workers → psychic-app-workers}/index.js +8 -8
  26. package/dist/esm/src/types/utils.js +1 -0
  27. package/dist/types/src/background/BaseBackgroundedModel.d.ts +108 -3
  28. package/dist/types/src/background/BaseBackgroundedService.d.ts +73 -2
  29. package/dist/types/src/background/BaseScheduledService.d.ts +53 -2
  30. package/dist/types/src/background/helpers/nameToRedisQueueName.d.ts +2 -0
  31. package/dist/types/src/background/index.d.ts +115 -30
  32. package/dist/types/src/error/background/ActivatingBackgroundWorkersWithoutDefaultWorkerConnection.d.ts +3 -0
  33. package/dist/types/src/error/background/ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection.d.ts +5 -0
  34. package/dist/types/src/error/background/DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection.d.ts +3 -0
  35. package/dist/types/src/error/background/NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection.d.ts +5 -0
  36. package/dist/types/src/index.d.ts +3 -2
  37. package/dist/types/src/psychic-app-workers/cache.d.ts +4 -0
  38. package/dist/types/src/{psychic-application-workers → psychic-app-workers}/index.d.ts +12 -12
  39. package/dist/types/src/types/background.d.ts +47 -0
  40. package/package.json +12 -12
  41. package/dist/cjs/src/psychic-application-workers/cache.js +0 -17
  42. package/dist/esm/src/psychic-application-workers/cache.js +0 -12
  43. package/dist/types/src/psychic-application-workers/cache.d.ts +0 -4
  44. /package/dist/cjs/src/{background/types.js → types/background.js} +0 -0
  45. /package/dist/esm/src/{background/types.js → types/background.js} +0 -0
  46. /package/dist/types/src/{background/types.d.ts → types/utils.d.ts} +0 -0
@@ -5,87 +5,100 @@ exports.stopBackgroundWorkers = stopBackgroundWorkers;
5
5
  const dream_1 = require("@rvoh/dream");
6
6
  const psychic_1 = require("@rvoh/psychic");
7
7
  const bullmq_1 = require("bullmq");
8
- const ioredis_1 = require("ioredis");
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");
9
12
  const NoQueueForSpecifiedQueueName_js_1 = require("../error/background/NoQueueForSpecifiedQueueName.js");
10
13
  const NoQueueForSpecifiedWorkstream_js_1 = require("../error/background/NoQueueForSpecifiedWorkstream.js");
11
14
  const EnvInternal_js_1 = require("../helpers/EnvInternal.js");
12
- const index_js_1 = require("../psychic-application-workers/index.js");
13
- class DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection extends Error {
14
- get message() {
15
- return `
16
- Native BullMQ options don't include a default queue connection, and the
17
- default config does not include a queue connection
18
- `;
19
- }
20
- }
21
- class NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection extends Error {
22
- queueName;
23
- constructor(queueName) {
24
- super();
25
- this.queueName = queueName;
26
- }
27
- get message() {
28
- return `
29
- Native BullMQ options don't include a default queue connection, and the
30
- ${this.queueName} queue does not include a queue connection
31
- `;
32
- }
33
- }
34
- class ActivatingBackgroundWorkersWithoutDefaultWorkerConnection extends Error {
35
- get message() {
36
- return `
37
- defaultWorkerConnection is required when activating workers. For example,
38
- it may be omitted on webserver instances, but is required on worker instances.
39
- `;
40
- }
41
- }
42
- class ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection extends Error {
43
- queueName;
44
- constructor(queueName) {
45
- super();
46
- this.queueName = queueName;
47
- }
48
- get message() {
49
- return `
50
- defaultWorkerConnection is missing, and the ${this.queueName} queue does not
51
- specify a workerConnection. A worker connection isrequired when activating workers.
52
- For example, it may be omitted on webserver instances, but is required on worker instances.
53
- `;
54
- }
55
- }
15
+ const index_js_1 = require("../psychic-app-workers/index.js");
16
+ const nameToRedisQueueName_js_1 = require("./helpers/nameToRedisQueueName.js");
17
+ /**
18
+ * the underlying class driving the `background` singleton,
19
+ * available as an import from `psychic-workers`.
20
+ */
56
21
  class Background {
22
+ /**
23
+ * returns the default queue name for your app
24
+ */
57
25
  static get defaultQueueName() {
58
26
  const psychicWorkersApp = index_js_1.default.getOrFail();
59
27
  return `${(0, dream_1.pascalize)(psychicWorkersApp.psychicApp.appName)}BackgroundJobQueue`;
60
28
  }
29
+ /**
30
+ * @internal
31
+ *
32
+ * returns the provided Worker class, or the Worker class from BullMQ
33
+ * if no override was provided. This is providable because BullMQ also
34
+ * offers a pro version, which requires you to provide custom classes.
35
+ */
61
36
  static get Worker() {
62
37
  const psychicWorkersApp = index_js_1.default.getOrFail();
63
38
  return (psychicWorkersApp.backgroundOptions.providers?.Worker || bullmq_1.Worker);
64
39
  }
40
+ /**
41
+ * @internal
42
+ *
43
+ * returns the provided Queue class, or the Queue class from BullMQ
44
+ * if no override was provided. This is providable because BullMQ also
45
+ * offers a pro version, which requires you to provide custom classes.
46
+ */
65
47
  static get Queue() {
66
48
  const psychicWorkersApp = index_js_1.default.getOrFail();
67
49
  return (psychicWorkersApp.backgroundOptions.providers?.Queue || bullmq_1.Queue);
68
50
  }
69
51
  /**
52
+ * @internal
53
+ *
70
54
  * Used when adding jobs to the default queue
71
55
  */
72
56
  defaultQueue = null;
73
57
  /**
58
+ * @internal
59
+ *
74
60
  * Used when adding jobs to the default transitional queue
75
61
  */
76
62
  defaultTransitionalQueue = null;
77
63
  /**
64
+ * @internal
65
+ *
78
66
  * Used when adding jobs to a named queue
79
67
  */
80
68
  namedQueues = {};
69
+ /**
70
+ * @internal
71
+ *
72
+ * Used when adding grouped jobs
73
+ */
81
74
  groupNames = {};
75
+ /**
76
+ * @internal
77
+ *
78
+ * Used when adding workstreams
79
+ */
82
80
  workstreamNames = [];
83
81
  /**
82
+ * @internal
83
+ *
84
84
  * Used when adding jobs to a named transitioanl queue
85
85
  */
86
86
  namedTransitionalQueues = {};
87
+ /**
88
+ * @internal
89
+ *
90
+ * All of the workers that are currently registered
91
+ */
87
92
  _workers = [];
93
+ /**
94
+ * @internal
95
+ *
96
+ * All of the redis connections that are currently registered
97
+ */
88
98
  redisConnections = [];
99
+ /**
100
+ * Establishes connection to BullMQ via redis
101
+ */
89
102
  connect({ activateWorkers = false, } = {}) {
90
103
  if (this.defaultQueue)
91
104
  return;
@@ -98,6 +111,9 @@ class Background {
98
111
  this.simpleConnect(defaultBullMQQueueOptions, psychicWorkersApp.backgroundOptions, { activateWorkers });
99
112
  }
100
113
  }
114
+ /**
115
+ * Returns all the queues in your application
116
+ */
101
117
  get queues() {
102
118
  return (0, dream_1.compact)([
103
119
  this.defaultQueue,
@@ -106,6 +122,9 @@ class Background {
106
122
  ...Object.values(this.namedTransitionalQueues).map(queue => queue),
107
123
  ]);
108
124
  }
125
+ /**
126
+ * Returns all the workers in your application
127
+ */
109
128
  get workers() {
110
129
  return [...this._workers];
111
130
  }
@@ -113,6 +132,9 @@ class Background {
113
132
  await this.shutdown();
114
133
  process.exit();
115
134
  }
135
+ /**
136
+ * Shuts down workers, closes all redis connections
137
+ */
116
138
  async shutdown() {
117
139
  await Promise.all(this._workers.map(worker => worker.close()));
118
140
  const psychicWorkersApp = index_js_1.default.getOrFail();
@@ -122,6 +144,9 @@ class Background {
122
144
  await (0, dream_1.closeAllDbConnections)();
123
145
  await this.closeAllRedisConnections();
124
146
  }
147
+ /**
148
+ * closes all redis connections for workers and queues
149
+ */
125
150
  async closeAllRedisConnections() {
126
151
  for (const queue of this.queues) {
127
152
  await queue.close();
@@ -138,6 +163,11 @@ class Background {
138
163
  }
139
164
  }
140
165
  }
166
+ /**
167
+ * @internal
168
+ *
169
+ * connects to BullMQ using workstream-based arguments
170
+ */
141
171
  simpleConnect(defaultBullMQQueueOptions, backgroundOptions, { activateWorkers = false, activatingTransitionalWorkstreams = false, }) {
142
172
  const defaultQueueConnection = backgroundOptions.defaultQueueConnection;
143
173
  const defaultWorkerConnection = backgroundOptions.defaultWorkerConnection;
@@ -148,7 +178,7 @@ class Background {
148
178
  // transitional queues must have the same names they had prior to making them
149
179
  // transitional since the name is what identifies the queues and enables the
150
180
  // queues to be worked off
151
- const formattedQueueName = nameToRedisQueueName(Background.defaultQueueName, defaultQueueConnection);
181
+ const formattedQueueName = (0, nameToRedisQueueName_js_1.default)(Background.defaultQueueName, defaultQueueConnection);
152
182
  ///////////////////////////////
153
183
  // create default workstream //
154
184
  ///////////////////////////////
@@ -170,7 +200,7 @@ class Background {
170
200
  /////////////////////////////
171
201
  if (activateWorkers) {
172
202
  if (!defaultWorkerConnection)
173
- throw new ActivatingBackgroundWorkersWithoutDefaultWorkerConnection();
203
+ throw new ActivatingBackgroundWorkersWithoutDefaultWorkerConnection_js_1.default();
174
204
  const workerCount = backgroundOptions.defaultWorkstream?.workerCount ?? 1;
175
205
  for (let i = 0; i < workerCount; i++) {
176
206
  this._workers.push(new Background.Worker(formattedQueueName, async (job) => await this.doWork(job), {
@@ -196,7 +226,7 @@ class Background {
196
226
  // transitional queues must have the same names they had prior to making them
197
227
  // transitional since the name is what identifies the queues and enables the
198
228
  // queues to be worked off
199
- const namedWorkstreamFormattedQueueName = nameToRedisQueueName(namedWorkstream.name, namedWorkstreamQueueConnection);
229
+ const namedWorkstreamFormattedQueueName = (0, nameToRedisQueueName_js_1.default)(namedWorkstream.name, namedWorkstreamQueueConnection);
200
230
  const namedQueue = new Background.Queue(namedWorkstreamFormattedQueueName, {
201
231
  ...defaultBullMQQueueOptions,
202
232
  connection: namedWorkstreamQueueConnection,
@@ -213,7 +243,7 @@ class Background {
213
243
  //////////////////////////
214
244
  if (activateWorkers) {
215
245
  if (!namedWorkstreamWorkerConnection)
216
- throw new ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection(namedWorkstream.name);
246
+ throw new ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection_js_1.default(namedWorkstream.name);
217
247
  const workerCount = namedWorkstream.workerCount ?? 1;
218
248
  for (let i = 0; i < workerCount; i++) {
219
249
  this._workers.push(new Background.Worker(namedWorkstreamFormattedQueueName, async (job) => await this.doWork(job), {
@@ -243,6 +273,11 @@ class Background {
243
273
  });
244
274
  }
245
275
  }
276
+ /**
277
+ * @internal
278
+ *
279
+ * connects to BullMQ using native BullMQ arguments
280
+ */
246
281
  nativeBullMQConnect(defaultBullMQQueueOptions, backgroundOptions, { activateWorkers = false, }) {
247
282
  const nativeBullMQ = backgroundOptions.nativeBullMQ;
248
283
  const defaultQueueConnection = nativeBullMQ.defaultQueueOptions?.queueConnection || backgroundOptions.defaultQueueConnection;
@@ -252,8 +287,8 @@ class Background {
252
287
  if (defaultWorkerConnection)
253
288
  this.redisConnections.push(defaultWorkerConnection);
254
289
  if (!defaultQueueConnection)
255
- throw new DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection();
256
- const formattedQueueName = nameToRedisQueueName(Background.defaultQueueName, defaultQueueConnection);
290
+ throw new DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection_js_1.default();
291
+ const formattedQueueName = (0, nameToRedisQueueName_js_1.default)(Background.defaultQueueName, defaultQueueConnection);
257
292
  //////////////////////////
258
293
  // create default queue //
259
294
  //////////////////////////
@@ -270,7 +305,7 @@ class Background {
270
305
  /////////////////////////////
271
306
  if (activateWorkers) {
272
307
  if (!defaultWorkerConnection)
273
- throw new ActivatingBackgroundWorkersWithoutDefaultWorkerConnection();
308
+ throw new ActivatingBackgroundWorkersWithoutDefaultWorkerConnection_js_1.default();
274
309
  const workerCount = nativeBullMQ.defaultWorkerCount ?? 1;
275
310
  for (let i = 0; i < workerCount; i++) {
276
311
  this._workers.push(new Background.Worker(formattedQueueName, async (job) => await this.doWork(job), {
@@ -295,8 +330,8 @@ class Background {
295
330
  const namedQueueConnection = namedQueueOptions.queueConnection || defaultQueueConnection;
296
331
  const namedWorkerConnection = namedQueueOptions.workerConnection || defaultWorkerConnection;
297
332
  if (!namedQueueConnection)
298
- throw new NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection(queueName);
299
- const formattedQueuename = nameToRedisQueueName(queueName, namedQueueConnection);
333
+ throw new NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection_js_1.default(queueName);
334
+ const formattedQueuename = (0, nameToRedisQueueName_js_1.default)(queueName, namedQueueConnection);
300
335
  this.namedQueues[queueName] = new Background.Queue(formattedQueuename, {
301
336
  ...defaultBullMQQueueOptions,
302
337
  ...namedQueueOptions,
@@ -313,7 +348,7 @@ class Background {
313
348
  this.groupNames[queueName].push(extraWorkerOptions.group.id);
314
349
  if (activateWorkers) {
315
350
  if (!namedWorkerConnection)
316
- throw new ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection(queueName);
351
+ throw new ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection_js_1.default(queueName);
317
352
  for (let i = 0; i < extraWorkerCount; i++) {
318
353
  this._workers.push(new Background.Worker(formattedQueuename, async (job) => await this.doWork(job), {
319
354
  ...extraWorkerOptions,
@@ -329,16 +364,34 @@ class Background {
329
364
  // end: create named queues //
330
365
  //////////////////////////////
331
366
  }
367
+ /**
368
+ * starts background workers
369
+ */
332
370
  work() {
333
371
  this.connect({ activateWorkers: true });
334
372
  process.on('SIGTERM', () => {
335
- void this.shutdownAndExit();
373
+ void this.shutdownAndExit()
374
+ .then(() => { })
375
+ .catch(() => { });
336
376
  });
337
377
  process.on('SIGINT', () => {
338
- void this.shutdownAndExit();
378
+ void this.shutdownAndExit()
379
+ .then(() => { })
380
+ .catch(() => { });
339
381
  });
340
382
  }
341
- async staticMethod(ObjectClass, method, { delaySeconds, globalName, args = [], jobConfig = {}, }) {
383
+ /**
384
+ * adds the static method of a provided class to BullMQ
385
+ *
386
+ * @param ObjectClass - the class you wish to background
387
+ * @param method - the method you wish to background
388
+ * @param globalName - the globalName of the class you are processing
389
+ * @param args - (optional) a list of arguments to provide to your method when it is called
390
+ * @param delaySeconds - (optional) the number of seconds you wish to wait before allowing this job to process
391
+ * @param importKey - (optional) the import key for the class
392
+ * @param jobConfig - (optional) the background job config to use when backgrounding this method
393
+ */
394
+ async staticMethod(ObjectClass, method, { globalName, delaySeconds, args = [], jobConfig = {}, }) {
342
395
  this.connect();
343
396
  await this._addToQueue(`BackgroundJobQueueStaticJob`, {
344
397
  globalName,
@@ -346,11 +399,23 @@ class Background {
346
399
  args,
347
400
  }, {
348
401
  delaySeconds,
349
- jobConfig: jobConfig,
402
+ jobConfig,
350
403
  groupId: this.jobConfigToGroupId(jobConfig),
351
404
  priority: this.jobConfigToPriority(jobConfig),
352
405
  });
353
406
  }
407
+ /**
408
+ * adds the static method of a provided class to BullMQ,
409
+ * to be scheduled to run at a specified cron pattern
410
+ *
411
+ * @param ObjectClass - the class you wish to background
412
+ * @param pattern - the cron string you wish to use to govern the scheduling for this job
413
+ * @param method - the method you wish to background
414
+ * @param globalName - the globalName of the class you are processing
415
+ * @param args - (optional) a list of arguments to provide to your method when it is called
416
+ * @param importKey - (optional) the import key for the class
417
+ * @param jobConfig - (optional) the background job config to use when backgrounding this method
418
+ */
354
419
  async scheduledMethod(ObjectClass, pattern, method, { globalName, args = [], jobConfig = {}, }) {
355
420
  this.connect();
356
421
  // `jobId` is used to determine uniqueness along with name and repeat pattern.
@@ -393,6 +458,16 @@ class Background {
393
458
  }
394
459
  return queueInstance;
395
460
  }
461
+ /**
462
+ * adds the instance method of a provided dream model to BullMQ
463
+ *
464
+ * @param modelInstance - the dream model instance you wish to background
465
+ * @param method - the method you wish to background
466
+ * @param globalName - the globalName of the class you are processing
467
+ * @param args - (optional) a list of arguments to provide to your method when it is called
468
+ * @param importKey - (optional) the import key for the class
469
+ * @param jobConfig - (optional) the background job config to use when backgrounding this method
470
+ */
396
471
  async modelInstanceMethod(modelInstance, method, { delaySeconds, args = [], jobConfig = {}, }) {
397
472
  this.connect();
398
473
  await this._addToQueue('BackgroundJobQueueModelInstanceJob', {
@@ -402,7 +477,7 @@ class Background {
402
477
  args,
403
478
  }, {
404
479
  delaySeconds,
405
- jobConfig: jobConfig,
480
+ jobConfig,
406
481
  groupId: this.jobConfigToGroupId(jobConfig),
407
482
  priority: this.jobConfigToPriority(jobConfig),
408
483
  });
@@ -493,7 +568,7 @@ class Background {
493
568
  case 'BackgroundJobQueueStaticJob':
494
569
  if (globalName) {
495
570
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
496
- objectClass = psychic_1.PsychicApplication.lookupClassByGlobalName(globalName);
571
+ objectClass = psychic_1.PsychicApp.lookupClassByGlobalName(globalName);
497
572
  }
498
573
  if (!objectClass)
499
574
  return;
@@ -502,7 +577,7 @@ class Background {
502
577
  break;
503
578
  case 'BackgroundJobQueueModelInstanceJob':
504
579
  if (globalName) {
505
- dreamClass = psychic_1.PsychicApplication.lookupClassByGlobalName(globalName);
580
+ dreamClass = psychic_1.PsychicApp.lookupClassByGlobalName(globalName);
506
581
  }
507
582
  if (dreamClass) {
508
583
  const modelInstance = await dreamClass.connection('primary').find(id);
@@ -521,9 +596,3 @@ exports.default = background;
521
596
  async function stopBackgroundWorkers() {
522
597
  await background.shutdown();
523
598
  }
524
- function nameToRedisQueueName(queueName, redis) {
525
- queueName = queueName.replace(/\{|\}/g, '');
526
- if (redis instanceof ioredis_1.Cluster)
527
- return `{${queueName}}`;
528
- return queueName;
529
- }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ActivatingBackgroundWorkersWithoutDefaultWorkerConnection extends Error {
4
+ get message() {
5
+ return `
6
+ defaultWorkerConnection is required when activating workers. For example,
7
+ it may be omitted on webserver instances, but is required on worker instances.
8
+ `;
9
+ }
10
+ }
11
+ exports.default = ActivatingBackgroundWorkersWithoutDefaultWorkerConnection;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection extends Error {
4
+ queueName;
5
+ constructor(queueName) {
6
+ super();
7
+ this.queueName = queueName;
8
+ }
9
+ get message() {
10
+ return `
11
+ defaultWorkerConnection is missing, and the ${this.queueName} queue does not
12
+ specify a workerConnection. A worker connection isrequired when activating workers.
13
+ For example, it may be omitted on webserver instances, but is required on worker instances.
14
+ `;
15
+ }
16
+ }
17
+ exports.default = ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection extends Error {
4
+ get message() {
5
+ return `
6
+ Native BullMQ options don't include a default queue connection, and the
7
+ default config does not include a queue connection
8
+ `;
9
+ }
10
+ }
11
+ exports.default = DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection extends Error {
4
+ queueName;
5
+ constructor(queueName) {
6
+ super();
7
+ this.queueName = queueName;
8
+ }
9
+ get message() {
10
+ return `
11
+ Native BullMQ options don't include a default queue connection, and the
12
+ ${this.queueName} queue does not include a queue connection
13
+ `;
14
+ }
15
+ }
16
+ exports.default = NamedBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NoQueueForSpecifiedWorkstream = exports.NoQueueForSpecifiedQueueName = exports.PsychicApplicationWorkers = exports.BaseScheduledService = exports.BaseBackgroundedService = exports.BaseBackgroundedModel = exports.stopBackgroundWorkers = exports.Background = exports.background = void 0;
3
+ exports.NoQueueForSpecifiedWorkstream = exports.NoQueueForSpecifiedQueueName = exports.PsychicAppWorkers = exports.BaseScheduledService = exports.BaseBackgroundedService = exports.BaseBackgroundedModel = exports.stopBackgroundWorkers = exports.Background = exports.background = void 0;
4
4
  var index_js_1 = require("./background/index.js");
5
5
  Object.defineProperty(exports, "background", { enumerable: true, get: function () { return index_js_1.default; } });
6
6
  Object.defineProperty(exports, "Background", { enumerable: true, get: function () { return index_js_1.Background; } });
@@ -11,8 +11,8 @@ var BaseBackgroundedService_js_1 = require("./background/BaseBackgroundedService
11
11
  Object.defineProperty(exports, "BaseBackgroundedService", { enumerable: true, get: function () { return BaseBackgroundedService_js_1.default; } });
12
12
  var BaseScheduledService_js_1 = require("./background/BaseScheduledService.js");
13
13
  Object.defineProperty(exports, "BaseScheduledService", { enumerable: true, get: function () { return BaseScheduledService_js_1.default; } });
14
- var index_js_2 = require("./psychic-application-workers/index.js");
15
- Object.defineProperty(exports, "PsychicApplicationWorkers", { enumerable: true, get: function () { return index_js_2.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
16
  var NoQueueForSpecifiedQueueName_js_1 = require("./error/background/NoQueueForSpecifiedQueueName.js");
17
17
  Object.defineProperty(exports, "NoQueueForSpecifiedQueueName", { enumerable: true, get: function () { return NoQueueForSpecifiedQueueName_js_1.default; } });
18
18
  var NoQueueForSpecifiedWorkstream_js_1 = require("./error/background/NoQueueForSpecifiedWorkstream.js");
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cachePsychicWorkersApp = cachePsychicWorkersApp;
4
+ exports.getCachedPsychicWorkersApp = getCachedPsychicWorkersApp;
5
+ exports.getCachedPsychicWorkersAppOrFail = getCachedPsychicWorkersAppOrFail;
6
+ let _psychicWorkersApp = undefined;
7
+ function cachePsychicWorkersApp(psychicWorkersApp) {
8
+ _psychicWorkersApp = psychicWorkersApp;
9
+ }
10
+ function getCachedPsychicWorkersApp() {
11
+ return _psychicWorkersApp;
12
+ }
13
+ function getCachedPsychicWorkersAppOrFail() {
14
+ if (!_psychicWorkersApp)
15
+ throw new Error('must call `cachePsychicWorkersApp` before loading cached psychic application workers');
16
+ return _psychicWorkersApp;
17
+ }
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const bullmq_1 = require("bullmq");
4
- const index_js_1 = require("../background/index.js");
5
4
  const cache_js_1 = require("./cache.js");
6
- class PsychicApplicationWorkers {
5
+ const index_js_1 = require("../background/index.js");
6
+ class PsychicAppWorkers {
7
7
  static async init(psychicApp, cb) {
8
- const psychicWorkersApp = new PsychicApplicationWorkers(psychicApp);
8
+ const psychicWorkersApp = new PsychicAppWorkers(psychicApp);
9
9
  await cb(psychicWorkersApp);
10
10
  psychicApp.on('sync', () => {
11
11
  index_js_1.default.connect();
@@ -18,17 +18,17 @@ class PsychicApplicationWorkers {
18
18
  psychicApp.on('server:shutdown', async () => {
19
19
  await index_js_1.default.closeAllRedisConnections();
20
20
  });
21
- (0, cache_js_1.cachePsychicWorkersApplication)(psychicWorkersApp);
21
+ (0, cache_js_1.cachePsychicWorkersApp)(psychicWorkersApp);
22
22
  return psychicWorkersApp;
23
23
  }
24
24
  /**
25
25
  * Returns the cached psychic application if it has been set.
26
26
  * If it has not been set, an exception is raised.
27
27
  *
28
- * The psychic application can be set by calling PsychicApplication#init
28
+ * The psychic application can be set by calling PsychicApp#init
29
29
  */
30
30
  static getOrFail() {
31
- return (0, cache_js_1.getCachedPsychicWorkersApplicationOrFail)();
31
+ return (0, cache_js_1.getCachedPsychicWorkersAppOrFail)();
32
32
  }
33
33
  psychicApp;
34
34
  constructor(psychicApp) {
@@ -53,7 +53,7 @@ class PsychicApplicationWorkers {
53
53
  this._hooks.workerShutdown.push(cb);
54
54
  break;
55
55
  default:
56
- throw new Error(`unrecognized event provided to PsychicWorkersApplication#on: ${hookEventType}`);
56
+ throw new Error(`unrecognized event provided to PsychicWorkersApp#on: ${hookEventType}`);
57
57
  }
58
58
  }
59
59
  set(option, value) {
@@ -70,8 +70,8 @@ class PsychicApplicationWorkers {
70
70
  };
71
71
  break;
72
72
  default:
73
- throw new Error(`Unhandled option type passed to PsychicWorkersApplication#set: ${option}`);
73
+ throw new Error(`Unhandled option type passed to PsychicWorkersApp#set: ${option}`);
74
74
  }
75
75
  }
76
76
  }
77
- exports.default = PsychicApplicationWorkers;
77
+ exports.default = PsychicAppWorkers;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });