qrusty-client 0.2.0 → 0.3.0

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.
Files changed (3) hide show
  1. package/README.md +4 -4
  2. package/index.js +24 -13
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -22,12 +22,12 @@ const QrustyClient = require("qrusty-client");
22
22
  const client = new QrustyClient("http://localhost:6784");
23
23
 
24
24
  (async () => {
25
- await client.createQueue("orders", "MaxFirst", true);
25
+ await client.createQueue("orders", "MaxFirst", true);
26
26
  await client.publish("orders", 100, { order_id: 123 });
27
27
  const msg = await client.consume("orders", "worker-1");
28
- if (msg) {
29
- await client.ack("orders", msg.id, "worker-1");
30
- }
28
+ if (msg) {
29
+ await client.ack("orders", msg.id, "worker-1");
30
+ }
31
31
  })();
32
32
  ```
33
33
 
package/index.js CHANGED
@@ -38,20 +38,26 @@ class QrustyClient {
38
38
  }
39
39
 
40
40
  /**
41
- * Rename a queue and optionally update its configuration
42
- * @param {string} from
43
- * @param {string} to
44
- * @param {string} [ordering="MaxFirst"]
45
- * @param {boolean} [allowDuplicates=true]
41
+ * Update queue configuration (name and/or allow_duplicates)
42
+ * @param {string} name - Current queue name
43
+ * @param {string} [newName] - New name for the queue (optional)
44
+ * @param {boolean} [allowDuplicates] - New allow_duplicates setting (optional)
46
45
  * @returns {Promise<void>}
47
46
  */
48
- async renameQueue(from, to, ordering = "MaxFirst", allowDuplicates = true) {
49
- const data = {
50
- from,
51
- to,
52
- config: { ordering, allow_duplicates: allowDuplicates },
53
- };
54
- await axios.post(`${this.baseUrl}/rename-queue`, data);
47
+ async updateQueue(name, newName = undefined, allowDuplicates = undefined) {
48
+ const config = {};
49
+ if (newName !== undefined) config.name = newName;
50
+ if (allowDuplicates !== undefined)
51
+ config.allow_duplicates = allowDuplicates;
52
+
53
+ if (Object.keys(config).length === 0) {
54
+ throw new Error(
55
+ "At least one of newName or allowDuplicates must be specified",
56
+ );
57
+ }
58
+
59
+ const data = { name, config };
60
+ await axios.post(`${this.baseUrl}/update-queue`, data);
55
61
  }
56
62
 
57
63
  /**
@@ -75,7 +81,12 @@ class QrustyClient {
75
81
  async publish(queue, priority, payload, maxRetries = 3) {
76
82
  const payloadStr =
77
83
  typeof payload === "string" ? payload : JSON.stringify(payload);
78
- const data = { queue, priority, payload: payloadStr, max_retries: maxRetries };
84
+ const data = {
85
+ queue,
86
+ priority,
87
+ payload: payloadStr,
88
+ max_retries: maxRetries,
89
+ };
79
90
  const resp = await axios.post(`${this.baseUrl}/publish`, data);
80
91
  return resp.data;
81
92
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qrusty-client",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Node.js client for the qrusty priority queue server API.",
5
5
  "main": "index.js",
6
6
  "author": "Gordon Greene <greeng3@obscure-reference.com>",