Browse Source

refactor(core): Move `supportsListAllQueues` out of VendureConfig

This property was moved onto the InspectableJobQueueStrategy interface, since
it is tightly bound to a specific strategy, and should not be settable
from elsewhere, like with regular VendureConfig options.
Michael Bromley 1 year ago
parent
commit
48dfd1479a

+ 8 - 1
packages/core/src/api/resolvers/admin/global-settings.resolver.ts

@@ -32,6 +32,7 @@ import {
     RelationCustomFieldConfig,
     StructCustomFieldConfig,
 } from '../../../config/custom-field/custom-field-types';
+import { isInspectableJobQueueStrategy } from '../../../config/job-queue/inspectable-job-queue-strategy';
 import { GlobalSettings } from '../../../entity/global-settings/global-settings.entity';
 import { ChannelService } from '../../../service/services/channel.service';
 import { GlobalSettingsService } from '../../../service/services/global-settings.service';
@@ -64,6 +65,11 @@ export class GlobalSettingsResolver {
         const permissions = getAllPermissionsMetadata(
             this.configService.authOptions.customPermissions,
         ).filter(p => !p.internal);
+        const { jobQueueStrategy } = this.configService.jobQueueOptions;
+        const isInspectable = isInspectableJobQueueStrategy(jobQueueStrategy);
+        const supportsListAllQueues = isInspectable
+            ? jobQueueStrategy.supportsListAllQueues !== false
+            : false;
         return {
             customFieldConfig: this.generateCustomFieldConfig(info),
             entityCustomFields: this.generateEntityCustomFieldConfig(info),
@@ -72,7 +78,8 @@ export class GlobalSettingsResolver {
             permissions,
             moneyStrategyPrecision: this.configService.entityOptions.moneyStrategy.precision ?? 2,
             jobQueue: {
-                supportsListAllQueues: this.configService.jobQueueOptions.supportsListAllQueues ?? true,
+                isInspectable,
+                supportsListAllQueues,
             },
         };
     }

+ 12 - 3
packages/core/src/api/schema/admin-api/global-settings.type.graphql

@@ -19,15 +19,24 @@ type PermissionDefinition {
     assignable: Boolean!
 }
 
-type JobQueueConfig {
+type JobQueueInfo {
+    """
+    Whether the JobQueue is inspectable, i.e. it is possible to fetch
+    information about jobs and their state.
+    """
+    isInspectable: Boolean!
+    """
+    Whether the JobQueue supports listing all queues at once. If this is false,
+    then the `jobs` query must have a `queueName` filter set.
+    """
     supportsListAllQueues: Boolean!
 }
 
-# Programatically extended by the addGraphQLCustomFields function
+# Programmatically extended by the addGraphQLCustomFields function
 type ServerConfig {
     orderProcess: [OrderProcessState!]!
     permittedAssetTypes: [String!]!
     permissions: [PermissionDefinition!]!
     moneyStrategyPrecision: Int!
-    jobQueue: JobQueueConfig!
+    jobQueue: JobQueueInfo!
 }

+ 0 - 1
packages/core/src/config/default-config.ts

@@ -191,7 +191,6 @@ export const defaultConfig: RuntimeVendureConfig = {
         jobBufferStorageStrategy: new InMemoryJobBufferStorageStrategy(),
         activeQueues: [],
         prefix: '',
-        supportsListAllQueues: true,
     },
     customFields: {
         Address: [],

+ 11 - 0
packages/core/src/config/job-queue/inspectable-job-queue-strategy.ts

@@ -12,6 +12,17 @@ import { JobQueueStrategy } from './job-queue-strategy';
  * @docsCategory JobQueue
  */
 export interface InspectableJobQueueStrategy extends JobQueueStrategy {
+    /**
+     * @description
+     * Whether the `jobs` query should return a list of all jobs across all queues.
+     * If this is `false`, the `jobs` query will only return jobs for the specified queue.
+     * Defaults to `true`.
+     *
+     * @default true
+     * @since 3.1.0
+     */
+    supportsListAllQueues?: boolean;
+
     /**
      * @description
      * Returns a job by its id.

+ 0 - 9
packages/core/src/config/vendure-config.ts

@@ -951,15 +951,6 @@ export interface JobQueueOptions {
      * @since 1.5.0
      */
     prefix?: string;
-
-    /**
-     * @description
-     * Defines if the job queue strategy supports listing all jobs of all queues.
-     * By default, this is set to true, but some strategies may not support this feature.
-     *
-     * @since 3.1.0
-     */
-    supportsListAllQueues?: boolean;
 }
 
 /**

+ 10 - 0
packages/job-queue-plugin/src/bullmq/bullmq-job-queue-strategy.ts

@@ -53,6 +53,16 @@ export class BullMQJobQueueStrategy implements InspectableJobQueueStrategy {
     private readonly CANCELLED_JOB_LIST_NAME = 'vendure:cancelled-jobs';
     private jobQueueService: JobQueueService;
 
+    /**
+     * Currently, this strategy does not support listing all jobs across all queues.
+     * This limitation was introduced in v3.1.0 and may be lifted in a future version.
+     *
+     * The reason for this chance was a switch from using a single BullMQ queue for all jobs to using
+     * a separate queue for each JobQueue. This change was made to allow for more fine-grained control
+     * over the processing of different types of jobs.
+     */
+    readonly supportsListAllQueues = false;
+
     async init(injector: Injector): Promise<void> {
         const options = injector.get<BullMQPluginOptions>(BULLMQ_PLUGIN_OPTIONS);
         this.jobQueueService = injector.get(JobQueueService);

+ 0 - 1
packages/job-queue-plugin/src/bullmq/plugin.ts

@@ -136,7 +136,6 @@ import { BullMQPluginOptions } from './types';
     configuration: config => {
         config.jobQueueOptions.jobQueueStrategy = new BullMQJobQueueStrategy();
         config.jobQueueOptions.jobBufferStorageStrategy = new RedisJobBufferStorageStrategy();
-        config.jobQueueOptions.supportsListAllQueues = false;
         config.systemOptions.healthChecks.push(new RedisHealthCheckStrategy());
         return config;
     },