@avada-falcon/worker-sdk 0.5.1 → 0.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avada-falcon/worker-sdk",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "Self-hosted background job runner powered by BullMQ + Redis",
5
5
  "type": "module",
6
6
  "main": "src/index.cjs",
@@ -15,7 +15,17 @@ export function createClient(configPath) {
15
15
  const optsCache = new Map(); // job opts are static per job name — build once
16
16
 
17
17
  return {
18
- async add(jobName, payload) {
18
+ /**
19
+ * @param {string} jobName
20
+ * @param {object} payload
21
+ * @param {{jobId?: string, priority?: number}} [opts] - Caller may supply:
22
+ * - jobId: a readable, unique id (e.g. `<job>-<shop>-<rand>`). MUST be unique per
23
+ * dispatch — BullMQ silently drops an add whose id already exists (dedup), so the
24
+ * caller owns collision-resistance. Omitted → a random `<jobName>-<uuid>`.
25
+ * - priority: BullMQ job priority (lower = higher; runs earlier in the wait list).
26
+ * Omitted → no priority (BullMQ default FIFO).
27
+ */
28
+ async add(jobName, payload, opts = {}) {
19
29
  const jobConfig = config.jobs[jobName];
20
30
  if (!jobConfig) {
21
31
  throw new Error(`Unknown job: ${jobName}. Define it in your worker config.`);
@@ -28,7 +38,8 @@ export function createClient(configPath) {
28
38
 
29
39
  return queue.add(jobName, payload, {
30
40
  ...optsCache.get(jobName),
31
- jobId: `${jobName}-${randomUUID()}`
41
+ jobId: opts.jobId || `${jobName}-${randomUUID()}`,
42
+ ...(opts.priority != null ? {priority: opts.priority} : {})
32
43
  });
33
44
  },
34
45