bullmq 5.80.12 → 5.81.1

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.
package/README.md CHANGED
@@ -186,6 +186,8 @@ $ yarn add bullmq
186
186
 
187
187
  If you use the node-redis adapter (`createNodeRedisClient`), install `redis` v5 or newer (`redis >= 5.0.0`).
188
188
 
189
+ If you use the Valkey Glide adapter (`createValkeyGlideClient`), install `@valkey/valkey-glide`.
190
+
189
191
  Add jobs to the queue:
190
192
 
191
193
  ```ts
@@ -11,6 +11,7 @@ tslib_1.__exportStar(require("./flow-producer"), exports);
11
11
  tslib_1.__exportStar(require("./ioredis-client"), exports);
12
12
  tslib_1.__exportStar(require("./node-redis-client"), exports);
13
13
  tslib_1.__exportStar(require("./bun-redis-client"), exports);
14
+ tslib_1.__exportStar(require("./valkey-glide-client"), exports);
14
15
  tslib_1.__exportStar(require("./job"), exports);
15
16
  tslib_1.__exportStar(require("./job-scheduler"), exports);
16
17
  // export * from './main'; this file must not be exported
@@ -389,8 +389,13 @@ class QueueGetters extends queue_base_1.QueueBase {
389
389
  */
390
390
  async getJobs(types, start = 0, end = -1, asc = false) {
391
391
  const currentTypes = this.sanitizeJobTypes(types);
392
- const jobIds = await this.getRanges(currentTypes, start, end, asc);
393
- return Promise.all(jobIds.map(jobId => this.Job.fromId(this, jobId)));
392
+ const jobDataByType = await this.scripts.getJobs(currentTypes, start, end, asc);
393
+ return jobDataByType.reduce((jobs, jobData) => {
394
+ for (const [jobId, jobHashFields] of jobData || []) {
395
+ jobs.push(this.Job.fromJSON(this, (0, utils_1.array2obj)(jobHashFields), jobId));
396
+ }
397
+ return jobs;
398
+ }, []);
394
399
  }
395
400
  /**
396
401
  * Returns the logs for a given Job.
@@ -15,6 +15,13 @@ const enums_1 = require("../enums");
15
15
  const utils_1 = require("../utils");
16
16
  const version_1 = require("../version");
17
17
  const errors_1 = require("./errors");
18
+ /**
19
+ * Upper bound on the number of forward backfill iterations the `getJobs` Lua
20
+ * script performs to replace skipped ids (missing job hashes) within a bounded
21
+ * range. It caps the work done per call so a range full of missing jobs cannot
22
+ * scan the whole state unboundedly.
23
+ */
24
+ const GET_JOBS_MAX_BACKFILL_ITERATIONS = 5;
18
25
  class Scripts {
19
26
  constructor(queue) {
20
27
  this.queue = queue;
@@ -612,6 +619,32 @@ class Scripts {
612
619
  const args = this.getRangesArgs(types, start, end, asc);
613
620
  return await this.execCommand(client, 'getRanges', args);
614
621
  }
622
+ getJobsArgs(types, start, end, asc) {
623
+ const queueKeys = this.queue.keys;
624
+ const transformedTypes = [
625
+ ...new Set(types.map(type => (type === 'waiting' ? 'wait' : type))),
626
+ ];
627
+ const keys = [queueKeys['']];
628
+ const args = [
629
+ start,
630
+ end,
631
+ asc ? '1' : '0',
632
+ GET_JOBS_MAX_BACKFILL_ITERATIONS,
633
+ ...transformedTypes,
634
+ ];
635
+ return keys.concat(args);
636
+ }
637
+ /**
638
+ * Fetches job ids and their job hashes for the provided states in a single
639
+ * script, skipping ids whose job hash is missing (for example the deprecated
640
+ * wait list marker or jobs removed after their id was read). Each returned
641
+ * entry is a `[jobId, jobHashFields]` tuple grouped per requested type.
642
+ */
643
+ async getJobs(types, start = 0, end = -1, asc = false) {
644
+ const client = await this.queue.client;
645
+ const args = this.getJobsArgs(types, start, end, asc);
646
+ return await this.execCommand(client, 'getJobs', args);
647
+ }
615
648
  getCountsArgs(types) {
616
649
  const queueKeys = this.queue.keys;
617
650
  const transformedTypes = types.map(type => {