fair_machines 0.1.5 → 0.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e5f7f1b342dea36d744b3fcadb3374cc460cefb979217b07864f3706441c675
4
- data.tar.gz: 4601b614cd4838b2d8825403944a47ee7b7c0f6fc327b16b9084c52df2986d1a
3
+ metadata.gz: 687ce87a9f48c9a1bc4eb32db7a21592decce4fc01290bc8936a9e85bb43197d
4
+ data.tar.gz: f560225b9bba38bf6e37d7369affb3dac766f52cd5c4d163099ef014ae4b6545
5
5
  SHA512:
6
- metadata.gz: e3b0e4df6de3a2f7fcd90a8acad8ba052ccd3131ed4159fdf5b2a1e41e38dc9a9a8a27b9f67f3adc1786d855a48f9b51f9a54a938d3a28c8b88a6c77f1c5306d
7
- data.tar.gz: 37bec0f1d1535776accb53b2779ed5f1da1e40a507a5c0e45608b2c363aa7ae0b84dbd9275736248e91b2b6122820b7ded91759ebe221d1e5badcde033a995c9
6
+ metadata.gz: 3c7131456fc07cee7f2187e1113ad8166cff0768d9c7d7310c29acec67c4bbaa2c2343dbda42f5332f4cafe2be4019b92d9ab3da677528c04ebebd5e01e751f2
7
+ data.tar.gz: d9f8ff94c607dcdefc9f21a767c8d0881a1b3bea6517d5db28dd6fb39b2cb022772269ec6e56bdf638490c810b77291c6411cb0463328c1b8a277ba7cb57ae05
data/CHANGELOG.md CHANGED
@@ -1,5 +1,74 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.6.1](https://github.com/seuros/fair_machines/compare/fair_machines/v0.6.0...fair_machines/v0.6.1) (2026-11-16)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * fix wrapped classes at load so building a value runs no Ruby ([eb9ca70](https://github.com/seuros/fair_machines/commit/eb9ca70c43f9165eacdcfb00d54a482d303ee07b))
9
+
10
+ ## [0.6.0](https://github.com/seuros/fair_machines/compare/fair_machines/v0.5.1...fair_machines/v0.6.0) (2026-11-16)
11
+
12
+
13
+ ### ⚠ BREAKING CHANGES
14
+
15
+ * seal TenantFair and KeyedFair against subclassing
16
+
17
+ ### Features
18
+
19
+ * seal TenantFair and KeyedFair against subclassing ([74f1b9c](https://github.com/seuros/fair_machines/commit/74f1b9c6f3d283689441bfa7a8e469da16695f4f))
20
+
21
+ ## [0.5.1](https://github.com/seuros/fair_machines/compare/fair_machines/v0.5.0...fair_machines/v0.5.1) (2026-11-14)
22
+
23
+
24
+ ### Bug Fixes
25
+
26
+ * **deps:** require matryona-machines >= 0.4 ([04666de](https://github.com/seuros/fair_machines/commit/04666de21538f824df21f6012e2cbbeca419bafe))
27
+
28
+ ## [0.5.0](https://github.com/seuros/fair_machines/compare/fair_machines/v0.4.0...fair_machines/v0.5.0) (2026-11-14)
29
+
30
+
31
+ ### ⚠ BREAKING CHANGES
32
+
33
+ * adopt matryona-machines 0.3 (optional_positive heads, integer_in lanes)
34
+
35
+ ### Features
36
+
37
+ * adopt matryona-machines 0.3 (optional_positive heads, integer_in lanes) ([fd6b0cf](https://github.com/seuros/fair_machines/commit/fd6b0cf9ff26bb52d4a8606a0bc4cc7bf27a5be6))
38
+
39
+ ## [0.4.0](https://github.com/seuros/fair_machines/compare/fair_machines/v0.3.0...fair_machines/v0.4.0) (2026-11-14)
40
+
41
+
42
+ ### ⚠ BREAKING CHANGES
43
+
44
+ * build the binding on matryona-machines 0.2; compiler-checked refusal symbols; read Lane fields from the struct; ship no test files
45
+
46
+ ### Features
47
+
48
+ * build the binding on matryona-machines 0.2; compiler-checked refusal symbols; read Lane fields from the struct; ship no test files ([9e05fa0](https://github.com/seuros/fair_machines/commit/9e05fa06ec652a0693d0d83f4fd5c5e63fc96f31))
49
+
50
+ ## [0.3.0](https://github.com/seuros/fair_machines/compare/fair_machines/v0.2.0...fair_machines/v0.3.0) (2026-11-14)
51
+
52
+
53
+ ### ⚠ BREAKING CHANGES
54
+
55
+ * validate Lane through the core, seal it, exact-class reads, clone-then-keep admit
56
+
57
+ ### Features
58
+
59
+ * validate Lane through the core, seal it, exact-class reads, clone-then-keep admit ([2f819ae](https://github.com/seuros/fair_machines/commit/2f819aeed1bfc76251be703b14e8dafd6d17ee45))
60
+
61
+ ## [0.2.0](https://github.com/seuros/fair_machines/compare/fair_machines/v0.1.5...fair_machines/v0.2.0) (2026-11-13)
62
+
63
+
64
+ ### ⚠ BREAKING CHANGES
65
+
66
+ * converted to the fleet conventions. One exhaustive Refusal per crate, Result from every operation that can refuse, a refusal changes nothing, provable idempotent repeats are honoured, Ruby mirrors the core. No compatibility aliases. Requires flow-machines >= 0.3 and priority-machines >= 0.4.
67
+
68
+ ### Features
69
+
70
+ * answer Result<_, Refusal>, refuse unadmitted heads in select, mirror the core positionally in Ruby ([5e73ef6](https://github.com/seuros/fair_machines/commit/5e73ef67f86a0326709e27eca46d8f97bccd8aba))
71
+
3
72
  ## [0.1.5](https://github.com/seuros/fair_machines/compare/fair_machines/v0.1.4...fair_machines/v0.1.5) (2026-11-07)
4
73
 
5
74
 
data/Cargo.lock ADDED
@@ -0,0 +1,321 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "aho-corasick"
7
+ version = "1.1.5"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
10
+ dependencies = [
11
+ "memchr",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "bindgen"
16
+ version = "0.72.1"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895"
19
+ dependencies = [
20
+ "bitflags",
21
+ "cexpr",
22
+ "clang-sys",
23
+ "itertools",
24
+ "proc-macro2",
25
+ "quote",
26
+ "regex",
27
+ "rustc-hash",
28
+ "shlex",
29
+ "syn",
30
+ ]
31
+
32
+ [[package]]
33
+ name = "bitflags"
34
+ version = "2.13.2"
35
+ source = "registry+https://github.com/rust-lang/crates.io-index"
36
+ checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
37
+
38
+ [[package]]
39
+ name = "bytes"
40
+ version = "1.12.1"
41
+ source = "registry+https://github.com/rust-lang/crates.io-index"
42
+ checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
43
+
44
+ [[package]]
45
+ name = "cexpr"
46
+ version = "0.6.0"
47
+ source = "registry+https://github.com/rust-lang/crates.io-index"
48
+ checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
49
+ dependencies = [
50
+ "nom",
51
+ ]
52
+
53
+ [[package]]
54
+ name = "cfg-if"
55
+ version = "1.0.5"
56
+ source = "registry+https://github.com/rust-lang/crates.io-index"
57
+ checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
58
+
59
+ [[package]]
60
+ name = "clang-sys"
61
+ version = "1.9.1"
62
+ source = "registry+https://github.com/rust-lang/crates.io-index"
63
+ checksum = "157a8ba7b480713b56f4c09fd13fc3e0a22a5dfab8097ba61cbc5feef950788a"
64
+ dependencies = [
65
+ "glob",
66
+ "libc",
67
+ "libloading",
68
+ ]
69
+
70
+ [[package]]
71
+ name = "either"
72
+ version = "1.19.0"
73
+ source = "registry+https://github.com/rust-lang/crates.io-index"
74
+ checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"
75
+
76
+ [[package]]
77
+ name = "fair-machines"
78
+ version = "0.7.0"
79
+ dependencies = [
80
+ "flow-machines",
81
+ "matryona-machines",
82
+ "priority-machines",
83
+ ]
84
+
85
+ [[package]]
86
+ name = "fair_machines_native"
87
+ version = "0.1.8"
88
+ dependencies = [
89
+ "fair-machines",
90
+ "magnus",
91
+ "matryona-machines",
92
+ "rb-sys",
93
+ ]
94
+
95
+ [[package]]
96
+ name = "flow-machines"
97
+ version = "0.4.1"
98
+ source = "registry+https://github.com/rust-lang/crates.io-index"
99
+ checksum = "762c59df44265a4181afd1ee4bd1f4a0b87b954b71cbd1bb128f3cbcaaccfac4"
100
+
101
+ [[package]]
102
+ name = "glob"
103
+ version = "0.3.4"
104
+ source = "registry+https://github.com/rust-lang/crates.io-index"
105
+ checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b"
106
+
107
+ [[package]]
108
+ name = "itertools"
109
+ version = "0.13.0"
110
+ source = "registry+https://github.com/rust-lang/crates.io-index"
111
+ checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
112
+ dependencies = [
113
+ "either",
114
+ ]
115
+
116
+ [[package]]
117
+ name = "lazy_static"
118
+ version = "1.5.1"
119
+ source = "registry+https://github.com/rust-lang/crates.io-index"
120
+ checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb"
121
+
122
+ [[package]]
123
+ name = "libc"
124
+ version = "0.2.191"
125
+ source = "registry+https://github.com/rust-lang/crates.io-index"
126
+ checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
127
+
128
+ [[package]]
129
+ name = "libloading"
130
+ version = "0.8.9"
131
+ source = "registry+https://github.com/rust-lang/crates.io-index"
132
+ checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
133
+ dependencies = [
134
+ "cfg-if",
135
+ "windows-link",
136
+ ]
137
+
138
+ [[package]]
139
+ name = "magnus"
140
+ version = "0.9.3"
141
+ source = "registry+https://github.com/rust-lang/crates.io-index"
142
+ checksum = "40ef424404d166cbb71c8b8d19c9c589c748c4547c1afa1928c5504299f6c713"
143
+ dependencies = [
144
+ "bytes",
145
+ "magnus-macros",
146
+ "rb-sys",
147
+ "rb-sys-env",
148
+ "seq-macro",
149
+ ]
150
+
151
+ [[package]]
152
+ name = "magnus-macros"
153
+ version = "0.9.1"
154
+ source = "registry+https://github.com/rust-lang/crates.io-index"
155
+ checksum = "9dafde2eeb66f090e0f326112323eb8324b12cb32b5d1210e541d3df6b0ce77e"
156
+ dependencies = [
157
+ "proc-macro2",
158
+ "quote",
159
+ "syn",
160
+ ]
161
+
162
+ [[package]]
163
+ name = "matryona-machines"
164
+ version = "0.6.0"
165
+ source = "registry+https://github.com/rust-lang/crates.io-index"
166
+ checksum = "cf8a06ab02efd767270815a1f515a40bbf3bfc77038e9360676ebe8d47833b07"
167
+ dependencies = [
168
+ "magnus",
169
+ ]
170
+
171
+ [[package]]
172
+ name = "memchr"
173
+ version = "2.8.3"
174
+ source = "registry+https://github.com/rust-lang/crates.io-index"
175
+ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
176
+
177
+ [[package]]
178
+ name = "minimal-lexical"
179
+ version = "0.2.1"
180
+ source = "registry+https://github.com/rust-lang/crates.io-index"
181
+ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
182
+
183
+ [[package]]
184
+ name = "nom"
185
+ version = "7.1.3"
186
+ source = "registry+https://github.com/rust-lang/crates.io-index"
187
+ checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
188
+ dependencies = [
189
+ "memchr",
190
+ "minimal-lexical",
191
+ ]
192
+
193
+ [[package]]
194
+ name = "priority-machines"
195
+ version = "0.7.0"
196
+ source = "registry+https://github.com/rust-lang/crates.io-index"
197
+ checksum = "c4fe60b36f6dd77f7954cec7508b2a56ef13b845df99a95f76794602d89fe06d"
198
+
199
+ [[package]]
200
+ name = "proc-macro2"
201
+ version = "1.0.107"
202
+ source = "registry+https://github.com/rust-lang/crates.io-index"
203
+ checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
204
+ dependencies = [
205
+ "unicode-ident",
206
+ ]
207
+
208
+ [[package]]
209
+ name = "quote"
210
+ version = "1.0.47"
211
+ source = "registry+https://github.com/rust-lang/crates.io-index"
212
+ checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
213
+ dependencies = [
214
+ "proc-macro2",
215
+ ]
216
+
217
+ [[package]]
218
+ name = "rb-sys"
219
+ version = "0.9.130"
220
+ source = "registry+https://github.com/rust-lang/crates.io-index"
221
+ checksum = "02faf625bb10ba893e3ae620f19c9fb1b5f8fcae0fe4eb86bb3f2230fad75edb"
222
+ dependencies = [
223
+ "rb-sys-build",
224
+ ]
225
+
226
+ [[package]]
227
+ name = "rb-sys-build"
228
+ version = "0.9.130"
229
+ source = "registry+https://github.com/rust-lang/crates.io-index"
230
+ checksum = "05be6f9c86fe5482808162826f6c047d093b3670582296c770de1d94f8066694"
231
+ dependencies = [
232
+ "bindgen",
233
+ "lazy_static",
234
+ "proc-macro2",
235
+ "quote",
236
+ "regex",
237
+ "shell-words",
238
+ "syn",
239
+ ]
240
+
241
+ [[package]]
242
+ name = "rb-sys-env"
243
+ version = "0.2.3"
244
+ source = "registry+https://github.com/rust-lang/crates.io-index"
245
+ checksum = "cca7ad6a7e21e72151d56fe2495a259b5670e204c3adac41ee7ef676ea08117a"
246
+
247
+ [[package]]
248
+ name = "regex"
249
+ version = "1.13.1"
250
+ source = "registry+https://github.com/rust-lang/crates.io-index"
251
+ checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d"
252
+ dependencies = [
253
+ "aho-corasick",
254
+ "memchr",
255
+ "regex-automata",
256
+ "regex-syntax",
257
+ ]
258
+
259
+ [[package]]
260
+ name = "regex-automata"
261
+ version = "0.4.18"
262
+ source = "registry+https://github.com/rust-lang/crates.io-index"
263
+ checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2"
264
+ dependencies = [
265
+ "aho-corasick",
266
+ "memchr",
267
+ "regex-syntax",
268
+ ]
269
+
270
+ [[package]]
271
+ name = "regex-syntax"
272
+ version = "0.8.11"
273
+ source = "registry+https://github.com/rust-lang/crates.io-index"
274
+ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
275
+
276
+ [[package]]
277
+ name = "rustc-hash"
278
+ version = "2.1.3"
279
+ source = "registry+https://github.com/rust-lang/crates.io-index"
280
+ checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
281
+
282
+ [[package]]
283
+ name = "seq-macro"
284
+ version = "0.3.6"
285
+ source = "registry+https://github.com/rust-lang/crates.io-index"
286
+ checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc"
287
+
288
+ [[package]]
289
+ name = "shell-words"
290
+ version = "1.1.1"
291
+ source = "registry+https://github.com/rust-lang/crates.io-index"
292
+ checksum = "dc6fe69c597f9c37bfeeeeeb33da3530379845f10be461a66d16d03eca2ded77"
293
+
294
+ [[package]]
295
+ name = "shlex"
296
+ version = "1.3.0"
297
+ source = "registry+https://github.com/rust-lang/crates.io-index"
298
+ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
299
+
300
+ [[package]]
301
+ name = "syn"
302
+ version = "2.0.119"
303
+ source = "registry+https://github.com/rust-lang/crates.io-index"
304
+ checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
305
+ dependencies = [
306
+ "proc-macro2",
307
+ "quote",
308
+ "unicode-ident",
309
+ ]
310
+
311
+ [[package]]
312
+ name = "unicode-ident"
313
+ version = "1.0.27"
314
+ source = "registry+https://github.com/rust-lang/crates.io-index"
315
+ checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
316
+
317
+ [[package]]
318
+ name = "windows-link"
319
+ version = "0.2.1"
320
+ source = "registry+https://github.com/rust-lang/crates.io-index"
321
+ checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
data/Cargo.toml CHANGED
@@ -8,13 +8,15 @@ rust-version = "1.99"
8
8
  license = "MIT"
9
9
  [workspace.dependencies]
10
10
  fair-machines = { path = "ext/fair_machines_native/core" }
11
+ matryona-machines = { version = ">=0.6", default-features = false }
11
12
  magnus = { version = "0.9.3", default-features = false }
12
13
  rb-sys = { version = "0.9.130", default-features = false, features = ["stable-api-compiled-fallback"] }
13
- priority-machines = ">=0.2"
14
- flow-machines = ">=0.2"
14
+ priority-machines = ">=0.7"
15
+ flow-machines = ">=0.4.1"
15
16
  [workspace.lints.rust]
16
17
  unsafe_code = "deny"
17
18
  unused_must_use = "warn"
19
+ missing_docs = "warn"
18
20
  [workspace.lints.clippy]
19
21
  all = { level = "warn", priority = -1 }
20
22
  pedantic = { level = "warn", priority = -1 }
data/README.md CHANGED
@@ -12,11 +12,11 @@ gem 'fair_machines'
12
12
 
13
13
  ```ruby
14
14
  # Two tenants. Each may have 100 units of work queued; each gets 2 units per round.
15
- fair = FairMachines::TenantFair.new(capacities: [100, 100], quanta: [2, 2])
15
+ fair = FairMachines::TenantFair.new([100, 100], [2, 2]) # capacities, quanta
16
16
 
17
17
  # Enterprise tenant enqueues ten PDF exports at cost 5. Small tenant queues five emails at cost 1.
18
- 10.times { fair.admit(tenant: 0, cost: 5) }
19
- 5.times { fair.admit(tenant: 1, cost: 1) }
18
+ 10.times { fair.admit(0, 5) } # => :admitted (tenant, cost)
19
+ 5.times { fair.admit(1, 1) }
20
20
 
21
21
  # Each round, tell the scheduler the cost at the head of every tenant's queue.
22
22
  # It answers with the tenant whose head runs now. You pop that job and run it.
@@ -58,7 +58,7 @@ end
58
58
 
59
59
  ## The Flight Plan
60
60
 
61
- Each tenant is either idle or has cost queued. Admission moves cost in, dispatch and cancellation move it out, and a full budget turns new work away.
61
+ Each tenant is either idle or has cost queued. Admission moves cost in, dispatch and cancellation move it out, and a full budget turns new work away. A refusal moves nothing.
62
62
 
63
63
  ```mermaid
64
64
  stateDiagram-v2
@@ -82,9 +82,9 @@ sequenceDiagram
82
82
  participant W as Workers
83
83
 
84
84
  E->>F: admit cost 5, ten times
85
- F-->>E: true, true, true...
85
+ F-->>E: :admitted, :admitted...
86
86
  S->>F: admit cost 1
87
- F-->>S: true
87
+ F-->>S: :admitted
88
88
 
89
89
  W->>F: select([5, 1])
90
90
  F-->>W: tenant 1
@@ -104,44 +104,54 @@ sequenceDiagram
104
104
 
105
105
  ### Admit
106
106
 
107
- Before a job is enqueued, ask whether the tenant has room for its cost. The answer is a plain boolean, and `false` means the job doesn't go on the queue.
107
+ Before a job is enqueued, ask whether the tenant has room for its cost. `:admitted` means it does and the cost is now on the ledger. Anything else is a refusal, and the job doesn't go on the queue.
108
108
 
109
109
  ```ruby
110
- fair = FairMachines::TenantFair.new(capacities: [10, 5], quanta: [3, 1])
111
-
112
- fair.admit(tenant: 1, cost: 5) # => true budget 5, now full
113
- fair.admit(tenant: 1, cost: 1) # => false over budget
114
- fair.admit(tenant: 2, cost: 1) # => false no such tenant
115
- fair.tenant_count # => 2
110
+ fair = FairMachines::TenantFair.new([10, 5], [3, 1])
111
+
112
+ fair.admit(1, 5) # => :admitted budget 5, now full
113
+ fair.admit(1, 1) # => :insufficient over budget
114
+ fair.admit(2, 1) # => :unknown_tenant no such tenant
115
+ fair.in_flight(1) # => 5
116
+ fair.available(1) # => 0
117
+ fair.tenant_count # => 2
116
118
  ```
117
119
 
118
- Over-budget is a refusal, not an error. Decide what to do with the job: reject it, hold it, tell the tenant.
120
+ Over-budget is a refusal, not an error. Decide what to do with the job: reject it, hold it, tell the tenant. Every answer is a symbol and every symbol is truthy, so don't write `if fair.admit(...)`. Compare against `:admitted`.
119
121
 
120
122
  ### Select
121
123
 
122
124
  Each round, pass the head cost of every tenant's queue. You get back the tenant whose head runs now, or `nil` when nobody is eligible. The chosen tenant is charged that cost against its budget, so the room comes back as the work drains.
123
125
 
124
126
  ```ruby
125
- fair = FairMachines::TenantFair.new(capacities: [10, 5], quanta: [3, 1])
126
- fair.admit(tenant: 0, cost: 4)
127
- fair.admit(tenant: 1, cost: 1)
128
-
129
- fair.select([4, 1]) # => 1
130
- fair.select([4, nil]) # => 0
131
- fair.select([4, nil]) # => nil tenant 0 has nothing left queued
132
- fair.admit(tenant: 0, cost: 7) # => true the dispatched 4 freed its room
127
+ fair = FairMachines::TenantFair.new([10, 5], [3, 1])
128
+ fair.admit(0, 4)
129
+ fair.admit(1, 1)
130
+
131
+ fair.select([4, 1]) # => 1
132
+ fair.select([4, nil]) # => 0
133
+ fair.select([nil, nil]) # => nil both queues are empty
134
+ fair.admit(0, 7) # => :admitted the dispatched 4 freed its room
133
135
  ```
134
136
 
135
- Heads have to be truthful. A head that costs more than the tenant has admitted is not eligible and `select` returns `nil` for it.
137
+ `nil` means one thing: every head you passed was `nil`.
138
+
139
+ Heads have to be truthful. A head that costs more than its tenant has admitted was never admitted, so it can't be dispatched. `select` refuses the whole round with `:exceeds_in_flight` and changes nothing, rather than quietly skipping that tenant and leaving you to wonder why its jobs never run.
140
+
141
+ ```ruby
142
+ fair.select([8, nil]) # => :exceeds_in_flight tenant 0 only admitted 7
143
+ fair.select([7, 1]) # => :exceeds_in_flight tenant 1 admitted nothing
144
+ fair.select([7, nil]) # => 0
145
+ ```
136
146
 
137
147
  ### Share is by cost, not by count
138
148
 
139
149
  Quanta are how much cost each tenant may dispatch per round, with leftover carried to the next round. A tenant whose head is expensive waits until it has saved up. A tenant with cheap jobs runs one every round.
140
150
 
141
151
  ```ruby
142
- fair = FairMachines::TenantFair.new(capacities: [50, 50], quanta: [2, 2])
143
- fair.admit(tenant: 0, cost: 40) # heavy jobs at cost 4
144
- fair.admit(tenant: 1, cost: 10) # light jobs at cost 1
152
+ fair = FairMachines::TenantFair.new([50, 50], [2, 2])
153
+ fair.admit(0, 40) # heavy jobs at cost 4
154
+ fair.admit(1, 10) # light jobs at cost 1
145
155
 
146
156
  Array.new(10) { fair.select([4, 1]) }
147
157
  # => [1, 1, 0, 1, 1, 1, 1, 0, 1, 1]
@@ -152,9 +162,9 @@ Same quanta, same share of the pool, and the light tenant still dispatches four
152
162
  Give one tenant a bigger quantum and it gets a bigger share of the pool outright:
153
163
 
154
164
  ```ruby
155
- fair = FairMachines::TenantFair.new(capacities: [20, 20], quanta: [3, 1])
156
- fair.admit(tenant: 0, cost: 20)
157
- fair.admit(tenant: 1, cost: 20)
165
+ fair = FairMachines::TenantFair.new([20, 20], [3, 1])
166
+ fair.admit(0, 20)
167
+ fair.admit(1, 20)
158
168
 
159
169
  Array.new(8) { fair.select([1, 1]) }
160
170
  # => [0, 0, 0, 1, 0, 0, 0, 1]
@@ -165,38 +175,72 @@ Array.new(8) { fair.select([1, 1]) }
165
175
  A job that leaves the queue without being dispatched has to give its cost back, or the tenant's budget leaks until nothing is admitted.
166
176
 
167
177
  ```ruby
168
- fair = FairMachines::TenantFair.new(capacities: [10, 5], quanta: [3, 1])
169
- fair.admit(tenant: 0, cost: 4)
178
+ fair = FairMachines::TenantFair.new([10, 5], [3, 1])
179
+ fair.admit(0, 4)
170
180
 
171
- fair.cancel(tenant: 0, cost: 4) # => true
172
- fair.cancel(tenant: 0, cost: 1) # => false nothing left to cancel
173
- fair.select([4, nil]) # => nil the queue is empty, and so is the ledger
181
+ fair.cancel(0, 4) # => :cancelled
182
+ fair.cancel(0, 1) # => :exceeds_in_flight nothing left to cancel
183
+ fair.select([nil, nil]) # => nil the queue is empty, and so is the ledger
174
184
  ```
175
185
 
176
- Cancelling more than was admitted is refused, and the ledger is untouched.
186
+ Cancelling more than was admitted is refused, and the ledger is untouched. The ledger counts cost, not jobs: it can't tell a cancel you sent twice from two jobs of the same cost. Cancel each job once.
177
187
 
178
188
  ### Too many tenants to name: `KeyedFair`
179
189
 
180
- Sixteen tenant slots is a crew roster. Orgs, API keys and IP prefixes are a starfield. `KeyedFair` hashes each key onto a fixed set of lanes, every lane with its own budget and no queue. A loud org fills its lane and gets `nil`; the other lanes don't notice. Keys that hash to the same lane share its budget, so pick enough lanes that a collision is rare.
190
+ Sixteen tenant slots is a crew roster. Orgs, API keys and IP prefixes are a starfield. `KeyedFair` hashes each key onto a fixed set of lanes, every lane with its own budget and no queue. A loud org fills its lane and gets `:insufficient`; the other lanes don't notice. Keys that hash to the same lane share its budget, so pick enough lanes that a collision is rare.
181
191
 
182
192
  ```ruby
183
- fair = FairMachines::KeyedFair.new(lanes: 64, capacity: 8)
193
+ fair = FairMachines::KeyedFair.new(64, 8) # lanes, capacity per lane
184
194
 
185
- lane = fair.admit(hash: org_id.hash, cost: 1) # => 17, or nil when that lane is full
195
+ hash = org_id.hash & 0xFFFF_FFFF_FFFF_FFFF # hashes are unsigned 64-bit
196
+ lane = fair.admit(hash, 1) # => #<data FairMachines::Lane index=17>, or :insufficient
186
197
  # ... do the work ...
187
- fair.release(lane:, cost: 1) # => true
198
+ fair.release(lane, 1) # => :released
188
199
  ```
189
200
 
190
- `lanes:` is a power of two from 1 to 256. Any Integer works as `hash:`, negatives included, so `key.hash` goes straight in.
201
+ Any lane count from 1 to 256 works. `admit` hands back the `Lane` it charged so you don't hash twice. A lane is just a bucket number wrapped in a `Data`: the same hash lands in the same lane every time, in every `KeyedFair` with as many lanes, and you can ask for one without admitting anything.
202
+
203
+ ```ruby
204
+ FairMachines::KeyedFair.lane(64, hash) # => #<data FairMachines::Lane index=17>
205
+ FairMachines::KeyedFair.lane_at(64, 63) # => #<data FairMachines::Lane index=63>
206
+ FairMachines::KeyedFair.lane_at(64, 64) # => nil
207
+ fair.in_flight(lane) # => 0
208
+ fair.release(FairMachines::Lane.new(64), 1) # => :unknown_lane
209
+ ```
191
210
 
192
211
  ## The Rules of the Escort
193
212
 
194
- - **1 to 16 tenants**, set by the length of `capacities:`. `quanta:` must be the same length. Empty, longer, or mismatched arrays raise `ArgumentError`.
195
- - **Capacities, quanta, and costs are positive Integers** below `2**32`. Zero is `ArgumentError`, negative or too large is `RangeError`, floats and strings are `TypeError`. Nothing is rounded for you.
196
- - **Heads are exactly `tenant_count` entries**, each a positive Integer or `nil`. The wrong length or a zero raises `ArgumentError`, and a float raises `TypeError`, before anything changes.
197
- - **Bad tenant indices don't raise.** `admit` and `cancel` with an unknown tenant return `false`.
198
- - **Frozen means frozen.** `freeze` the scheduler and `admit`, `cancel`, and `select` raise `FrozenError`. `tenant_count` still answers.
199
- - **A tenant that drains to empty loses its saved-up share.** Leftover quantum doesn't accumulate for a tenant with nothing queued.
213
+ - **Ruby mirrors the Rust core.** Arguments are positional, in the core's order: `TenantFair.new(capacities, quanta)`, `admit(tenant, cost)`, `KeyedFair.new(lanes, capacity)`. `Lane` is a `Data` with an `index`. Where the core has a function on the type, `KeyedFair::<LANES>::lane(hash)`, Ruby has a class method that takes the lane count first: `KeyedFair.lane(lanes, hash)`.
214
+ - **Every answer, by method.**
215
+
216
+ | Method | Honoured | Refused |
217
+ | --- | --- | --- |
218
+ | `TenantFair#admit(tenant, cost)` | `:admitted` | `:unknown_tenant`, `:insufficient` |
219
+ | `TenantFair#cancel(tenant, cost)` | `:cancelled` | `:unknown_tenant`, `:exceeds_in_flight` |
220
+ | `TenantFair#select(heads)` | the tenant to dispatch (Integer), `nil` exactly when every head is `nil` | `:exceeds_in_flight` |
221
+ | `TenantFair#in_flight(tenant)`, `#available(tenant)` | Integer, `nil` for an index that is not a tenant | never refuse |
222
+ | `KeyedFair#admit(hash, cost)` | the `Lane` charged | `:insufficient` |
223
+ | `KeyedFair#release(lane, cost)` | `:released` | `:unknown_lane`, `:exceeds_in_flight` |
224
+ | `KeyedFair#in_flight(lane)`, `#available(lane)` | Integer, `nil` for a lane this instance does not have | never refuse |
225
+ | `KeyedFair.lane(lanes, hash)` | a `Lane` | never refuses |
226
+ | `KeyedFair.lane_at(lanes, index)` | a `Lane`, `nil` for an index of `lanes` or more | never refuses |
227
+ | `tenant_count`, `lane_count` | Integer | never refuse |
228
+
229
+ Every refusal has its own symbol; there is no catch-all. No method takes a time, so no answer records a clock.
230
+ - **A refusal never raises and changes nothing.** Not a budget, not a tenant's saved share, not whose turn it is.
231
+ - **1 to 16 tenants**, set by the length of `capacities`; `quanta` must be the same length. Empty, longer, or mismatched arrays raise `RangeError`. The tenant count is the core's const generic `N`, and the core has no ceiling of its own: `TenantFair::MAX_TENANTS`, 16, is the largest `N` compiled into the binding.
232
+ - **1 to 256 lanes**, any count, not only powers of two. Outside that is `RangeError`. The lane count is the core's const generic `LANES`; `KeyedFair::MAX_LANES`, 256, is the largest compiled into the binding.
233
+ - **Wrong type is `TypeError`, wrong value is `RangeError`,** and the message names the argument (`tenant must be an Integer`, `cost must be in 1..=4294967295`). `ArgumentError` is Ruby's own, for the wrong number of arguments.
234
+ - **Capacities, quanta, and costs are positive Integers** below `2**32`. Zero, negative or too large is `RangeError`; floats and strings are `TypeError`. Nothing is rounded for you.
235
+ - **Hashes are Integers** in `0...2**64`; **tenant indices** are Integers a `usize` holds (`0...2**64` on a 64-bit platform, `0...2**32` on a 32-bit one). Negative or too large is `RangeError`. Ruby's `#hash` can be negative: mask it, as above. A tenant index past the last tenant doesn't raise; it's `:unknown_tenant`.
236
+ - **Heads are exactly `tenant_count` entries**, each a positive Integer or `nil`. The wrong length or a zero raises `RangeError`, a float `TypeError`, before anything changes.
237
+ - **`release`, `in_flight` and `available` on a `KeyedFair` take a `Lane`**, not a bare Integer. Anything else is `TypeError`.
238
+ - **A `Lane` is valid or does not exist.** `Lane.new(index)` is the core's `Lane::new(index)`: an Integer a `usize` holds, `TypeError` for anything else, `RangeError` outside the range. One you build by hand is held to the same rule as one `admit` returned. `Lane` is sealed: subclassing it raises `TypeError` and `allocate` is gone. That stops accidents, not reflection, so the binding checks too: a lane it reads must be an instance of exactly `Lane` (`TypeError` otherwise) and its index is re-checked (`RangeError`), so a lane forged with `Data#initialize` or `Marshal` never reaches the core. `TenantFair` and `KeyedFair` are sealed too: they wrap native state, and subclassing either raises `TypeError`.
239
+ - **The binding never loses work.** Everything that can raise happens before the core is called. `admit` charges a copy, builds the `Lane` it answers, and keeps the copy only if the `KeyedFair` is still unfrozen and unchanged: if building the lane raises, freezes it (`FrozenError`) or calls back into it (`RuntimeError`), nothing is charged.
240
+ - **A `Lane` is a bucket, not a ticket.** Nobody issued it and it proves nothing: anyone can build one, and two `KeyedFair`s with the same lane count agree on every lane. That's the point of hashing. Keep separate things in separate `KeyedFair`s and don't mix their lanes up.
241
+ - **Repeats aren't recognised.** `cancel` and `release` count cost, so a second one is honoured while cost remains and `:exceeds_in_flight` after. There are no ids, so nothing survives a restart either: a new ledger starts empty.
242
+ - **Frozen means frozen.** `freeze` either object and `admit`, `cancel`, `select`, and `release` raise `FrozenError`. Readers still answer.
243
+ - **A tenant that drains to empty loses its saved-up share.** Leftover quantum doesn't accumulate for a tenant with nothing queued, and a tenant you present as `nil` to `select` is treated the same.
200
244
 
201
245
  ## What You Think You're Doing vs Reality
202
246
 
@@ -207,7 +251,7 @@ Taking turns by job count hands the pool to whoever submits the heaviest jobs. F
207
251
 
208
252
  ## What's Yours
209
253
 
210
- The scheduler is a ledger, not a queue. You keep a queue per tenant, call `admit` before you push, hand `select` the cost at the head of each queue, and pop the job from the tenant it names. Your cost estimates have to be honest, because the ledger believes them. And when a job dies on the floor without running, call `cancel`, or the tenant pays for it forever.
254
+ The scheduler is a ledger, not a queue. You keep a queue per tenant, call `admit` before you push and push only on `:admitted`, hand `select` the cost at the head of each queue, and pop the job from the tenant it names. Your cost estimates have to be honest, because the ledger believes them. And when a job dies on the floor without running, call `cancel`, or the tenant pays for it forever.
211
255
 
212
256
  ## License
213
257