Skip to content

Commit

Permalink
Merge pull request #10 from hackmdio/feat/export-consume-options-from…
Browse files Browse the repository at this point in the history
…-worker

feat: export consume options from worker
  • Loading branch information
stanley2058 authored Dec 25, 2024
2 parents 97b7926 + fdf64f0 commit f0f7b30
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,20 @@ 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 () => {
const startRedisTime = await client.redis.time()
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)
}
Expand Down

0 comments on commit f0f7b30

Please sign in to comment.