stablemates-workhorse 0.0.0 → 0.6.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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +147 -0
  3. data/LICENSE +201 -0
  4. data/NOTICE +6 -0
  5. data/README.md +104 -1
  6. data/lib/stablemates/workhorse/active_job.rb +272 -0
  7. data/lib/stablemates/workhorse/active_record_executor.rb +23 -0
  8. data/lib/stablemates/workhorse/admin.rb +630 -0
  9. data/lib/stablemates/workhorse/batch_context.rb +36 -0
  10. data/lib/stablemates/workhorse/compatibility.rb +43 -0
  11. data/lib/stablemates/workhorse/context.rb +587 -0
  12. data/lib/stablemates/workhorse/contracts.rb +379 -0
  13. data/lib/stablemates/workhorse/dashboard/backend.rb +328 -0
  14. data/lib/stablemates/workhorse/dashboard/bundle.json +6 -0
  15. data/lib/stablemates/workhorse/dashboard/read-surface-1.tar.gz +0 -0
  16. data/lib/stablemates/workhorse/dashboard/v1_generated.rb +54 -0
  17. data/lib/stablemates/workhorse/dashboard/validator.rb +124 -0
  18. data/lib/stablemates/workhorse/dashboard.rb +310 -0
  19. data/lib/stablemates/workhorse/ecma_pattern/properties.rb +299 -0
  20. data/lib/stablemates/workhorse/ecma_pattern.rb +270 -0
  21. data/lib/stablemates/workhorse/errors.rb +233 -0
  22. data/lib/stablemates/workhorse/executor.rb +138 -0
  23. data/lib/stablemates/workhorse/policies.rb +52 -0
  24. data/lib/stablemates/workhorse/queue.rb +668 -0
  25. data/lib/stablemates/workhorse/sql_catalogue_generated.rb +1117 -0
  26. data/lib/stablemates/workhorse/telemetry.rb +152 -0
  27. data/lib/stablemates/workhorse/types.rb +273 -0
  28. data/lib/stablemates/workhorse/version.rb +7 -0
  29. data/lib/stablemates/workhorse/worker/batch.rb +211 -0
  30. data/lib/stablemates/workhorse/worker/heartbeat.rb +207 -0
  31. data/lib/stablemates/workhorse/worker/listener.rb +168 -0
  32. data/lib/stablemates/workhorse/worker/process.rb +93 -0
  33. data/lib/stablemates/workhorse/worker/supervisor.rb +140 -0
  34. data/lib/stablemates/workhorse/worker.rb +1566 -0
  35. data/lib/stablemates/workhorse.rb +49 -0
  36. metadata +99 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0ccf89624e70f05719adf1c51708ea2225f3e572f9f76feefa9ed1bbe70d931
4
- data.tar.gz: d0edc384cabeedd7e279d2d5a34a13eabc55617bf626daaaac5fb739fee56b08
3
+ metadata.gz: 98c5582b19c14aaf69dd9b317684c9a5e49a5508caf5759b79894fbe78c54146
4
+ data.tar.gz: 6f9a14b8dff61da2cadacc25f792c44a8b25281877b12bb47530a296b5a1e9e0
5
5
  SHA512:
