Kaynağa Gözat

docs: Add some more docs on job queue plugin

Michael Bromley 4 yıl önce
ebeveyn
işleme
8339c3cb71

+ 13 - 5
docs/content/developer-guide/job-queue/index.md

@@ -19,10 +19,12 @@ Some operations however will need to perform much longer-running tasks. For exam
 
 ## What does Vendure use the job queue for?
 
--   Re-building the search index
--   Updating the search index when changes are made to Products, ProductVariants, Assets etc.
--   Updating the contents of Collections
--   Sending transactional emails
+By default, Vendure uses the job queue for the following tasks:
+
+- Re-building the search index
+- Updating the search index when changes are made to Products, ProductVariants, Assets etc.
+- Updating the contents of Collections
+- Sending transactional emails
 
 ## How does the Job Queue work?
 
@@ -40,7 +42,13 @@ If no strategy is defined, Vendure uses an [in-memory store]({{< relref "in-memo
 
 A better alternative is to use the [DefaultJobQueuePlugin]({{< relref "default-job-queue-plugin" >}}) (which will be used in a standard `@vendure/create` installation), which configures Vendure to use the [SqlJobQueueStrategy]({{< relref "sql-job-queue-strategy" >}}). This strategy uses the database as a queue, and means that event if the Vendure server stops, pending jobs will be persisted and upon re-start, they will be processed.
 
-It is also possible to implement your own JobQueueStrategy to take advantage of other technologies. Examples include Redis, RabbitMQ, Google Cloud Pub Sub & Amazon SQS. It may make sense to implement a custom strategy based on one of these if the default database-based approach does not meet your performance requirements.
+It is also possible to implement your own JobQueueStrategy to take advantage of other technologies. Examples include RabbitMQ, Google Cloud Pub Sub & Amazon SQS. It may make sense to implement a custom strategy based on one of these if the default database-based approach does not meet your performance requirements.
+
+## Job Queue Performance
+
+It is common for larger Vendure projects to define multiple custom job queues, When using the [DefaultJobQueuePlugin]({{< relref "default-job-queue-plugin" >}}) with many queues, performance may be impacted. This is because the `SqlJobQueueStrategy` uses polling to check for new jobs in the database. Each queue will (by default) query the database every 200ms. So if there are 10 queues, this will result in a constant 50 queries/second.
+
+In this case it is recommended to try the [BullMQJobQueuePlugin]({{< relref "bull-mqjob-queue-plugin" >}}), which uses an efficient push-based strategy built on Redis.
 
 ## Using Job Queues in a plugin
 

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

@@ -52,6 +52,33 @@ import { BullMQPluginOptions } from './types';
  * };
  * ```
  *
+ * ### Running Redis locally
+ *
+ * To develop with this plugin, you'll need an instance of Redis to connect to. Here's a docker-compose config
+ * that will set up [Redis](https://redis.io/) as well as [Redis Commander](https://github.com/joeferner/redis-commander),
+ * which is a web-based UI for interacting with Redis:
+ *
+ * ```YAML
+ * version: "3"
+ * services:
+ *   redis:
+ *     image: bitnami/redis:6.2
+ *     hostname: redis
+ *     container_name: redis
+ *     environment:
+ *       - ALLOW_EMPTY_PASSWORD=yes
+ *     ports:
+ *       - "6379:6379"
+ *   redis-commander:
+ *     container_name: redis-commander
+ *     hostname: redis-commander
+ *     image: rediscommander/redis-commander:latest
+ *     environment:
+ *       - REDIS_HOSTS=local:redis:6379
+ *     ports:
+ *       - "8085:8081"
+ * ```
+ *
  * ## Concurrency
  *
  * The default concurrency of a single worker is 3, i.e. up to 3 jobs will be processed at the same time.

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

@@ -21,18 +21,21 @@ export interface BullMQPluginOptions {
      * @description
      * Additional options used when instantiating the BullMQ
      * Queue instance.
+     * See the [BullMQ QueueOptions docs](https://github.com/taskforcesh/bullmq/blob/master/docs/gitbook/api/bullmq.queueoptions.md)
      */
     queueOptions?: Exclude<QueueOptions, 'connection'>;
     /**
      * @description
      * Additional options used when instantiating the BullMQ
      * Worker instance.
+     * See the [BullMQ WorkerOptions docs](https://github.com/taskforcesh/bullmq/blob/master/docs/gitbook/api/bullmq.workeroptions.md)
      */
     workerOptions?: Exclude<WorkerOptions, 'connection'>;
     /**
      * @description
      * Additional options used when instantiating the BullMQ
      * QueueScheduler instance.
+     * See the [BullMQ QueueSchedulerOptions docs](https://github.com/taskforcesh/bullmq/blob/master/docs/gitbook/api/bullmq.queuescheduleroptions.md)
      */
     schedulerOptions?: Exclude<QueueSchedulerOptions, 'connection'>;
 }