arcway 0.1.8 → 0.1.9

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": "arcway",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "A convention-based framework for building modular monoliths with strict domain boundaries.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -27,6 +27,15 @@ class KnexQueueDriver {
27
27
  status: 'available',
28
28
  });
29
29
  }
30
+ async pushBulk(namespace, topic, payloads) {
31
+ const rows = payloads.map((payload) => ({
32
+ namespace,
33
+ topic,
34
+ payload,
35
+ status: 'available',
36
+ }));
37
+ await this.db(this.tableName).insert(rows);
38
+ }
30
39
  async pop(namespace, topic, count, lockCooldownMs) {
31
40
  const cutoff = new Date(Date.now() - lockCooldownMs).toISOString();
32
41
  const now = new Date().toISOString();
@@ -37,6 +37,16 @@ class RedisQueueDriver {
37
37
  const item = JSON.stringify({ id, payload });
38
38
  await this.client.rpush(this.listKey(namespace, topic), item);
39
39
  }
40
+ async pushBulk(namespace, topic, payloads) {
41
+ const listKey = this.listKey(namespace, topic);
42
+ const idKey = this.idKey();
43
+ const startId = await this.client.incrby(idKey, payloads.length);
44
+ const items = payloads.map((payload, i) => {
45
+ const id = startId - payloads.length + 1 + i;
46
+ return JSON.stringify({ id, payload });
47
+ });
48
+ await this.client.rpush(listKey, ...items);
49
+ }
40
50
  async pop(namespace, topic, count, lockCooldownMs) {
41
51
  const results = [];
42
52
  const listKey = this.listKey(namespace, topic);
@@ -29,6 +29,12 @@ class Queue {
29
29
  await this._driver.push(this._namespace, topic, JSON.stringify(item));
30
30
  }
31
31
 
32
+ async pushBulk(topic, items) {
33
+ if (!items || items.length === 0) return;
34
+ const payloads = items.map((item) => JSON.stringify(item));
35
+ await this._driver.pushBulk(this._namespace, topic, payloads);
36
+ }
37
+
32
38
  async pop(topic, count = 1) {
33
39
  const rows = await this._driver.pop(this._namespace, topic, count, this._cooldownMs);
34
40
  return rows.map((r) => {