bull-mqplugin-options.mdx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. ---
  2. title: "BullMQPluginOptions"
  3. generated: true
  4. ---
  5. <GenerationInfo sourceFile="packages/job-queue-plugin/src/bullmq/types.ts" sourceLine="21" packageName="@vendure/job-queue-plugin" since="1.2.0" />
  6. Configuration options for the [BullMQJobQueuePlugin](/reference/core-plugins/job-queue-plugin/bull-mqjob-queue-plugin#bullmqjobqueueplugin).
  7. ```ts title="Signature"
  8. interface BullMQPluginOptions {
  9. connection?: ConnectionOptions;
  10. queueOptions?: Omit<QueueOptions, 'connection'>;
  11. workerOptions?: Omit<WorkerOptions, 'connection'>;
  12. setRetries?: (queueName: string, job: Job) => number;
  13. setBackoff?: (queueName: string, job: Job) => BackoffOptions | undefined;
  14. setJobOptions?: (queueName: string, job: Job) => BullJobsOptions;
  15. }
  16. ```
  17. <div className="members-wrapper">
  18. ### connection
  19. <MemberInfo kind="property" type={`ConnectionOptions`} />
  20. Connection options which will be passed directly to BullMQ when
  21. creating a new Queue, Worker and Scheduler instance.
  22. If omitted, it will attempt to connect to Redis at `127.0.0.1:6379`.
  23. ### queueOptions
  24. <MemberInfo kind="property" type={`Omit<QueueOptions, 'connection'>`} />
  25. Additional options used when instantiating the BullMQ
  26. Queue instance.
  27. See the [BullMQ QueueOptions docs](https://github.com/taskforcesh/bullmq/blob/master/docs/gitbook/api/bullmq.queueoptions.md)
  28. ### workerOptions
  29. <MemberInfo kind="property" type={`Omit<WorkerOptions, 'connection'>`} />
  30. Additional options used when instantiating the BullMQ
  31. Worker instance.
  32. See the [BullMQ WorkerOptions docs](https://github.com/taskforcesh/bullmq/blob/master/docs/gitbook/api/bullmq.workeroptions.md)
  33. ### setRetries
  34. <MemberInfo kind="property" type={`(queueName: string, job: Job) => number`} since="1.3.0" />
  35. When a job is added to the JobQueue using `JobQueue.add()`, the calling
  36. code may specify the number of retries in case of failure. This option allows
  37. you to override that number and specify your own number of retries based on
  38. the job being added.
  39. *Example*
  40. ```ts
  41. setRetries: (queueName, job) => {
  42. if (queueName === 'send-email') {
  43. // Override the default number of retries
  44. // for the 'send-email' job because we have
  45. // a very unreliable email service.
  46. return 10;
  47. }
  48. return job.retries;
  49. }
  50. ```
  51. ### setBackoff
  52. <MemberInfo kind="property" type={`(queueName: string, job: Job) => <a href='/reference/core-plugins/job-queue-plugin/bull-mqplugin-options#backoffoptions'>BackoffOptions</a> | undefined`} default={`'exponential', 1000`} since="1.3.0" />
  53. This allows you to specify the backoff settings when a failed job gets retried.
  54. In other words, this determines how much time should pass before attempting to
  55. process the failed job again. If the function returns `undefined`, the default
  56. value of exponential/1000ms will be used.
  57. *Example*
  58. ```ts
  59. setBackoff: (queueName, job) => {
  60. return {
  61. type: 'exponential', // or 'fixed'
  62. delay: 10000 // first retry after 10s, second retry after 20s, 40s,...
  63. };
  64. }
  65. ```
  66. ### setJobOptions
  67. <MemberInfo kind="property" type={`(queueName: string, job: Job) => BullJobsOptions`} since="3.2.0" />
  68. This allows you to specify additional options for a job when it is added to the queue.
  69. The object returned is the BullMQ [JobsOptions](https://api.docs.bullmq.io/types/v5.JobsOptions.html)
  70. type, which includes control over settings such as `delay`, `attempts`, `priority` and much more.
  71. This function is called every time a job is added to the queue, so you can return different options
  72. based on the job being added.
  73. *Example*
  74. ```ts
  75. // Here we want to assign a higher priority to jobs in the 'critical' queue
  76. setJobOptions: (queueName, job) => {
  77. const priority = queueName === 'critical' ? 1 : 5;
  78. return { priority };
  79. }
  80. ```
  81. </div>
  82. <GenerationInfo sourceFile="packages/job-queue-plugin/src/bullmq/types.ts" sourceLine="122" packageName="@vendure/job-queue-plugin" since="1.3.0" />
  83. Configuration for the backoff function when retrying failed jobs.
  84. ```ts title="Signature"
  85. interface BackoffOptions {
  86. type: 'exponential' | 'fixed';
  87. delay: number;
  88. }
  89. ```
  90. <div className="members-wrapper">
  91. ### type
  92. <MemberInfo kind="property" type={`'exponential' | 'fixed'`} />
  93. ### delay
  94. <MemberInfo kind="property" type={`number`} />
  95. </div>