6
- metadata.gz: 4010e3ad425e862f212588b5b2b60b43bf9f7cab7b35203ba8fd470d2534b839419977474ec339dd9d9354458ba5f032329a6b2edcc0cd83c49c0636cdc6c3e4
7
- data.tar.gz: 73c8d6c59994652de82b8539e195308019e729607cfee18f84a1d1c22332ef40ffa518c61bb3e9820a6f3aefaba7cae80a0fdc45a266505f2e1eb4a853cf7c70
6
+ metadata.gz: 98805ebb4ddc387026073a530960c1494ea7fbfac0a294829b1152b0f300dbb551d1ae4c944a87fdf698e6a0debd96ddf825e55444c8dffb9b584beb74053e05
7
+ data.tar.gz: 81fef1e8bf1c9e5850b031aa5ac697a93b85ecbda2ae63687b60dfd6c2d821f08304b45e816dafadeea6105ef12820734e81086f3543bbfb5bb9bd7f857c9061
data/CHANGELOG.md ADDED
@@ -0,0 +1,147 @@
1
+ # Ruby changelog
2
+
3
+ `stablemates-workhorse` gem versions and release notes live here. The gem carries the version the
4
+ other SDKs carry, because every tag names one release of all of them.
5
+
6
+ ## 0.6.0 — 2026-10-02
7
+
8
+ The npm packages, Python distribution, Go module, Rust crate, and Ruby gem release from one source commit.
9
+
10
+ Requires **schema v43**, Ruby **3.3** or newer, and PostgreSQL **15** or newer.
11
+
12
+ - The gem needs schema version 43 or later. The SDK compatibility floor is schema version **43**,
13
+ and the final schema version is **52**. The migrations since 0.5.0 only add, so the upgrade is a
14
+ rolling deployment: run `workhorse schema migrate` before any new process starts. The
15
+ [root changelog](../CHANGELOG.md) lists the SQL fixes. Each takes effect when its migration commits, and version 52
16
+ includes them all.
17
+ - An installation that runs cold export stops its exporters across migration 0052. That migration
18
+ repairs the export ledger, but it cannot stop an upload already in flight. Upgrade in this order:
19
+
20
+ 1. Stop every cold exporter, and let each finish its object and manifest uploads.
21
+ 2. Keep cold export enabled, so retention keeps waiting for the export.
22
+ 3. Run `workhorse schema migrate`.
23
+ 4. Restart the exporters after the migration commits.
24
+
25
+ An installation that never enabled cold export needs no extra step. The
26
+ [cold export guide](../docs/guides/335-cold-export.md#a-day-is-a-utc-day) explains the repair.
27
+
28
+ - A handler result PostgreSQL cannot store now fails only its task. jsonb refuses a NUL character
29
+ and an unpaired surrogate. Such a result used to reach the completion statement, whose refusal
30
+ ended `run` and left the task leased. The worker now fails the attempt under the task's retry
31
+ policy with an `ArgumentError`. Its message names the task type and carries no part of the value.
32
+ On the fast tier the other members of a completion batch still complete. A database error during
33
+ completion still ends `run`.
34
+ - `Queue#sync_schedules` applies each task type's current contract, read from PostgreSQL, before
35
+ the write. A payload that fails the schema raises `ContractValidationError` and writes nothing. A
36
+ valid definition stores the contract version, its size limits, and its redaction keys.
37
+ - Add the `Queue` client: `enqueue` and `enqueue_many` with every client enqueue option,
38
+ cancellation, signal and human wait delivery, queue health, and schedule and contract
39
+ synchronization. `sync_concurrency_policies`, `sync_rate_limit_policies`, and `sync_budgets`
40
+ replace a namespace's definitions, and the list methods read them back.
41
+ - Durations, including a `RateLimit` interval, are finite Numeric seconds. The client refuses a
42
+ value outside a protocol bound with `ArgumentError` before it sends any statement.
43
+ - Contract schemas are checked against the draft 2020-12 meta-schema. The contract profile rejects
44
+ `pattern` and `patternProperties` at any depth with `ArgumentError`, as every SDK does
45
+ ([ADR 0039](../docs/decisions/0039-use-a-restricted-json-schema-contract-profile.md)). Check a
46
+ string's shape in handler code instead. A `$ref` must point at a subschema, so it cannot reach a
47
+ schema hidden in `default` or `examples`; any other reference raises `ArgumentError` with
48
+ `<path>.$ref must point at a subschema of the contract`, including a pointer that encodes `/` as
49
+ `%2F`.
50
+ - **Breaking: a contract version that another SDK's 0.5 release synced with `pattern` or
51
+ `patternProperties` does not compile in this gem.** Upgrade in this order:
52
+ 1. Find each contract version that uses either keyword, or a `$ref` that points outside a
53
+ subschema.
54
+ 2. Publish a new version without either keyword, and move `currentVersion` to it.
55
+ 3. Let tasks that hold the old version finish before you run Ruby workers. A worker checks a
56
+ task's result against the version the task holds. If that version's result schema uses either
57
+ keyword, completing the task fails the attempt with `ArgumentError`, and the task's retry
58
+ policy applies. Each payload was checked at enqueue, so a keyword in the payload schema does
59
+ not affect tasks already queued.
60
+ - **Breaking: a contract `$ref` must be `#` or `#/$defs/<name>`, and `$anchor` is no longer
61
+ accepted** ([ADR 0039](../docs/decisions/0039-use-a-restricted-json-schema-contract-profile.md)).
62
+ `<name>` is a key of the root `$defs`. `ArgumentError` names any other reference with
63
+ `<path>.$ref must point at a subschema of the contract`, and also `$defs` below the root, a
64
+ `$defs` name that does not match `^[A-Za-z_][-A-Za-z0-9._]*$`, and `$anchor` at any depth. A
65
+ property named `$anchor` stays valid. Upgrade in this order:
66
+ 1. Find each contract version that references anything other than `#` or a root definition, nests
67
+ `$defs`, uses `$anchor`, or names a definition outside that pattern.
68
+ 2. Move each referenced or anchored subschema into the root `$defs` and reference it as
69
+ `#/$defs/<name>`. Rename each definition outside the pattern and update the references to it.
70
+ Declare a new contract version, because contract rows are immutable, and move `currentVersion`
71
+ to it.
72
+ 3. Let tasks that hold the old version finish before you run Ruby workers. A removed form in a
73
+ task's result schema fails the attempt with `ArgumentError`, and the task's retry policy
74
+ applies.
75
+ - Add the executor forms: a `PG::Connection`, a `ConnectionPool`, or any object whose `with`
76
+ yields a connection. `ActiveRecordExecutor` joins the caller's Active Record transaction.
77
+ - Add the error hierarchy under `Stablemates::Workhorse::Error`.
78
+ - Add the `Admin` operator client: task, timeline, checkpoint, progress, and wait inspection, dead
79
+ letter listing and redrive, worker pause, and queue pause, resume, and purge. Every control takes
80
+ an `AdminAudit`.
81
+ - Add `Dashboard`, a Rack application that serves the operator dashboard under a Rails `mount` or a
82
+ `Rack::Builder#map`. It answers the dashboard/v1 procedures and serves the bundled browser app.
83
+ - `Executor.for` ignores the `Object#with` that ActiveSupport defines, so a plain object is still
84
+ refused.
85
+ - Add `Worker`: it claims, heartbeats, completes, fails, and retries tasks over a
86
+ `ConnectionPool`, and runs handlers on a thread pool of `concurrency` threads. A handler receives
87
+ its payload and a `HandlerContext` with the task and a `CancellationToken`. `stop` requests
88
+ shutdown. `run` then drains handlers within `shutdown_grace`, cancels the rest with `:shutdown`,
89
+ and raises `ShutdownIncompleteError` when any handler still runs.
90
+ - Add the durable `HandlerContext` calls: `checkpoint`, `sleep`, `sleep_until`, `wait_for_signal`,
91
+ `wait_for_human`, `run_child`, `run_children`, `run_children_all`, `get_progress`, and
92
+ `set_progress`. A call that waits suspends the attempt and releases its lease, and the task
93
+ resumes in the same attempt. A handler that swallows the suspension still suspends, and the
94
+ worker logs `workhorse.handler.signal_swallowed`. After the lease is lost, every durable write
95
+ raises `LeaseLostError`; reads and checkpoint replays still return. A child without a queue runs on the worker's first queue.
96
+ - Under Rails, handlers run inside `Rails.application.executor.wrap`. `run` warns when the Active
97
+ Record pool is smaller than `concurrency`.
98
+ - `Worker` runs tasks on a fast-tier queue: it probes each queue with `complete_many_and_claim_v1`,
99
+ records one `fast_task_outcome` row per task, and fuses each completion with a refill claim.
100
+ `Worker.new(cohorts:)` splits the slots into dispatch cohorts; without it, the worker keeps one
101
+ below concurrency 8, else `concurrency / 8` from 2 through 8, capped by the pool's spare
102
+ connections. The handler thread pool now allows two threads per slot.
103
+ A fast-tier task's `HandlerContext` raises `FastTierUnsupportedError` for checkpoints,
104
+ progress writes, durable waits, and child tasks before any durable write. That holds for a
105
+ task claimed through `claim_many_v1` after its queue moved to the fast tier.
106
+ - `HandlerContext#wait_for_signal`, `wait_for_human`, `run_child`, `run_children`, and
107
+ `run_children_all` validate each step name before the deferred tier read or any write, as
108
+ `checkpoint` and `sleep` do. An invalid name raises `ArgumentError`. A child set is checked for
109
+ its type and size before its names.
110
+ - A pooled connection that PostgreSQL dropped is discarded through the pool's
111
+ `discard_current_connection`, so the next statement gets a fresh connection. Before, the pool
112
+ reused the dead connection until the process restarted. An ordinary SQL error keeps the
113
+ connection, and the failed statement is never resent.
114
+ - `Worker` measures a result as PostgreSQL does, by the UTF-8 length of its `jsonb` text, before
115
+ it completes the task. A result over the task's limit fails only its own attempt with
116
+ `ValueSizeLimitError`, and the retry policy decides what happens next. The worker no longer stops
117
+ when PostgreSQL refuses an oversized completion. That holds on both tiers and for batch members.
118
+ - Add `Worker#handle_batch` with `max_size:` and `linger:` in seconds. Once the worker stops, a
119
+ lingering batch runs as soon as every task it claimed has arrived.
120
+ - Change the `handle_batch` block from `|payloads, context|` to `|items|`. Each `BatchHandlerItem`
121
+ holds a member's `payload` and its own `BatchHandlerContext` with `task`, `cancellation`,
122
+ `get_checkpoint`, `checkpoint`, `get_progress`, and `set_progress`. The batch-wide `tasks` and
123
+ shared `cancellation` are gone. Each write is fenced on its member's lease, and a member's
124
+ checkpoint replays whatever batch a retry puts it in. A fast-tier member's `checkpoint` and
125
+ `set_progress` raise `FastTierUnsupportedError` before any durable write.
126
+ - Add `HandlerContext#get_checkpoint`.
127
+ - `HandlerContext#checkpoint`, `sleep`, and `sleep_until` refuse a name outside 1 to 200
128
+ characters with `ArgumentError` before the block runs or any statement. `get_progress` keeps the
129
+ highest progress revision PostgreSQL acknowledged when `set_progress` calls return out of order.
130
+ - The Active Job adapter's `enqueue_all` clears each job's `enqueue_error`, so a job reports only
131
+ the error of the current call.
132
+ - Add `run_worker_process`, which stops the worker on `TERM` or `INT` and exits at once on a second
133
+ signal, and `run_worker_processes`, which forks, supervises, and restarts worker processes.
134
+ - A `logger` that raises no longer reaches worker lifecycle code. An accepted heartbeat still
135
+ renews the lease, `Worker#stop` still wakes the dispatcher, and a second signal still exits the
136
+ process. The first failure of each logger is written to standard error.
137
+ - Add the Active Job adapter, selected with `config.active_job.queue_adapter =
138
+ :stablemates_workhorse`. It requires Active Job 8.0 or later. A default job runs under the
139
+ `active_job` task type. A typed job declares its task type with `workhorse_options` and carries
140
+ one JSON `Hash`, so another SDK can enqueue or run it. `Stablemates::Workhorse::ActiveJob.handle`
141
+ registers both formats on a `Worker`.
142
+ - Workers built on one pool share one notification listener connection, as they share the
143
+ heartbeat connection. Each worker is woken only for its own queues, and the listener stops when
144
+ the last worker on the pool stops.
145
+ - `EnqueueResult#reason` says why a debounced enqueue was `:non_replaceable`:
146
+ `:incompatible_key_mode`, `:not_pending`, or `:window_elapsed_pending`. It is `nil` for every other
147
+ outcome.
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but not
32
+ limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Stablemates
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/NOTICE ADDED
@@ -0,0 +1,6 @@
1
+ Workhorse
2
+ Copyright 2026 Stablemates
3
+
4
+ This product includes software developed by Stablemates.
5
+ The corresponding source is licensed under the Apache License, Version 2.0.
6
+ See the LICENSE file in the repository root.
data/README.md CHANGED
@@ -1 +1,104 @@
1
- Name reservation. Use stablemates-workhorse 0.6.0 or later.
1
+ # Workhorse for Ruby
2
+
3
+ The Ruby queue client, operator client, and worker runtime for the Workhorse durable task queue for
4
+ PostgreSQL.
5
+
6
+ > **Public beta:** Workhorse is usable for evaluation and early production adoption. A 0.x minor
7
+ > release may change behaviour, so read the
8
+ > [changelog](https://github.com/stablemates/workhorse/blob/main/ruby/CHANGELOG.md) before you
9
+ > upgrade. It will not ask you to recreate your database: migrations are ordered, and inside a major
10
+ > line a migration only adds, so a running deployment upgrades in place. The one exception is
11
+ > migration 0025: a database from before 0.5.0 crosses it offline, with the
12
+ > [0.5.0 upgrade steps](https://github.com/stablemates/workhorse/blob/main/CHANGELOG.md#050--2026-09-28).
13
+ > The upgrade from 0.5 to 0.6 only adds.
14
+
15
+ An AI agent should read [the Workhorse documentation index](https://workhorse.run/llms.txt) first.
16
+
17
+ ## Install
18
+
19
+ Add the gem and the connection pool it runs on:
20
+
21
+ ```bash
22
+ bundle add stablemates-workhorse
23
+ bundle add connection_pool
24
+ ```
25
+
26
+ Install the schema once, as a deployment step. The application never installs or migrates it.
27
+
28
+ ```bash
29
+ npx --package @stablemates/workhorse@0.6.0 workhorse schema install
30
+ ```
31
+
32
+ The machine that runs that deployment step needs Node.js 22 or newer. The application itself needs
33
+ no Node.js.
34
+
35
+ Pin that version to the gem version the application depends on. The two come from one commit of
36
+ this repository, so the numbers match. A schema tool older than the application leaves a schema the
37
+ application refuses to start against.
38
+
39
+ Runtime processes verify compatibility instead of changing the schema. Call
40
+ `Queue#assert_compatible` or `Admin#assert_compatible` at startup. A refusal is
41
+ `Stablemates::Workhorse::CompatibilityError`, whose `code` names the reason.
42
+
43
+ Requires Ruby 3.3 or newer and PostgreSQL 15 through 18.
44
+
45
+ ## Run one task
46
+
47
+ ```ruby
48
+ require "connection_pool"
49
+ require "pg"
50
+ require "stablemates/workhorse"
51
+
52
+ url = ENV.fetch("DATABASE_URL")
53
+ pool = ConnectionPool.new(size: 4) { PG.connect(url) }
54
+
55
+ queue = Stablemates::Workhorse::Queue.new(pool)
56
+ enqueued = queue.enqueue("email.welcome", {"to" => "ada@example.com"})
57
+
58
+ worker = Stablemates::Workhorse::Worker.new(pool)
59
+ worker.handle("email.welcome") do |payload, _context|
60
+ {"deliveredTo" => payload["to"]}
61
+ end
62
+ worker.run_once # production uses Stablemates::Workhorse.run_worker_process(worker)
63
+
64
+ task = Stablemates::Workhorse::Admin.new(pool).get_task(enqueued.task_id)
65
+ puts "#{task.state} #{task.result}" if task
66
+ ```
67
+
68
+ Handlers receive at-least-once delivery. Use stable provider idempotency keys around external
69
+ effects. `ruby/examples/` also holds a transactional enqueue, a dedicated worker process, and an
70
+ orchestration of child tasks, signals, and human decisions. An integration spec runs every one of
71
+ them against PostgreSQL.
72
+
73
+ ## Package boundary
74
+
75
+ The gem is `stablemates-workhorse`, and its namespace is `Stablemates::Workhorse`.
76
+
77
+ - `Queue` enqueues, cancels, signals, and synchronizes schedules, policies, budgets, and contracts.
78
+ `Queue.new` accepts a `PG::Connection`, a `ConnectionPool`, or an open `pg` transaction.
79
+ `ActiveRecordExecutor` joins the caller's Active Record transaction instead. Either way, the
80
+ enqueue becomes part of your commit. When a statement finds its pooled connection unusable, the
81
+ SDK discards that connection through the pool's `discard_current_connection`. The SDK never
82
+ closes a connection the caller owns. A source without `discard_current_connection` must replace
83
+ an unusable connection itself.
84
+ Each enqueue returns an `EnqueueResult` with the task ID and an `outcome`. A debounced request
85
+ that was `:non_replaceable` also carries a `reason`: `:incompatible_key_mode`, `:not_pending`, or
86
+ `:window_elapsed_pending`.
87
+ - `Worker` takes a pool, registers handlers by task type, and runs them under a lease with a shared
88
+ heartbeat connection. `run_worker_process` drains it on `TERM` or `INT`.
89
+ - `HandlerContext` offers checkpoints, durable sleeps, signal and human waits, child tasks, and
90
+ progress. PostgreSQL owns every durable decision, and an unresolved wait suspends the task.
91
+ - `Admin` lists, inspects, and repairs tasks, dead letters, waits, workers, and queues.
92
+ - `Dashboard` is a Rack application that Rails routes or any Rack builder mounts under its own path.
93
+ - The [Active Job adapter](https://workhorse.run/docs/active-job) runs Rails jobs on Workhorse.
94
+ - When the application loads `opentelemetry-api`, the gem adds spans and trace propagation. Loading
95
+ `opentelemetry-metrics-api` as well adds metrics.
96
+
97
+ The gem never installs or migrates the shared PostgreSQL schema.
98
+
99
+ ## Next
100
+
101
+ - Follow the [quickstart](https://workhorse.run/docs/quickstart) and deploy
102
+ [worker processes](https://workhorse.run/docs/worker-processes).
103
+ - Move Rails jobs over with the [Active Job adapter](https://workhorse.run/docs/active-job).
104
+ - Read the [compatibility policy](https://workhorse.run/docs/compatibility).