worker-options.d.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { AdvancedOptions } from './advanced-options';
  2. import { QueueBaseOptions } from './queue-options';
  3. import { RateLimiterOptions } from './rate-limiter-options';
  4. import { MetricsOptions } from './metrics-options';
  5. import { KeepJobs } from '../types/keep-jobs';
  6. import { Telemetry } from './telemetry';
  7. import { SandboxedOptions } from './sandboxed-options';
  8. export interface WorkerOptions extends QueueBaseOptions, SandboxedOptions {
  9. /**
  10. * Optional worker name. The name will be stored on every job
  11. * processed by this worker instance, and can be used to monitor
  12. * which worker is processing or has processed a given job.
  13. */
  14. name?: string;
  15. /**
  16. * Condition to start processor at instance creation.
  17. *
  18. * @defaultValue true
  19. */
  20. autorun?: boolean;
  21. /**
  22. * Amount of jobs that a single worker is allowed to work on
  23. * in parallel.
  24. *
  25. * @defaultValue 1
  26. * @see {@link https://docs.bullmq.io/guide/workers/concurrency}
  27. */
  28. concurrency?: number;
  29. /**
  30. * Enable rate limiter
  31. * @see {@link https://docs.bullmq.io/guide/rate-limiting}
  32. */
  33. limiter?: RateLimiterOptions;
  34. /**
  35. * Enable collect metrics.
  36. * @see {@link https://docs.bullmq.io/guide/metrics}
  37. */
  38. metrics?: MetricsOptions;
  39. /**
  40. * Maximum time in milliseconds where the job is idle while being rate limited.
  41. * While workers are idle because of a rate limiter, they won't fetch new jobs to process
  42. * and delayed jobs won't be promoted.
  43. * @defaultValue 30000
  44. */
  45. maximumRateLimitDelay?: number;
  46. /**
  47. * Defines the maximum number of times a job is allowed to start processing,
  48. * regardless of whether it completes or fails. Each time a worker picks up the job
  49. * and begins processing it, the attemptsStarted counter is incremented.
  50. * If this counter reaches maxStartedAttempts, the job will be moved to the failed state with an UnrecoverableError.
  51. * @defaultValue undefined
  52. */
  53. maxStartedAttempts?: number;
  54. /**
  55. * Amount of times a job can be recovered from a stalled state
  56. * to the `wait` state. If this is exceeded, the job is moved
  57. * to `failed`.
  58. *
  59. * @defaultValue 1
  60. */
  61. maxStalledCount?: number;
  62. /**
  63. * Number of milliseconds between stallness checks.
  64. *
  65. * @defaultValue 30000
  66. */
  67. stalledInterval?: number;
  68. /**
  69. * You can provide an object specifying max
  70. * age and/or count to keep.
  71. * Default behavior is to keep the job in the completed set.
  72. *
  73. * Eviction is evaluated on a best-effort basis when a job finishes,
  74. * so aged jobs are only removed once another job completes after
  75. * their expiration.
  76. */
  77. removeOnComplete?: KeepJobs;
  78. /**
  79. * You can provide an object specifying max
  80. * age and/or count to keep.
  81. * Default behavior is to keep the job in the failed set.
  82. *
  83. * Eviction is evaluated on a best-effort basis when a job fails, so
  84. * aged jobs are only removed once another job fails after their
  85. * expiration.
  86. */
  87. removeOnFail?: KeepJobs;
  88. /**
  89. * Skip stalled check for this worker. Note that other workers could still
  90. * perform stalled checkd and move jobs back to wait for jobs being processed
  91. * by this worker.
  92. *
  93. * @defaultValue false
  94. */
  95. skipStalledCheck?: boolean;
  96. /**
  97. * Skip lock renewal for this worker. If set to true, the lock will expire
  98. * after lockDuration and moved back to the wait queue (if the stalled check is
  99. * not disabled)
  100. *
  101. * @defaultValue false
  102. */
  103. skipLockRenewal?: boolean;
  104. /**
  105. * Number of seconds to long poll for jobs when the queue is empty.
  106. *
  107. * @defaultValue 5
  108. */
  109. drainDelay?: number;
  110. /**
  111. * Duration of the lock for the job in milliseconds. The lock represents that
  112. * a worker is processing the job. If the lock is lost, the job will be eventually
  113. * be picked up by the stalled checker and move back to wait so that another worker
  114. * can process it again.
  115. *
  116. * @defaultValue 30000
  117. */
  118. lockDuration?: number;
  119. /**
  120. * The time in milliseconds before the lock is automatically renewed.
  121. *
  122. * It is not recommended to modify this value, which is by default set to
  123. * halv the lockDuration value, which is optimal for most use cases.
  124. */
  125. lockRenewTime?: number;
  126. /**
  127. * This is an internal option that should not be modified.
  128. *
  129. * @defaultValue 15000
  130. */
  131. runRetryDelay?: number;
  132. /**
  133. * More advanced options.
  134. */
  135. settings?: AdvancedOptions;
  136. /**
  137. * Use Worker Threads instead of Child Processes.
  138. * Note: This option can only be used when specifying
  139. * a file for the processor argument.
  140. *
  141. * @defaultValue false
  142. */
  143. useWorkerThreads?: boolean;
  144. /**
  145. * Telemetry Addon
  146. */
  147. telemetry?: Telemetry;
  148. }
  149. export interface GetNextJobOptions {
  150. block?: boolean;
  151. }