@zintrust/zedgi 3.0.2 → 3.0.3

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.
@@ -1,4 +1,5 @@
1
1
  import { Logger } from '@zintrust/core/logger';
2
+ import { isWaitingJobState } from '@zintrust/queue-monitor/driver';
2
3
  import { ZedgiRuntime } from './ZedgiRuntime.js';
3
4
  const createZedgiEnqueue = (getQueueConfig) => async (name, payload, options) => {
4
5
  try {
@@ -67,6 +68,35 @@ const createZedgiRetryJob = (getQueueConfig) => async (queueName, jobId) => {
67
68
  throw error;
68
69
  }
69
70
  };
71
+ const waitingStateRejection = (state) => ({
72
+ ok: false,
73
+ status: 'not_waiting',
74
+ reason: `Job is ${typeof state === 'string' && state.trim() !== '' ? state : 'unknown'}, not waiting`,
75
+ });
76
+ const createZedgiDeleteWaitingJob = (getQueueConfig) => async (queueName, jobId) => {
77
+ const queue = ZedgiRuntime.queue(queueName, getQueueConfig());
78
+ const job = (await queue.getJob(jobId));
79
+ if (!job)
80
+ return { ok: false, status: 'missing' };
81
+ if (!isWaitingJobState(job.state))
82
+ return waitingStateRejection(job.state);
83
+ await queue.removeJob(jobId);
84
+ return { ok: true, status: 'removed' };
85
+ };
86
+ const createZedgiRequeueWaitingJob = (getQueueConfig) => async (queueName, jobId) => {
87
+ const queue = ZedgiRuntime.queue(queueName, getQueueConfig());
88
+ const job = (await queue.getJob(jobId));
89
+ if (!job)
90
+ return { ok: false, status: 'missing' };
91
+ if (!isWaitingJobState(job.state))
92
+ return waitingStateRejection(job.state);
93
+ const opts = { ...job.opts };
94
+ delete opts['jobId'];
95
+ await queue.removeJob(jobId);
96
+ const added = await queue.add(job.name ?? `${queueName}-job`, job.data ?? {}, opts);
97
+ const newJobId = added?.id !== undefined && added.id !== null ? String(added.id) : undefined;
98
+ return { ok: true, status: 'requeued', newJobId };
99
+ };
70
100
  const createZedgiRecoverActiveJob = (getQueueConfig) => async (queueName, jobId) => {
71
101
  try {
72
102
  const queue = ZedgiRuntime.queue(queueName, getQueueConfig());
@@ -121,6 +151,8 @@ const createZedgiMonitorDriver = (config) => {
121
151
  getRecentJobs: createZedgiGetRecentJobs(getQueueConfig),
122
152
  retryJob: createZedgiRetryJob(getQueueConfig),
123
153
  recoverActiveJob: createZedgiRecoverActiveJob(getQueueConfig),
154
+ deleteWaitingJob: createZedgiDeleteWaitingJob(getQueueConfig),
155
+ requeueWaitingJob: createZedgiRequeueWaitingJob(getQueueConfig),
124
156
  getQueues: createZedgiGetQueues(getQueueConfig),
125
157
  close: createZedgiClose(),
126
158
  };
@@ -1,4 +1,5 @@
1
1
  import { Env } from '@zintrust/core/config';
2
+ import { ErrorFactory } from '@zintrust/core/errors';
2
3
  import { generateUuid } from '@zintrust/core/utils';
3
4
  import { ZedgiRuntime } from './ZedgiRuntime.js';
4
5
  const resolveRequestedJobId = (payload) => {
@@ -40,7 +41,7 @@ const callQueueRpc = async (config, queueName, method, payload) => {
40
41
  ...payload,
41
42
  });
42
43
  }
43
- throw new Error('Zedgi Redis RPC hook support is required for queue consumption');
44
+ throw ErrorFactory.createConfigError('Zedgi Redis RPC hook support is required for queue consumption');
44
45
  };
45
46
  const createDriver = (config) => {
46
47
  const queue = (name) => ZedgiRuntime.queue(name, config);
@@ -7,6 +7,9 @@ export declare const ZedgiRuntime: Readonly<{
7
7
  redis(config?: Partial<ZedgiRedisCacheConfig | ZedgiQueueConfig>): import("@zedgi/zedgi-client").RedisClient;
8
8
  queue(name: string, config?: Partial<ZedgiQueueConfig | ZedgiRedisCacheConfig>): Readonly<{
9
9
  add: (jobName: string, data?: unknown, opts?: Record<string, unknown>) => Promise<import("@zedgi/zedgi-client").QueueJob | null>;
10
+ dequeue: (visibilityTimeoutMs?: number) => Promise<import("@zedgi/zedgi-client").QueueJob | null>;
11
+ ack: (id: string, returnValue?: unknown) => Promise<boolean>;
12
+ fail: (id: string, reason?: string) => Promise<boolean>;
10
13
  getJob: (id: string) => Promise<import("@zedgi/zedgi-client").QueueJob | null>;
11
14
  getJobs: (states?: string[], start?: number, end?: number, asc?: boolean) => Promise<(import("@zedgi/zedgi-client").QueueJob | null)[]>;
12
15
  getJobCounts: (...types: string[]) => Promise<Record<string, number>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zintrust/zedgi",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "Zedgi HTTPS transport drivers for ZinTrust cache, database, and queue.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -38,7 +38,7 @@
38
38
  "adapter"
39
39
  ],
40
40
  "dependencies": {
41
- "@zedgi/zedgi-client": "^1.0.3"
41
+ "@zedgi/zedgi-client": "^1.1.1"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "tsc -p tsconfig.json",