From fdf64f0e10e29533393b03e529fadf177c49dab6 Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Tue, 24 Dec 2024 18:08:09 +0800 Subject: [PATCH] feat: export consume options from worker --- src/api.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/api.js b/src/api.js index 28a4a26..35b36e0 100644 --- a/src/api.js +++ b/src/api.js @@ -342,8 +342,12 @@ export const createWorker = async (store, opts) => { export class Worker { /** * @param {Api} client + * @param {Object} opts + * @param {number} [opts.blockTime] + * @param {number} [opts.tryReclaimCount] + * @param {number} [opts.tryClaimCount] */ - constructor (client) { + constructor (client, opts = {}) { this.client = client logWorker('Created worker process ', { id: client.consumername, prefix: client.prefix, minMessageLifetime: client.redisMinMessageLifetime }) ;(async () => { @@ -351,7 +355,7 @@ export class Worker { const timeDiff = startRedisTime.getTime() - time.getUnixTime() while (!client._destroyed) { try { - const tasks = await client.consumeWorkerQueue() + const tasks = await client.consumeWorkerQueue(opts) if (tasks.length === 0 || (client.redisMinMessageLifetime > time.getUnixTime() + timeDiff - number.parseInt(tasks[0].id.split('-')[0]))) { await promise.wait(client.redisMinMessageLifetime / 2) }