@prsm/queue 3.0.0 → 3.0.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
@@ -147,7 +147,7 @@ queue.on('drain', () => {})
147
147
  uuid: string,
148
148
  payload: any,
149
149
  createdAt: number,
150
- groupKey?: string, // present when pushed with { group }
150
+ group?: string, // present when pushed with { group }
151
151
  attempts: number
152
152
  }
153
153
  ```
@@ -178,15 +178,15 @@ Each tenant gets up to 2 concurrent LLM calls with a 50ms pause between them. To
178
178
 
179
179
  ## WebSocket Integration with [mesh](https://github.com/nvms/mesh)
180
180
 
181
- Queue events are local-only - only the server that processes a task emits `complete`/`failed`. Use [mesh](https://github.com/nvms/mesh) to push results to connected clients in real time.
181
+ Queue events are local-only - only the server that processes a task emits `complete`/`failed`. Use [@prsm/realtime](https://github.com/nvms/realtime) to push results to connected clients in real time.
182
182
 
183
183
  Send results to a specific client:
184
184
 
185
185
  ```js
186
186
  import Queue from '@prsm/queue'
187
- import { MeshServer } from '@mesh-kit/server'
187
+ import { RealtimeServer } from '@prsm/realtime'
188
188
 
189
- const mesh = new MeshServer({ redis: { host: 'localhost', port: 6379 } })
189
+ const realtime = new RealtimeServer({ redis: { host: 'localhost', port: 6379 } })
190
190
  const queue = new Queue({ concurrency: 5, groups: { concurrency: 1 } })
191
191
 
192
192
  queue.process(async (payload) => {
@@ -194,14 +194,14 @@ queue.process(async (payload) => {
194
194
  })
195
195
 
196
196
  queue.on('complete', ({ task, result }) => {
197
- mesh.sendTo(task.payload.connectionId, 'job:complete', result)
197
+ realtime.sendTo(task.payload.connectionId, 'job:complete', result)
198
198
  })
199
199
 
200
200
  queue.on('failed', ({ task, error }) => {
201
- mesh.sendTo(task.payload.connectionId, 'job:failed', { error: error.message })
201
+ realtime.sendTo(task.payload.connectionId, 'job:failed', { error: error.message })
202
202
  })
203
203
 
204
- mesh.exposeCommand('generate-report', async (ctx) => {
204
+ realtime.exposeCommand('generate-report', async (ctx) => {
205
205
  const taskId = await queue.push({
206
206
  connectionId: ctx.connection.id,
207
207
  ...ctx.payload,
@@ -210,10 +210,10 @@ mesh.exposeCommand('generate-report', async (ctx) => {
210
210
  })
211
211
 
212
212
  await queue.ready()
213
- await mesh.listen(8080)
213
+ await realtime.listen(8080)
214
214
  ```
215
215
 
216
- Both queue and mesh use the same Redis instance. No key conflicts (`queue:*` vs `mesh:*`).
216
+ Both queue and realtime use the same Redis instance. No key conflicts (`queue:*` vs `mesh:*`).
217
217
 
218
218
  ## Horizontal Scaling
219
219
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prsm/queue",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Redis-backed distributed task queue with grouped concurrency, retries, and rate limiting",
5
5
  "type": "module",
6
6
  "exports": {
package/src/queue.js CHANGED
@@ -20,7 +20,7 @@ import ms from "@prsm/ms"
20
20
  * @property {string} uuid
21
21
  * @property {any} payload
22
22
  * @property {number} createdAt
23
- * @property {string} [groupKey]
23
+ * @property {string} [group]
24
24
  * @property {number} attempts
25
25
  */
26
26
 
@@ -157,7 +157,7 @@ export default class Queue extends EventEmitter {
157
157
  async push(payload, { group } = {}) {
158
158
  if (this._closed) throw new Error("Queue is closed")
159
159
  const task = group
160
- ? { uuid: randomUUID(), payload, createdAt: Date.now(), groupKey: group, attempts: 0 }
160
+ ? { uuid: randomUUID(), payload, createdAt: Date.now(), group, attempts: 0 }
161
161
  : { uuid: randomUUID(), payload, createdAt: Date.now(), attempts: 0 }
162
162
  this._pushed++
163
163
  try {
@@ -178,7 +178,7 @@ export default class Queue extends EventEmitter {
178
178
  pushAndWait(payload, { group, timeout = 0 } = {}) {
179
179
  if (this._closed) return Promise.reject(new Error("Queue is closed"))
180
180
  const task = group
181
- ? { uuid: randomUUID(), payload, createdAt: Date.now(), groupKey: group, attempts: 0 }
181
+ ? { uuid: randomUUID(), payload, createdAt: Date.now(), group, attempts: 0 }
182
182
  : { uuid: randomUUID(), payload, createdAt: Date.now(), attempts: 0 }
183
183
  this._pushed++
184
184
  const result = this._awaitTask(task.uuid, timeout)
@@ -338,13 +338,13 @@ export default class Queue extends EventEmitter {
338
338
  timeout: this._options.groups.timeout,
339
339
  maxRetries: this._options.groups.maxRetries,
340
340
  retryKey: `queue:groups:${groupKey}`,
341
- groupKey,
341
+ group: groupKey,
342
342
  }
343
343
  this._runWorkerLoop(workerId, client, `queue:groups:${groupKey}`, groupWorkers, opts)
344
344
  }
345
345
 
346
346
  async _runWorkerLoop(workerId, client, key, activeMap, opts) {
347
- const delay = opts.groupKey ? this._options.groups.delay : this._options.delay
347
+ const delay = opts.group ? this._options.groups.delay : this._options.delay
348
348
 
349
349
  while (activeMap.get(workerId)) {
350
350
  try {
@@ -371,17 +371,17 @@ export default class Queue extends EventEmitter {
371
371
  }
372
372
 
373
373
  this._inFlight++
374
- if (opts.groupKey) {
375
- this._groupInFlight.set(opts.groupKey, (this._groupInFlight.get(opts.groupKey) || 0) + 1)
374
+ if (opts.group) {
375
+ this._groupInFlight.set(opts.group, (this._groupInFlight.get(opts.group) || 0) + 1)
376
376
  }
377
377
 
378
378
  try {
379
379
  await this._processTask(task, opts)
380
380
  } finally {
381
- if (opts.groupKey) {
382
- const count = (this._groupInFlight.get(opts.groupKey) || 1) - 1
383
- if (count <= 0) this._groupInFlight.delete(opts.groupKey)
384
- else this._groupInFlight.set(opts.groupKey, count)
381
+ if (opts.group) {
382
+ const count = (this._groupInFlight.get(opts.group) || 1) - 1
383
+ if (count <= 0) this._groupInFlight.delete(opts.group)
384
+ else this._groupInFlight.set(opts.group, count)
385
385
  }
386
386
  if (leaseId) await this._releaseGlobal(leaseId).catch(() => {})
387
387
  }
package/types/queue.d.ts CHANGED
@@ -4752,7 +4752,7 @@ export type Task = {
4752
4752
  uuid: string;
4753
4753
  payload: any;
4754
4754
  createdAt: number;
4755
- groupKey?: string;
4755
+ group?: string;
4756
4756
  attempts: number;
4757
4757
  };
4758
4758
  export type TaskHandler = (payload: any, task: Task) => Promise<any> | any;