@rvoh/psychic-workers 0.3.1 → 0.3.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.
@@ -322,6 +322,7 @@ class Background {
|
|
322
322
|
/////////////////////////
|
323
323
|
const namedQueueOptionsMap = nativeBullMQ.namedQueueOptions || {};
|
324
324
|
Object.keys(namedQueueOptionsMap).forEach(queueName => {
|
325
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
325
326
|
const namedQueueOptions = namedQueueOptionsMap[queueName];
|
326
327
|
if (namedQueueOptions.queueConnection)
|
327
328
|
this.redisConnections.push(namedQueueOptions.queueConnection);
|
@@ -344,7 +345,7 @@ class Background {
|
|
344
345
|
const extraWorkerOptions = extraWorkerOptionsMap[queueName];
|
345
346
|
const extraWorkerCount = extraWorkerOptions ? (extraWorkerOptions.workerCount ?? 1) : 0;
|
346
347
|
this.groupNames[queueName] ||= [];
|
347
|
-
if (extraWorkerOptions
|
348
|
+
if (extraWorkerOptions?.group?.id)
|
348
349
|
this.groupNames[queueName].push(extraWorkerOptions.group.id);
|
349
350
|
if (activateWorkers) {
|
350
351
|
if (!namedWorkerConnection)
|
@@ -425,7 +426,10 @@ class Background {
|
|
425
426
|
//
|
426
427
|
// See: https://docs.bullmq.io/guide/jobs/repeatable
|
427
428
|
const jobId = `${ObjectClass.name}:${method}`;
|
428
|
-
|
429
|
+
const queueInstance = this.queueInstance(jobConfig);
|
430
|
+
if (!queueInstance)
|
431
|
+
throw new Error(`Missing queue for: ${jobConfig.queue?.toString()}`);
|
432
|
+
await queueInstance.add('BackgroundJobQueueStaticJob', {
|
429
433
|
globalName,
|
430
434
|
method,
|
431
435
|
args,
|
@@ -492,9 +496,12 @@ class Background {
|
|
492
496
|
const queue = new Background.Queue('TestQueue', { connection: {} });
|
493
497
|
const job = new bullmq_1.Job(queue, jobType, jobData, {});
|
494
498
|
await this.doWork(job);
|
499
|
+
return;
|
495
500
|
//
|
496
501
|
}
|
497
|
-
|
502
|
+
if (!queueInstance)
|
503
|
+
throw new Error(`missing queue: ${jobConfig?.queue?.toString() || 'N/A'}`);
|
504
|
+
if (groupId && priority) {
|
498
505
|
await queueInstance.add(jobType, jobData, {
|
499
506
|
delay,
|
500
507
|
group: {
|
@@ -318,6 +318,7 @@ export class Background {
|
|
318
318
|
/////////////////////////
|
319
319
|
const namedQueueOptionsMap = nativeBullMQ.namedQueueOptions || {};
|
320
320
|
Object.keys(namedQueueOptionsMap).forEach(queueName => {
|
321
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
321
322
|
const namedQueueOptions = namedQueueOptionsMap[queueName];
|
322
323
|
if (namedQueueOptions.queueConnection)
|
323
324
|
this.redisConnections.push(namedQueueOptions.queueConnection);
|
@@ -340,7 +341,7 @@ export class Background {
|
|
340
341
|
const extraWorkerOptions = extraWorkerOptionsMap[queueName];
|
341
342
|
const extraWorkerCount = extraWorkerOptions ? (extraWorkerOptions.workerCount ?? 1) : 0;
|
342
343
|
this.groupNames[queueName] ||= [];
|
343
|
-
if (extraWorkerOptions
|
344
|
+
if (extraWorkerOptions?.group?.id)
|
344
345
|
this.groupNames[queueName].push(extraWorkerOptions.group.id);
|
345
346
|
if (activateWorkers) {
|
346
347
|
if (!namedWorkerConnection)
|
@@ -421,7 +422,10 @@ export class Background {
|
|
421
422
|
//
|
422
423
|
// See: https://docs.bullmq.io/guide/jobs/repeatable
|
423
424
|
const jobId = `${ObjectClass.name}:${method}`;
|
424
|
-
|
425
|
+
const queueInstance = this.queueInstance(jobConfig);
|
426
|
+
if (!queueInstance)
|
427
|
+
throw new Error(`Missing queue for: ${jobConfig.queue?.toString()}`);
|
428
|
+
await queueInstance.add('BackgroundJobQueueStaticJob', {
|
425
429
|
globalName,
|
426
430
|
method,
|
427
431
|
args,
|
@@ -488,9 +492,12 @@ export class Background {
|
|
488
492
|
const queue = new Background.Queue('TestQueue', { connection: {} });
|
489
493
|
const job = new Job(queue, jobType, jobData, {});
|
490
494
|
await this.doWork(job);
|
495
|
+
return;
|
491
496
|
//
|
492
497
|
}
|
493
|
-
|
498
|
+
if (!queueInstance)
|
499
|
+
throw new Error(`missing queue: ${jobConfig?.queue?.toString() || 'N/A'}`);
|
500
|
+
if (groupId && priority) {
|
494
501
|
await queueInstance.add(jobType, jobData, {
|
495
502
|
delay,
|
496
503
|
group: {
|
@@ -169,10 +169,10 @@ export declare class Background {
|
|
169
169
|
jobConfig?: BackgroundJobConfig<any>;
|
170
170
|
}): Promise<void>;
|
171
171
|
_addToQueue(jobType: JobTypes, jobData: BackgroundJobData, { delaySeconds, jobConfig, priority, groupId, }: {
|
172
|
-
delaySeconds?: number;
|
172
|
+
delaySeconds?: number | undefined;
|
173
173
|
jobConfig: BackgroundJobConfig<any>;
|
174
174
|
priority: BackgroundQueuePriority;
|
175
|
-
groupId?: string;
|
175
|
+
groupId?: string | undefined;
|
176
176
|
}): Promise<void>;
|
177
177
|
private jobConfigToPriority;
|
178
178
|
private jobConfigToGroupId;
|
@@ -103,7 +103,7 @@ export type QueueOptionsWithConnectionInstance = Omit<QueueOptions, 'connection'
|
|
103
103
|
* queue and worker connections.
|
104
104
|
*/
|
105
105
|
queueConnection?: RedisOrRedisClusterConnection;
|
106
|
-
workerConnection?: RedisOrRedisClusterConnection;
|
106
|
+
workerConnection?: RedisOrRedisClusterConnection | undefined;
|
107
107
|
};
|
108
108
|
export interface PsychicBackgroundSimpleOptions extends PsychicBackgroundSharedOptions {
|
109
109
|
/**
|
@@ -114,7 +114,7 @@ export interface PsychicBackgroundSimpleOptions extends PsychicBackgroundSharedO
|
|
114
114
|
/**
|
115
115
|
* defaultWorkerConnection is only optional when workers will not be activated (e.g. on the webserver)
|
116
116
|
*/
|
117
|
-
defaultWorkerConnection
|
117
|
+
defaultWorkerConnection: RedisOrRedisClusterConnection | undefined;
|
118
118
|
/**
|
119
119
|
* Every Psychic application that leverages simple background jobs will have a default
|
120
120
|
* workstream. Set workerCount to set the number of workers that will work through the
|