solid_objects 0.14.1 → 0.14.2
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 +4 -4
- data/CHANGELOG.md +30 -0
- data/README.md +349 -1132
- data/docs/architecture.md +40 -1
- data/docs/operations.md +146 -20
- data/docs/reminders.md +112 -0
- data/lib/solid_objects/version.rb +1 -1
- metadata +3 -2
data/docs/architecture.md
CHANGED
|
@@ -435,6 +435,45 @@ send_to(InventoryActor.ref("sku-123")).reserve(order_id: id, quantity: 2)
|
|
|
435
435
|
|
|
436
436
|
The source actor commit never waits for the target. The outbox worker allocates the target's sequence after source commit. There is no global order across actors.
|
|
437
437
|
|
|
438
|
+
## Registering effect and commit-action handlers
|
|
439
|
+
|
|
440
|
+
Register an effect handler during application boot. The stable effect ID is the
|
|
441
|
+
idempotency key for the provider call:
|
|
442
|
+
|
|
443
|
+
```ruby
|
|
444
|
+
SolidObjects.register_effect(:charge_payment) do |arguments, context|
|
|
445
|
+
Payments.charge(
|
|
446
|
+
idempotency_key: context.id,
|
|
447
|
+
payment_id: arguments.fetch("payment_id"),
|
|
448
|
+
amount_cents: arguments.fetch("amount_cents")
|
|
449
|
+
)
|
|
450
|
+
end
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
A success callback receives `effect_id:`, the originally staged `arguments:`,
|
|
454
|
+
and `result:`. A failure callback receives `effect_id:`, `arguments:`, and
|
|
455
|
+
`error:`, so an actor can correlate concurrent effects without storing a
|
|
456
|
+
separate callback ledger.
|
|
457
|
+
|
|
458
|
+
A commit action is registered the same way and runs inside the short fenced
|
|
459
|
+
transaction:
|
|
460
|
+
|
|
461
|
+
```ruby
|
|
462
|
+
SolidObjects.register_commit_action(:complete_attempt) do |arguments, context|
|
|
463
|
+
AssessmentAttempt.find(arguments.fetch("attempt_id")).update!(
|
|
464
|
+
score: arguments.fetch("score"),
|
|
465
|
+
actor_message_id: context.message_id
|
|
466
|
+
)
|
|
467
|
+
end
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
Commit actions require Solid Objects and `ActiveRecord::Base` to share one
|
|
471
|
+
connection pool, and may be invoked again after a database rollback, so keep
|
|
472
|
+
them deterministic, bounded, and database-only. When Solid Objects uses a
|
|
473
|
+
separate actor database, use `emit` and an idempotent effect consumer instead;
|
|
474
|
+
two databases cannot share one transaction.
|
|
475
|
+
|
|
476
|
+
|
|
438
477
|
## Reminders
|
|
439
478
|
|
|
440
479
|
A reminder record contains actor identity, a reminder name, target message, JSON arguments, next run time, optional interval, status, and occurrence counter.
|
|
@@ -443,7 +482,7 @@ A reminder record contains actor identity, a reminder name, target message, JSON
|
|
|
443
482
|
schedule(at: 30.minutes.from_now).expire
|
|
444
483
|
```
|
|
445
484
|
|
|
446
|
-
Reminders are keyed by `(actor, reminder name)`, enforced by a unique index on `(instance_id, name)`. `schedule` is therefore an upsert: scheduling a name that is already armed moves that alarm instead of adding another, which is what makes re-arming safe from a handler that may run more than once. An actor needing several pending items should arm one alarm for the earliest and drain everything due when it fires, rather than one alarm per item; the [reminders guide](
|
|
485
|
+
Reminders are keyed by `(actor, reminder name)`, enforced by a unique index on `(instance_id, name)`. `schedule` is therefore an upsert: scheduling a name that is already armed moves that alarm instead of adding another, which is what makes re-arming safe from a handler that may run more than once. An actor needing several pending items should arm one alarm for the earliest and drain everything due when it fires, rather than one alarm per item; the [reminders guide](reminders.md#one-alarm-for-a-whole-queue) shows that pattern. A move that changes `next_run_at` emits `solid_objects.reminder.replaced`, because the replacement is otherwise indistinguishable from a first schedule.
|
|
447
486
|
|
|
448
487
|
When due, the scheduler locks the source instance and creates a normal mailbox
|
|
449
488
|
row with an idempotency key derived from reminder ID and occurrence. The
|
data/docs/operations.md
CHANGED
|
@@ -23,6 +23,103 @@ process, its activations, and its claimed messages untouched, including when an
|
|
|
23
23
|
application call overlaps the probe. A database busy enough to block cleanup
|
|
24
24
|
reports a failed or warned check rather than raising out of the command.
|
|
25
25
|
|
|
26
|
+
## Installing and upgrading
|
|
27
|
+
|
|
28
|
+
Review [CHANGELOG.md](CHANGELOG.md) for compatibility and deployment-order
|
|
29
|
+
notes, then update the gem:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
bundle update solid_objects
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
If the `Gemfile` pins an exact version, update that constraint first and run
|
|
36
|
+
`bundle install`. Commit both `Gemfile.lock` and the copied Solid Objects
|
|
37
|
+
migrations.
|
|
38
|
+
|
|
39
|
+
Copy only migrations that the newer gem has added, migrate, and verify the
|
|
40
|
+
installation:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
bin/rails solid_objects:install:migrations
|
|
44
|
+
bin/rails db:migrate
|
|
45
|
+
bin/rails solid_objects:doctor
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The migration task skips engine migrations already present in the application
|
|
49
|
+
and gives new migrations host-specific timestamps. Inspect the resulting
|
|
50
|
+
`db/migrate/*.solid_objects.rb` files before applying them. Do not rerun
|
|
51
|
+
`generate solid_objects:install` during an upgrade because that also attempts
|
|
52
|
+
to regenerate the application initializer.
|
|
53
|
+
|
|
54
|
+
When Solid Objects uses a separate database configuration named `actors`, copy
|
|
55
|
+
and run migrations through that database's configured migration path:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
DATABASE=actors bin/rails solid_objects:install:migrations
|
|
59
|
+
bin/rails db:migrate:actors
|
|
60
|
+
bin/rails solid_objects:doctor
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
For production, back up the actor database and run new migrations before
|
|
64
|
+
starting application or Solid Objects worker processes that require the new
|
|
65
|
+
schema. Restart the web and Solid Objects worker fleet after the bundle and
|
|
66
|
+
schema are current. For releases that change actor state versions, also follow
|
|
67
|
+
the [state migration and rolling-deployment guide](docs/state-migrations.md);
|
|
68
|
+
Rails schema migrations and actor state migrations are separate concerns.
|
|
69
|
+
|
|
70
|
+
### Host application tooling
|
|
71
|
+
|
|
72
|
+
Installed engine migrations are copied as
|
|
73
|
+
`db/migrate/*_create_solid_objects_tables.solid_objects.rb`. If the host enables
|
|
74
|
+
`Rails/CreateTableWithTimestamps`, exclude engine-owned migrations rather than
|
|
75
|
+
editing their intentionally specialized hot tables:
|
|
76
|
+
|
|
77
|
+
```yaml
|
|
78
|
+
Rails/CreateTableWithTimestamps:
|
|
79
|
+
Exclude:
|
|
80
|
+
- "db/migrate/*.solid_objects.rb"
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Solid Objects ships inline RBS signatures, not RBI files. Sorbet applications
|
|
84
|
+
can generate the gem RBI with:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
bundle exec tapioca gem solid_objects
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Running an extension in the same process
|
|
91
|
+
|
|
92
|
+
An extension gem can register its own long-running component, and
|
|
93
|
+
`solid_objects start` runs it beside the built-in roles. The component joins the
|
|
94
|
+
same supervision, the same replacement after a crash, and the same shutdown
|
|
95
|
+
timeout, so an operator deploys and monitors one process instead of two:
|
|
96
|
+
|
|
97
|
+
```ruby
|
|
98
|
+
SolidObjects.configure do |configuration|
|
|
99
|
+
configuration.register_component { MyExtension::FlushEngine.new }
|
|
100
|
+
end
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Pass `count:` for more than one instance. The block runs once for each instance,
|
|
104
|
+
and again when the supervisor replaces a crashed one, so no two components share
|
|
105
|
+
an object.
|
|
106
|
+
|
|
107
|
+
A registered component answers four methods, the contract the built-in roles
|
|
108
|
+
already keep:
|
|
109
|
+
|
|
110
|
+
| Method | Purpose |
|
|
111
|
+
| --- | --- |
|
|
112
|
+
| `run` | Runs the loop. The supervisor calls it in its own thread |
|
|
113
|
+
| `request_shutdown` | Asks the loop to finish. It must make `run` return |
|
|
114
|
+
| `stopped?` | Reports whether the component already finished |
|
|
115
|
+
| `stop` | Forces cleanup when the shutdown timeout expires first |
|
|
116
|
+
|
|
117
|
+
The supervisor checks that contract when it builds the component, and a missing
|
|
118
|
+
method raises `ArgumentError` as the supervisor starts, rather than hanging a
|
|
119
|
+
shutdown later. Registration itself never calls the block, so a component is
|
|
120
|
+
free to need a database connection that the application does not have while it
|
|
121
|
+
boots.
|
|
122
|
+
|
|
26
123
|
## Runtime
|
|
27
124
|
|
|
28
125
|
Start all configured roles:
|
|
@@ -50,6 +147,16 @@ actors by name for Cable subscriptions and component renders. Loading them in
|
|
|
50
147
|
every process is what lets a freshly booted web process serve a live card for
|
|
51
148
|
an actor no request in that process has rendered yet.
|
|
52
149
|
|
|
150
|
+
Worker and outbox counts can be overridden on the command line:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
bundle exec solid_objects start \
|
|
154
|
+
--workers 4 \
|
|
155
|
+
--effect-workers 2 \
|
|
156
|
+
--broadcast-workers 2 \
|
|
157
|
+
--reminder-schedulers 1
|
|
158
|
+
```
|
|
159
|
+
|
|
53
160
|
Inspect process records and clean stale ownership:
|
|
54
161
|
|
|
55
162
|
```bash
|
|
@@ -70,26 +177,45 @@ bundle exec solid_objects retry_dead_letter 123
|
|
|
70
177
|
|
|
71
178
|
## Configuration
|
|
72
179
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
180
|
+
Configure Solid Objects in `config/initializers/solid_objects.rb`:
|
|
181
|
+
|
|
182
|
+
```ruby
|
|
183
|
+
SolidObjects.configure do |configuration|
|
|
184
|
+
configuration.worker_count = 4
|
|
185
|
+
configuration.lease_duration = 30.seconds
|
|
186
|
+
configuration.lease_renewal_interval = 10.seconds
|
|
187
|
+
configuration.max_messages_per_activation_pass = 50
|
|
188
|
+
configuration.max_activation_duration = 5.seconds
|
|
189
|
+
end
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
| Setting | Default |
|
|
193
|
+
| --- | ---: |
|
|
194
|
+
| `polling_interval` | 0.1 seconds |
|
|
195
|
+
| `idle_polling_interval` | 1 second |
|
|
196
|
+
| `sync_polling_interval` | 0.05 seconds |
|
|
197
|
+
| `lease_duration` | 30 seconds |
|
|
198
|
+
| `lease_renewal_interval` | 10 seconds |
|
|
199
|
+
| `idle_deactivation_timeout` | 30 seconds |
|
|
200
|
+
| `max_messages_per_activation_pass` | 50 |
|
|
201
|
+
| `max_activation_duration` | 5 seconds |
|
|
202
|
+
| `max_mailbox_length` | 10,000 |
|
|
203
|
+
| `max_attempts` | 5 |
|
|
204
|
+
| `process_heartbeat_interval` | 15 seconds |
|
|
205
|
+
| `process_alive_threshold` | 60 seconds |
|
|
206
|
+
| `message_retention` | 30 days |
|
|
207
|
+
| `message_retention_by_actor_type` | `{}` |
|
|
208
|
+
| `instance_retention_by_actor_type` | `{}`; instances never expire unless listed |
|
|
209
|
+
| `process_retention` | 7 days |
|
|
210
|
+
| `prune_batch_size` | 1,000 |
|
|
211
|
+
| `worker_count` | 1 |
|
|
212
|
+
| `effect_worker_count` | 1 |
|
|
213
|
+
| `broadcast_worker_count` | 1 |
|
|
214
|
+
| `reminder_scheduler_count` | 1 |
|
|
215
|
+
|
|
216
|
+
Payload, state, and result byte limits; retry delay; table prefix; logging;
|
|
217
|
+
wake-up; broadcast; database; and authorization adapters are also configurable.
|
|
218
|
+
Invalid lease intervals, component counts, and size limits fail fast at boot.
|
|
93
219
|
|
|
94
220
|
Keep lease duration comfortably above renewal interval and expected database
|
|
95
221
|
pause time. A handler can exceed the pass-duration budget because Ruby code is
|
data/docs/reminders.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Reminders
|
|
2
|
+
|
|
3
|
+
Reminders are Solid Objects' durable equivalent of the Durable Objects Alarms
|
|
4
|
+
API. One-shot and recurring alarms are actor-owned database records:
|
|
5
|
+
|
|
6
|
+
```ruby
|
|
7
|
+
def schedule_evaluation
|
|
8
|
+
schedule(
|
|
9
|
+
at: 1.hour.from_now,
|
|
10
|
+
every: 1.hour,
|
|
11
|
+
missed: :latest
|
|
12
|
+
).evaluate(account_id:)
|
|
13
|
+
end
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Use `missed: :latest` to coalesce missed occurrences or `missed: :all` to
|
|
17
|
+
enqueue each one.
|
|
18
|
+
|
|
19
|
+
## A reminder is one named alarm per actor
|
|
20
|
+
|
|
21
|
+
The uniqueness key is `(actor, reminder name)`. Scheduling a name that is
|
|
22
|
+
already armed **moves the existing alarm** rather than adding a second one. The
|
|
23
|
+
database enforces this with a unique index on `(instance_id, name)`.
|
|
24
|
+
|
|
25
|
+
This is the same model as Orleans reminders and Durable Objects alarms, and it
|
|
26
|
+
is what makes a reminder safe to re-arm from a handler that may run more than
|
|
27
|
+
once. Without a key the name is the operation, so this is a data-loss bug:
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
# Wrong. Every entry overwrites the previous entry's alarm.
|
|
31
|
+
def add(entry:)
|
|
32
|
+
self.entries = entries + [ entry ]
|
|
33
|
+
schedule(at: entry.fetch("wait_until")).deliver
|
|
34
|
+
end
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Two entries leave one reminder. The earlier wake-up never happens, nothing
|
|
38
|
+
raises, and nothing is logged except a `solid_objects.reminder.replaced` event.
|
|
39
|
+
|
|
40
|
+
## An alarm per item, with `key:`
|
|
41
|
+
|
|
42
|
+
Pass `key:` when an actor is waiting on several things at once. The key is your
|
|
43
|
+
own identifier for the item, and it names that item's alarm, so each item gets
|
|
44
|
+
one:
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
def add(entry:)
|
|
48
|
+
self.entries = entries + [ entry ]
|
|
49
|
+
schedule(at: entry.fetch("wait_until"), key: entry.fetch("id")).deliver
|
|
50
|
+
end
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Two entries now leave two reminders. Scheduling the same key again moves that
|
|
54
|
+
item's alarm and leaves the others alone, which is what makes a keyed reminder
|
|
55
|
+
as safe to re-arm as an unkeyed one. The operation still decides which handler
|
|
56
|
+
runs; the key only decides which alarm is which.
|
|
57
|
+
|
|
58
|
+
A key must be non-empty, and the name it becomes must fit the 191-character
|
|
59
|
+
column, which is checked on the composed name rather than the key alone so a
|
|
60
|
+
long operation and a short key are caught too.
|
|
61
|
+
|
|
62
|
+
The key is separated from the operation by a colon, so an operation may not hold
|
|
63
|
+
one. Otherwise an unkeyed `deliver:item` and a `deliver` keyed `item` would be
|
|
64
|
+
one name, and the second would silently take the first one's alarm. A key may
|
|
65
|
+
hold colons of its own, because the operation before the first one cannot.
|
|
66
|
+
|
|
67
|
+
## One alarm for a whole queue
|
|
68
|
+
|
|
69
|
+
A key per item is not always what you want. An actor that only ever needs to
|
|
70
|
+
know "what is next" can keep one alarm and let the handler drain everything now
|
|
71
|
+
due before arming the next:
|
|
72
|
+
|
|
73
|
+
```ruby
|
|
74
|
+
def add(entry:)
|
|
75
|
+
self.entries = (entries + [ entry ]).sort_by { |item| item.fetch("wait_until") }
|
|
76
|
+
arm_next
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def deliver
|
|
80
|
+
now = Time.current.to_i
|
|
81
|
+
due, pending = entries.partition { |item| item.fetch("wait_until") <= now }
|
|
82
|
+
due.each { |item| emit :send_push, **item.symbolize_keys }
|
|
83
|
+
self.entries = pending
|
|
84
|
+
arm_next
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
def arm_next
|
|
90
|
+
earliest = entries.first
|
|
91
|
+
return unless earliest
|
|
92
|
+
|
|
93
|
+
schedule(at: Time.at(earliest.fetch("wait_until"))).deliver
|
|
94
|
+
end
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
That costs one reminder row instead of one per item, and a coalesced occurrence
|
|
98
|
+
cannot strand an entry because the handler drains by time rather than by alarm.
|
|
99
|
+
Prefer it when the queue is large and the items are interchangeable; prefer
|
|
100
|
+
`key:` when an item needs its own alarm that can be moved on its own.
|
|
101
|
+
|
|
102
|
+
Solid Objects has no `unschedule`. A reminder stops when its handler does not
|
|
103
|
+
re-arm it, and destroying an actor removes its reminders.
|
|
104
|
+
|
|
105
|
+
Self-scheduling actors should also have a low-frequency application reconciler.
|
|
106
|
+
It may read `SolidObjects::Instance.states_for`, `.without_pending_work`, and
|
|
107
|
+
`.orphaned`, but every repair must go through `async`. Never bulk-update actor
|
|
108
|
+
state around the lease and fencing checks.
|
|
109
|
+
|
|
110
|
+
Suspended actors should be reported rather than silently resumed. Spread large
|
|
111
|
+
repair batches with `available_at:` so reconciliation cannot stampede one
|
|
112
|
+
mailbox or the worker fleet.
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: solid_objects
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.14.
|
|
4
|
+
version: 0.14.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lucas Carlson
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-08-
|
|
11
|
+
date: 2026-08-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actioncable
|
|
@@ -355,6 +355,7 @@ files:
|
|
|
355
355
|
- docs/migrating-existing-state.md
|
|
356
356
|
- docs/operations.md
|
|
357
357
|
- docs/realtime.md
|
|
358
|
+
- docs/reminders.md
|
|
358
359
|
- docs/research/solid_queue.md
|
|
359
360
|
- docs/roadmap.md
|
|
360
361
|
- docs/security.md
|