@zintrust/zedgi 2.8.5 → 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
@@ -40,6 +40,7 @@ CACHE_DRIVER=redis-zedgi
40
40
  DB_CONNECTION=mysql-zedgi
41
41
  # or DB_CONNECTION=postgres-zedgi
42
42
  # or DB_CONNECTION=pg-zedgi
43
+ QUEUE_CONNECTION=queue-zedgi
43
44
  QUEUE_DRIVER=queue-zedgi
44
45
  ```
45
46
 
@@ -55,11 +56,17 @@ The package uses one shared Zedgi client/options object so account key, signing
55
56
  `queue-zedgi` supports:
56
57
 
57
58
  - `enqueue`
59
+ - `dequeue`
60
+ - `ack`
61
+ - `fail`
58
62
  - `length`
59
63
  - `drain`
60
- - `ack`
61
64
 
62
- Pull-based `dequeue` is intentionally unsupported because the Zedgi queue API does not currently expose a safe visibility-timeout claim operation. Use `queue-zedgi` for producers and monitoring, and run workers against the same Redis service directly.
65
+ Pull-based workers use Zedgi's Redis RPC BullMQ-intent operations, so `queue-zedgi`
66
+ can be used for producers, monitoring, and consumers. When `QUEUE_CONNECTION` and
67
+ `QUEUE_DRIVER` are both present, ZinTrust resolves `QUEUE_CONNECTION` first; set it
68
+ to `queue-zedgi` to keep workers, monitors, and producers on the same Zedgi-backed
69
+ Redis target.
63
70
 
64
71
  ## Registration
65
72
 
@@ -1,5 +1,4 @@
1
1
  import { Env } from '@zintrust/core/config';
2
- import { ErrorFactory } from '@zintrust/core/errors';
3
2
  import { generateUuid } from '@zintrust/core/utils';
4
3
  import { ZedgiRuntime } from './ZedgiRuntime.js';
5
4
  const resolveRequestedJobId = (payload) => {
@@ -32,6 +31,17 @@ const resolveJobId = (result, fallback) => {
32
31
  }
33
32
  return fallback;
34
33
  };
34
+ const resolveVisibilityTimeoutMs = () => Env.getInt('QUEUE_ZEDGI_VISIBILITY_TIMEOUT_MS', Env.getInt('QUEUE_REDIS_VISIBILITY_TIMEOUT_MS', 30_000));
35
+ const callQueueRpc = async (config, queueName, method, payload) => {
36
+ const redis = ZedgiRuntime.redis(config);
37
+ if (typeof redis.hook === 'function') {
38
+ return redis.hook(`bull:${method}`, {
39
+ target: queueName,
40
+ ...payload,
41
+ });
42
+ }
43
+ throw new Error('Zedgi Redis RPC hook support is required for queue consumption');
44
+ };
35
45
  const createDriver = (config) => {
36
46
  const queue = (name) => ZedgiRuntime.queue(name, config);
37
47
  return {
@@ -40,11 +50,31 @@ const createDriver = (config) => {
40
50
  const result = await queue(queueName).add(`${queueName}-job`, payload, createJobOptions(payload, fallbackJobId));
41
51
  return resolveJobId(result, fallbackJobId);
42
52
  },
43
- async dequeue(_queueName) {
44
- throw ErrorFactory.createConfigError('queue-zedgi does not support pull-based dequeue yet because the Zedgi queue API does not expose a safe visibility-timeout claim operation. Use it for enqueue and monitoring, or run workers against the same Redis service.');
53
+ async dequeue(queueName) {
54
+ const visibilityTimeoutMs = resolveVisibilityTimeoutMs();
55
+ const client = queue(queueName);
56
+ if (typeof client.dequeue === 'function') {
57
+ return client.dequeue(visibilityTimeoutMs);
58
+ }
59
+ return callQueueRpc(config, queueName, 'dequeue', {
60
+ visibilityTimeoutMs,
61
+ });
45
62
  },
46
63
  async ack(queueName, id) {
47
- await queue(queueName).removeJob(id);
64
+ const client = queue(queueName);
65
+ if (typeof client.ack === 'function') {
66
+ await client.ack(id, 'acknowledged');
67
+ return;
68
+ }
69
+ await callQueueRpc(config, queueName, 'ack', { args: [id, 'acknowledged'] });
70
+ },
71
+ async fail(queueName, id, reason = 'failed by queue-zedgi worker') {
72
+ const client = queue(queueName);
73
+ if (typeof client.fail === 'function') {
74
+ await client.fail(id, reason);
75
+ return;
76
+ }
77
+ await callQueueRpc(config, queueName, 'fail', { args: [id, reason] });
48
78
  },
49
79
  async length(queueName) {
50
80
  return queue(queueName).count();
package/dist/types.d.ts CHANGED
@@ -58,6 +58,7 @@ export type QueueDriver = {
58
58
  enqueue(queue: string, payload: BullMQPayload): Promise<string>;
59
59
  dequeue<T = unknown>(queue: string): Promise<QueueMessage<T> | undefined>;
60
60
  ack(queue: string, id: string): Promise<void>;
61
+ fail?(queue: string, id: string, reason?: string): Promise<void>;
61
62
  length(queue: string): Promise<number>;
62
63
  drain(queue: string): Promise<void>;
63
64
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zintrust/zedgi",
3
- "version": "2.8.5",
3
+ "version": "3.0.1",
4
4
  "description": "Zedgi HTTPS transport drivers for ZinTrust cache, database, and queue.",
5
5
  "private": false,
6
6
  "type": "module",