slashbin-kit-core 1.1.0-next.1 → 1.1.1-next.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.
Files changed (2) hide show
  1. package/README.md +66 -0
  2. package/package.json +7 -1
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # slashbin-kit-core
2
+
3
+ Shared queue-claim primitives for Slashbin receiver and ingest kits: at-least-once claim, ack, retry, dead-letter and boot reconcile over Redis lists.
4
+
5
+ This package is code you run in your own service. It is not a hosted Slashbin service.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install slashbin-kit-core ioredis
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ `DurableQueueClaim` is the only owner of a queue list and its processing list. Claim an item with `claimNext()`, run your handler, then `ack()` it after the handler succeeds. If the handler fails, call `fail()`: the item is requeued with its `attempts` count raised, or dead-lettered into the sink you inject once `maxAttempts` is reached. Call `reconcile()` once at boot, before the first claim, to move anything stranded in the processing list back to the queue.
16
+
17
+ `RedisQueueStore` needs two ioredis connections. The second, dedicated one runs the blocking claim, so a waiting claim never stalls your other commands. Passing the same connection twice throws.
18
+
19
+ ```ts
20
+ import { Redis } from "ioredis";
21
+ import { DurableQueueClaim, RedisQueueStore } from "slashbin-kit-core";
22
+
23
+ const client = new Redis();
24
+ const blockingClient = new Redis({ maxRetriesPerRequest: null });
25
+ const store = new RedisQueueStore(client, blockingClient);
26
+
27
+ const claim = new DurableQueueClaim(store, {
28
+ queue: "events",
29
+ processing: "events:processing",
30
+ maxAttempts: 8,
31
+ deadLetter: (item, reason) => store.deadLetterPush("events:dead", `${reason}:${item}`),
32
+ });
33
+
34
+ async function handle(item: string): Promise<void> {
35
+ // Your business action. It must be idempotent.
36
+ }
37
+
38
+ export async function run(): Promise<void> {
39
+ await claim.reconcile();
40
+ for (;;) {
41
+ const item = await claim.claimNext();
42
+ if (item === null) continue;
43
+ try {
44
+ await handle(item);
45
+ await claim.ack(item);
46
+ } catch (error) {
47
+ await claim.fail(item, String(error));
48
+ }
49
+ }
50
+ }
51
+ ```
52
+
53
+ Items are UTF-8 JSON object strings. The kit reads and writes only the top-level `attempts` member.
54
+
55
+ ## What to know
56
+
57
+ - **At-least-once.** An item is always in the queue, in the processing list, or in your dead-letter sink. A crash between claim and ack runs the item again, so handlers must be idempotent.
58
+ - **No sleeping.** The kit never sleeps. Backoff and rate limits belong to your own loop.
59
+ - **Failures surface.** A sink or Redis failure rejects the call and leaves the item in the processing list until the next `reconcile()`.
60
+ - **Constructor checks.** `processing` must equal `` `${queue}:processing` ``, and `maxAttempts` must be an integer of at least 1.
61
+
62
+ ## Source and licence
63
+
64
+ Source and issues: <https://github.com/slashbin-io/slashbin_kits>
65
+
66
+ MIT licence.
package/package.json CHANGED
@@ -1,8 +1,14 @@
1
1
  {
2
2
  "name": "slashbin-kit-core",
3
- "version": "1.1.0-next.1",
3
+ "version": "1.1.1-next.1",
4
4
  "description": "Shared queue-claim primitives for Slashbin receiver and ingest kits: at-least-once claim, ack, retry and boot reconcile over Redis lists.",
5
5
  "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/slashbin-io/slashbin_kits.git",
9
+ "directory": "packages/kit-core"
10
+ },
11
+ "homepage": "https://github.com/slashbin-io/slashbin_kits/tree/main/packages/kit-core#readme",
6
12
  "type": "module",
7
13
  "main": "./dist/index.js",
8
14
  "types": "./dist/index.d.ts",