@rvoh/psychic-workers 0.4.2 → 0.4.3

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.
@@ -430,7 +430,7 @@ class Background {
430
430
  * @param importKey - (optional) the import key for the class
431
431
  * @param jobConfig - (optional) the background job config to use when backgrounding this method
432
432
  */
433
- async scheduledMethod(ObjectClass, pattern, method, { globalName, args = [], jobConfig = {}, }) {
433
+ async scheduledMethod(ObjectClass, pattern, method, { globalName, args = [], jobConfig = {}, scheduleOpts = {}, }) {
434
434
  this.connect();
435
435
  // `jobId` is used to determine uniqueness along with name and repeat pattern.
436
436
  // Since the name is really a job type and never changes, the `jobId` is the only
@@ -438,22 +438,18 @@ class Background {
438
438
  // now be enforced by combining class name, method name, and cron repeat pattern.
439
439
  //
440
440
  // See: https://docs.bullmq.io/guide/jobs/repeatable
441
- const jobId = `${ObjectClass.name}:${method}`;
441
+ const schedulerId = `${globalName}:${method}`;
442
442
  const queueInstance = this.queueInstance(jobConfig);
443
443
  if (!queueInstance)
444
444
  throw new Error(`Missing queue for: ${jobConfig.queue?.toString()}`);
445
- await queueInstance.add('BackgroundJobQueueStaticJob', {
446
- globalName,
447
- method,
448
- args,
449
- }, {
450
- repeat: {
451
- pattern,
445
+ await queueInstance.upsertJobScheduler(schedulerId, { pattern }, {
446
+ name: schedulerId,
447
+ opts: scheduleOpts,
448
+ data: {
449
+ globalName,
450
+ method,
451
+ args,
452
452
  },
453
- jobId,
454
- group: this.jobConfigToGroup(jobConfig),
455
- priority: this.mapPriorityWordToPriorityNumber(this.jobConfigToPriority(jobConfig)),
456
- // explicitly typing as JobsOptions because Psychic can't be aware of BullMQ Pro options
457
453
  });
458
454
  }
459
455
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1,6 +1,6 @@
1
1
  import { closeAllDbConnections, compact, pascalize } from '@rvoh/dream';
2
2
  import { PsychicApp } from '@rvoh/psychic';
3
- import { Job, Queue, Worker } from 'bullmq';
3
+ import { Job, Queue, Worker, } from 'bullmq';
4
4
  import ActivatingBackgroundWorkersWithoutDefaultWorkerConnection from '../error/background/ActivatingBackgroundWorkersWithoutDefaultWorkerConnection.js';
5
5
  import ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection from '../error/background/ActivatingNamedQueueBackgroundWorkersWithoutWorkerConnection.js';
6
6
  import DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection from '../error/background/DefaultBullMQNativeOptionsMissingQueueConnectionAndDefaultQueueConnection.js';
@@ -426,7 +426,7 @@ export class Background {
426
426
  * @param importKey - (optional) the import key for the class
427
427
  * @param jobConfig - (optional) the background job config to use when backgrounding this method
428
428
  */
429
- async scheduledMethod(ObjectClass, pattern, method, { globalName, args = [], jobConfig = {}, }) {
429
+ async scheduledMethod(ObjectClass, pattern, method, { globalName, args = [], jobConfig = {}, scheduleOpts = {}, }) {
430
430
  this.connect();
431
431
  // `jobId` is used to determine uniqueness along with name and repeat pattern.
432
432
  // Since the name is really a job type and never changes, the `jobId` is the only
@@ -434,22 +434,18 @@ export class Background {
434
434
  // now be enforced by combining class name, method name, and cron repeat pattern.
435
435
  //
436
436
  // See: https://docs.bullmq.io/guide/jobs/repeatable
437
- const jobId = `${ObjectClass.name}:${method}`;
437
+ const schedulerId = `${globalName}:${method}`;
438
438
  const queueInstance = this.queueInstance(jobConfig);
439
439
  if (!queueInstance)
440
440
  throw new Error(`Missing queue for: ${jobConfig.queue?.toString()}`);
441
- await queueInstance.add('BackgroundJobQueueStaticJob', {
442
- globalName,
443
- method,
444
- args,
445
- }, {
446
- repeat: {
447
- pattern,
441
+ await queueInstance.upsertJobScheduler(schedulerId, { pattern }, {
442
+ name: schedulerId,
443
+ opts: scheduleOpts,
444
+ data: {
445
+ globalName,
446
+ method,
447
+ args,
448
448
  },
449
- jobId,
450
- group: this.jobConfigToGroup(jobConfig),
451
- priority: this.mapPriorityWordToPriorityNumber(this.jobConfigToPriority(jobConfig)),
452
- // explicitly typing as JobsOptions because Psychic can't be aware of BullMQ Pro options
453
449
  });
454
450
  }
455
451
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1,5 +1,5 @@
1
1
  import { Dream } from '@rvoh/dream';
2
- import { Job, Queue, Worker } from 'bullmq';
2
+ import { Job, JobSchedulerTemplateOptions, Queue, Worker } from 'bullmq';
3
3
  import { BackgroundJobConfig, BackgroundJobData, BackgroundQueuePriority, JobTypes } from '../types/background.js';
4
4
  /**
5
5
  * the underlying class driving the `background` singleton,
@@ -145,12 +145,11 @@ export declare class Background {
145
145
  * @param importKey - (optional) the import key for the class
146
146
  * @param jobConfig - (optional) the background job config to use when backgrounding this method
147
147
  */
148
- scheduledMethod(ObjectClass: Record<'name', string>, pattern: string, method: string, { globalName, args, jobConfig, }: {
148
+ scheduledMethod(ObjectClass: Record<'name', string>, pattern: string, method: string, { globalName, args, jobConfig, scheduleOpts, }: {
149
149
  globalName: string;
150
150
  args?: any[];
151
- filepath?: string;
152
- importKey?: string;
153
151
  jobConfig?: BackgroundJobConfig<any>;
152
+ scheduleOpts?: JobSchedulerTemplateOptions;
154
153
  }): Promise<void>;
155
154
  private queueInstance;
156
155
  /**
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.2",
5
+ "version": "0.4.3",
6
6
  "author": "RVO Health",
7
7
  "repository": {
8
8
  "type": "git",
@@ -73,4 +73,4 @@
73
73
  "vitest": "^3.1.1"
74
74
  },
75
75
  "packageManager": "yarn@4.7.0"
76
- }
76
+ }