solid_objects 1.0.5 → 1.1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +73 -0
- data/db/migrate/20261130000000_add_solid_objects_reminder_run_history.rb +30 -0
- data/docs/architecture.md +2 -1
- data/docs/compare/good-job.md +11 -2
- data/docs/compare/solid-queue.md +13 -2
- data/docs/compare/temporal.md +441 -0
- data/docs/comparisons.md +2 -0
- data/docs/reminders.md +49 -3
- data/docs/virtual-actors.md +2 -2
- data/examples/compare/game_room/game_room.rb +51 -0
- data/lib/solid_objects/actor.rb +31 -13
- data/lib/solid_objects/doctor.rb +1 -1
- data/lib/solid_objects/executor.rb +4 -0
- data/lib/solid_objects/message_pruner.rb +25 -19
- data/lib/solid_objects/reminder_scheduler.rb +44 -3
- data/lib/solid_objects/version.rb +1 -1
- data/sig/generated/lib/solid_objects/actor.rbs +16 -7
- data/sig/generated/lib/solid_objects/message_pruner.rbs +9 -0
- data/sig/generated/lib/solid_objects/reminder_scheduler.rbs +24 -2
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d4c2d5ded9cb5fb992d0e7897fc48f3180cf2ac6ee3fe4fe7027de36d5979c7f
|
|
4
|
+
data.tar.gz: 261f9f94db83d5cbd69561a81284b53e9764e26eeb5b107bd47d379beebbafc6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8c98fd43013596c1547f250853629682a226df921e2385f84ad4f284c80e0b00e19986520aef90a804ac8994c302e6ce00fec0e2ef38469c8a3017356275004b
|
|
7
|
+
data.tar.gz: b55c442043e25269b449f712f187bef86ba4c2e39561d017a83254d8c0fc85ca4d559d95128c1bd42cdb95620370899a1dbbb49f639e100b28de7defb9d46ec0
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,78 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 1.1.0 - 2026-12-02
|
|
6
|
+
|
|
7
|
+
- Reminders (#110): `schedule` accepts `missed: :skip`, which drops missed
|
|
8
|
+
occurrences of a recurring reminder and waits for the next scheduled time.
|
|
9
|
+
An occurrence that is late but still before the next scheduled time runs.
|
|
10
|
+
Once a later scheduled time has passed, the scheduler enqueues nothing and
|
|
11
|
+
advances to the first scheduled time after now. `:latest` and `:all` are
|
|
12
|
+
unchanged.
|
|
13
|
+
- `ReminderStatus` reports `last_run_at`, the scheduler's now when it last
|
|
14
|
+
enqueued the reminder, and `error_class`, the error that paused it.
|
|
15
|
+
Scheduling a name that already exists keeps `last_run_at` and `occurrence`
|
|
16
|
+
and clears `error_class`.
|
|
17
|
+
- A reminder whose operation the actor no longer declares is paused when it
|
|
18
|
+
comes due, with `error_class` `"SolidObjects::UnknownMessage"`, instead of
|
|
19
|
+
staying scheduled. The scheduler no longer raises on it, and no longer
|
|
20
|
+
claims it again on every pass. Scheduling the same name again arms it.
|
|
21
|
+
- `docs/reminders.md` documents the three missed policies and when a reminder
|
|
22
|
+
fires.
|
|
23
|
+
- Add `db/migrate/20261130000000_add_solid_objects_reminder_run_history.rb`,
|
|
24
|
+
which adds `reminders.last_run_at` and `reminders.error_class` and allows
|
|
25
|
+
`skip` in the `missed_policy` check. An application installs it with
|
|
26
|
+
`bin/rails solid_objects:install:migrations` and runs it before it upgrades a
|
|
27
|
+
scheduler, because the scheduler writes `last_run_at` on every enqueue. The
|
|
28
|
+
doctor now reports the columns as missing when they are not installed.
|
|
29
|
+
- Make `SolidObjects::MessagePruner#prune` fast on large tables. The guards
|
|
30
|
+
that keep a message alive (ready, claimed, dead-lettered, retried, unfinished
|
|
31
|
+
effects and undelivered broadcasts) are now correlated `NOT EXISTS`
|
|
32
|
+
subqueries instead of `NOT IN` lists. The `status != 'completed'` and
|
|
33
|
+
`status != 'delivered'` lists could not use an index, so SQLite scanned the
|
|
34
|
+
whole effects and broadcasts tables for every batch. Each batch now also
|
|
35
|
+
resumes after the last id of the previous one, and pruning stops after a
|
|
36
|
+
short batch instead of running one more full query. The same messages are
|
|
37
|
+
pruned on every database. No migration is needed (#113).
|
|
38
|
+
|
|
39
|
+
- Update CI and the development and test dependencies. The gemspec and the
|
|
40
|
+
gem's runtime requirements are unchanged.
|
|
41
|
+
- #104: add weekly Dependabot updates for Bundler and GitHub Actions
|
|
42
|
+
(`.github/dependabot.yml`). Minor and patch updates are grouped, and
|
|
43
|
+
updates wait 10 days after a release.
|
|
44
|
+
- #105: add a `latest_rails` CI job that runs the tests and the
|
|
45
|
+
at-least-once demo against the newest Rails and Rack that the gemspec
|
|
46
|
+
allows, resolved fresh on every run (`gemfiles/latest_rails.gemfile`).
|
|
47
|
+
- #106: `ruby/setup-ruby` from 1.321.0 to 1.343.0, in the minor-and-patch
|
|
48
|
+
group.
|
|
49
|
+
- #107: `softprops/action-gh-release` from 2.6.2 to 3.0.4.
|
|
50
|
+
- #108: `actions/setup-node` from 4.4.0 to 7.1.0.
|
|
51
|
+
- #109: the minor-and-patch group, 15 updates to `Gemfile.lock`.
|
|
52
|
+
- #112: `brakeman` from 8.1.0 to 8.1.1, in the minor-and-patch group.
|
|
53
|
+
|
|
54
|
+
## 1.0.6 - 2026-11-08
|
|
55
|
+
|
|
56
|
+
- Add `docs/compare/temporal.md`, a comparison with the Temporal Ruby SDK.
|
|
57
|
+
The first paragraph states that the SDK is generally available, with the
|
|
58
|
+
source and the date that it was checked. The page compares an ordered
|
|
59
|
+
billing sync for each customer and game rooms with turn timers, and says
|
|
60
|
+
when Temporal is the better choice. The new `GameRoom` actor is in
|
|
61
|
+
`examples/compare/game_room/` and runs in the test suite.
|
|
62
|
+
`docs/comparisons.md` lists the page.
|
|
63
|
+
- The Solid Queue page now answers whether Solid Queue releases blocked jobs
|
|
64
|
+
in order. The GoodJob page now answers whether its concurrency controls keep
|
|
65
|
+
first-in-first-out (FIFO) order. Each answer quotes the README and gives the
|
|
66
|
+
date that it was checked. A replay on October 18, 2026 of the searches that
|
|
67
|
+
coding agents made found no Solid Objects page for these questions.
|
|
68
|
+
- The short answer in `docs/virtual-actors.md` no longer states that version
|
|
69
|
+
1.0 makes no claim of measured scale. It links `docs/versioning.md`, the one
|
|
70
|
+
page that states the limits of version 1.0. Version 1.0.5 missed this
|
|
71
|
+
sentence.
|
|
72
|
+
|
|
73
|
+
- Make the effect-heartbeat recovery tests independent of database write
|
|
74
|
+
speed, including coverage of slow heartbeat writes.
|
|
75
|
+
|
|
3
76
|
## 1.0.5 - 2026-10-18
|
|
4
77
|
|
|
5
78
|
- `docs/versioning.md` is now the only page that states that version 1.0
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# rbs_inline: enabled
|
|
2
|
+
|
|
3
|
+
class AddSolidObjectsReminderRunHistory < ActiveRecord::Migration[7.1]
|
|
4
|
+
# @rbs () -> void
|
|
5
|
+
def up
|
|
6
|
+
add_column reminders_table, :last_run_at, :datetime, precision: 6
|
|
7
|
+
add_column reminders_table, :error_class, :string, limit: 191
|
|
8
|
+
remove_check_constraint reminders_table, name: "chk_so_reminders_missed"
|
|
9
|
+
add_check_constraint reminders_table,
|
|
10
|
+
"missed_policy IN ('latest', 'all', 'skip')",
|
|
11
|
+
name: "chk_so_reminders_missed"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# @rbs () -> void
|
|
15
|
+
def down
|
|
16
|
+
remove_check_constraint reminders_table, name: "chk_so_reminders_missed"
|
|
17
|
+
add_check_constraint reminders_table,
|
|
18
|
+
"missed_policy IN ('latest', 'all')",
|
|
19
|
+
name: "chk_so_reminders_missed"
|
|
20
|
+
remove_column reminders_table, :error_class
|
|
21
|
+
remove_column reminders_table, :last_run_at
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
# @rbs () -> String
|
|
27
|
+
def reminders_table
|
|
28
|
+
SolidObjects.table_name(:reminders)
|
|
29
|
+
end
|
|
30
|
+
end
|
data/docs/architecture.md
CHANGED
|
@@ -611,10 +611,11 @@ row with an idempotency key derived from reminder ID and occurrence. The
|
|
|
611
611
|
mailbox insert and reminder advancement commit atomically. The mailbox provides
|
|
612
612
|
sequential processing and ordinary retry behavior.
|
|
613
613
|
|
|
614
|
-
Solid Objects persists each occurrence by its mailbox row. Unlike Orleans reminders, an outage does not intentionally discard a due occurrence
|
|
614
|
+
Solid Objects persists each occurrence by its mailbox row. Unlike Orleans reminders, an outage does not intentionally discard a due occurrence unless the reminder opts into `:skip`. Recurring catch-up is configurable:
|
|
615
615
|
|
|
616
616
|
- `:latest` enqueues the current occurrence and advances beyond the current time.
|
|
617
617
|
- `:all` enqueues one occurrence per scheduler pass and advances one interval, allowing bounded catch-up through ordinary scheduler work.
|
|
618
|
+
- `:skip` enqueues an occurrence only while no later aligned time has passed. Otherwise it enqueues nothing and advances beyond the current time, dropping the missed occurrences.
|
|
618
619
|
|
|
619
620
|
### Schedule reconciliation
|
|
620
621
|
|
data/docs/compare/good-job.md
CHANGED
|
@@ -18,7 +18,16 @@ Solid Objects is an independent project. It is not affiliated with GoodJob or Ra
|
|
|
18
18
|
| Databases | PostgreSQL only | SQLite, PostgreSQL, MySQL |
|
|
19
19
|
| Licence | MIT | MIT |
|
|
20
20
|
|
|
21
|
-
The GoodJob facts come from the [GoodJob 4.22.1 README](https://github.com/bensheldon/good_job/blob/v4.22.1/README.md) (checked October
|
|
21
|
+
The GoodJob facts come from the [GoodJob 4.22.1 README](https://github.com/bensheldon/good_job/blob/v4.22.1/README.md) (checked October 18, 2026).
|
|
22
|
+
|
|
23
|
+
## Do GoodJob concurrency controls keep first-in-first-out (FIFO) order?
|
|
24
|
+
|
|
25
|
+
Not strictly. The GoodJob README says: "First-in-first-out job execution order is not strictly preserved: a waiting job that is re-scheduled can be overtaken by a newly enqueued job, and jobs retried with incremental back-off run in backoff order" ([GoodJob 4.22.1 README](https://github.com/bensheldon/good_job/blob/v4.22.1/README.md#how-concurrency-controls-work), checked October 18, 2026).
|
|
26
|
+
|
|
27
|
+
- `perform_limit` "counts running jobs". When a job exceeds it, the job raises `ConcurrencyExceededError`, and a `retry_on` handler "re-schedules the job to execute in the near future with an incremental backoff".
|
|
28
|
+
- After you migrate the `good_job_concurrency_claims` table, when a job that holds the key finishes, "the longest-waiting job is re-scheduled to run immediately rather than waiting for its backoff". The incremental backoff "remains as a fallback".
|
|
29
|
+
- Each rule applies to the jobs that carry its label. A `good_job_concurrency_rule` "with `key:` and no `label:`" is deprecated and "will raise in GoodJob v5".
|
|
30
|
+
- In Solid Objects, a second message for the same actor waits in the mailbox. Messages run in the order that the runtime stores them.
|
|
22
31
|
|
|
23
32
|
## Choose GoodJob when
|
|
24
33
|
|
|
@@ -227,7 +236,7 @@ GoodJob is older and has more users. If that matters more than order for each cu
|
|
|
227
236
|
|
|
228
237
|
## Sources
|
|
229
238
|
|
|
230
|
-
Checked October
|
|
239
|
+
Checked October 18, 2026:
|
|
231
240
|
|
|
232
241
|
- [GoodJob 4.22.1 README: concurrency controls](https://github.com/bensheldon/good_job/blob/v4.22.1/README.md#concurrency-controls)
|
|
233
242
|
- [GoodJob 4.22.1 README: how concurrency controls work](https://github.com/bensheldon/good_job/blob/v4.22.1/README.md#how-concurrency-controls-work)
|
data/docs/compare/solid-queue.md
CHANGED
|
@@ -17,7 +17,18 @@ Solid Objects is an independent project. It is not affiliated with Rails, 37sign
|
|
|
17
17
|
| Databases | MySQL, PostgreSQL, SQLite | SQLite, PostgreSQL, MySQL |
|
|
18
18
|
| Licence | MIT | MIT |
|
|
19
19
|
|
|
20
|
-
The Solid Queue facts come from the [Solid Queue 1.7.0 README](https://github.com/rails/solid_queue/blob/v1.7.0/README.md) (checked October
|
|
20
|
+
The Solid Queue facts come from the [Solid Queue 1.7.0 README](https://github.com/rails/solid_queue/blob/v1.7.0/README.md) (checked October 18, 2026).
|
|
21
|
+
|
|
22
|
+
## Does Solid Queue release blocked jobs in order?
|
|
23
|
+
|
|
24
|
+
Not with a guarantee. Solid Queue says that "Jobs are unblocked in order of priority" and that "there's no guarantee about _the order of execution_" ([Solid Queue 1.7.0 README](https://github.com/rails/solid_queue/blob/v1.7.0/README.md#concurrency-controls), checked October 18, 2026). With `limits_concurrency` and the default `on_conflict: :block`, jobs over the limit stay blocked "until another job finishes and unblocks them, or after the set expiry time (concurrency limit's _duration_) elapses".
|
|
25
|
+
|
|
26
|
+
- An unblocked job does not run at once. Solid Queue moves it "from _blocked_ to _ready_".
|
|
27
|
+
- In the 1.7.0 source code, Solid Queue releases blocked jobs by priority, then by job ID ([`execution.rb`](https://github.com/rails/solid_queue/blob/v1.7.0/app/models/solid_queue/execution.rb)).
|
|
28
|
+
- "Jobs that have been blocked for more than `duration` are candidates to be released, but only as many of them as the concurrency rules allow".
|
|
29
|
+
- A job that `retry_on` enqueues again waits like a new job. Retried jobs "get in the queue for getting an open semaphore". So the retry of an earlier job can run after a job that was enqueued later.
|
|
30
|
+
- With `on_conflict: :discard`, Solid Queue discards the job instead.
|
|
31
|
+
- In Solid Objects, a second message for the same actor waits in the mailbox. Messages run in the order that the runtime stores them.
|
|
21
32
|
|
|
22
33
|
## Choose Solid Queue when
|
|
23
34
|
|
|
@@ -222,7 +233,7 @@ Solid Queue is older and has more users. If that matters more than order for eac
|
|
|
222
233
|
|
|
223
234
|
## Sources
|
|
224
235
|
|
|
225
|
-
Checked October
|
|
236
|
+
Checked October 18, 2026:
|
|
226
237
|
|
|
227
238
|
- [Solid Queue 1.7.0 README: concurrency controls](https://github.com/rails/solid_queue/blob/v1.7.0/README.md#concurrency-controls)
|
|
228
239
|
- [Solid Queue 1.7.0 README: jobs interrupted by non-graceful process death](https://github.com/rails/solid_queue/blob/v1.7.0/README.md#jobs-interrupted-by-non-graceful-process-death)
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
# Temporal Ruby SDK and Solid Objects: general availability, ordered work, and timers in Rails
|
|
2
|
+
|
|
3
|
+
Yes, the Temporal Ruby SDK (the `temporalio` gem) is generally available. Temporal announced general availability on October 1, 2025, after a public preview that started on May 1, 2025 ([Temporal changelog](https://temporal.io/changelog/ruby-sdk-generally-available), checked October 18, 2026). The SDK runs workflows and activities in your Ruby worker processes, and a Temporal Service keeps the event history of each workflow. Solid Objects (the `solid_objects` gem) gives each key an actor with an ordered mailbox, durable state, and reminders, in the SQL database that the Rails app already uses. Choose Temporal for long workflows of many steps that must resume after a failure. Choose Solid Objects when one key, such as a customer or a game room, has state that each update reads and changes in order.
|
|
4
|
+
|
|
5
|
+
Solid Objects is an independent project. It is not affiliated with Temporal Technologies or Rails.
|
|
6
|
+
|
|
7
|
+
## The short answer
|
|
8
|
+
|
|
9
|
+
| Question | Temporal Ruby SDK | Solid Objects |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| Status | Generally available since October 1, 2025. The 1.0.0 release says "the Ruby SDK is now considered stable" | Stable public API since October 13, 2026, under semantic versioning |
|
|
12
|
+
| What has state | A workflow execution with a workflow ID | An actor class and an actor ID |
|
|
13
|
+
| One at a time for each key | "only one Workflow Execution with a given Workflow Id can be in an Open state at any given time" | One turn at a time for each actor |
|
|
14
|
+
| Order of messages | Temporal processes messages "in the order they were received". Handlers that wait "can run interleaved with the main Workflow and with one another" | Messages run in the order that the runtime stores them, one turn at a time |
|
|
15
|
+
| Where the state lives | The event history in the Temporal Service. The service stores it in Cassandra, PostgreSQL, or MySQL. SQLite is "only for development and testing" | Tables in your SQLite, PostgreSQL, or MySQL database |
|
|
16
|
+
| Code rules | Workflow code must be deterministic. "Temporal Workflows by default disallow use of IO during the Workflow run" | Ordinary Ruby. External calls go in effects, outside the turn |
|
|
17
|
+
| Timers | `Temporalio::Workflow.sleep` and `Temporalio::Workflow.timeout`. "Timers are persisted" | Reminders with `schedule(at:, key:)`, stored as rows |
|
|
18
|
+
| Retries | Activities retry with exponential backoff. The default waits 1 second, doubles the wait up to 100 seconds, and has no limit on attempts | Effect retries (the global `max_attempts` and `retry_delay` settings), then `on_failure` and a reminder |
|
|
19
|
+
| History size | "limited to 51,200 Events or 50 MB". A long-lived workflow continues as new | No event history. Each turn saves the current state |
|
|
20
|
+
| What you run | A Temporal Service (the Temporal Server and a database) or Temporal Cloud, and your worker processes | Your Rails app and `bundle exec solid_objects start` |
|
|
21
|
+
| Ruby and platforms | Ruby 3.3, 3.4, and 4.0. Gems for Linux and macOS. "MinGW-based Windows is not currently supported" | Ruby 3.3 or newer and Rails 7.1 or newer |
|
|
22
|
+
| Licence | SDK: MIT. Temporal Server: MIT | MIT |
|
|
23
|
+
|
|
24
|
+
The Temporal facts come from the [Temporal documentation](https://docs.temporal.io/develop/ruby), the [Ruby SDK README](https://github.com/temporalio/sdk-ruby), and the [Temporal changelog](https://temporal.io/changelog/product-area/ruby-sdk) (checked October 18, 2026).
|
|
25
|
+
|
|
26
|
+
## Choose Temporal when
|
|
27
|
+
|
|
28
|
+
- The work is a long workflow of many steps, for example an order that waits days for a payment, a shipment, and a refund.
|
|
29
|
+
- You want the event history of each workflow, and you want to replay it.
|
|
30
|
+
- A step must wait for a person or a system for days, with durable timers and signals.
|
|
31
|
+
- You already run a Temporal Service, or you can use Temporal Cloud.
|
|
32
|
+
|
|
33
|
+
## Choose Solid Objects when
|
|
34
|
+
|
|
35
|
+
- The updates for one key must apply one at a time, in the order they arrived.
|
|
36
|
+
- Each key has state that the updates read and change, for example the last synced version or the current turn.
|
|
37
|
+
- You want that state in the SQL database that you already back up and query, not in a workflow history.
|
|
38
|
+
- You want a state change and its effects and reminders to commit in one SQL transaction.
|
|
39
|
+
- You do not want to run a Temporal Service.
|
|
40
|
+
|
|
41
|
+
## The same terms in each
|
|
42
|
+
|
|
43
|
+
| Temporal Ruby SDK | Solid Objects |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| Workflow ID | Actor ID |
|
|
46
|
+
| A class that extends `Temporalio::Workflow::Definition` | A class that extends `SolidObjects::Actor` |
|
|
47
|
+
| Signal (`workflow_signal`) | `ref(id).async.method(...)` |
|
|
48
|
+
| Update (`workflow_update`) with a validator | `ref(id).method(...)` and `reject` |
|
|
49
|
+
| Query (`workflow_query`) | `query` or `snapshot` |
|
|
50
|
+
| Activity | Effect (`emit` and `SolidObjects.register_effect`) |
|
|
51
|
+
| Activity retry policy | Effect retries (the global `max_attempts` and `retry_delay` settings) |
|
|
52
|
+
| `Temporalio::Workflow.sleep` or `Temporalio::Workflow.timeout` | `schedule(at:, key:)` and an operation |
|
|
53
|
+
| Signal-With-Start | The first message to an actor ID |
|
|
54
|
+
| Continue-As-New | No equivalent. An actor keeps only its current state |
|
|
55
|
+
|
|
56
|
+
## One billing sync for each customer
|
|
57
|
+
|
|
58
|
+
The task: a Rails 8 app on PostgreSQL syncs each customer's subscription with an external billing API. The updates for one customer must run one at a time and in the order they arrived. Different customers run in parallel. Each customer has state: the last synced version, a retry count, and the next retry time. A failed sync must retry with backoff and survive a restart.
|
|
59
|
+
|
|
60
|
+
### With the Temporal Ruby SDK
|
|
61
|
+
|
|
62
|
+
There is one `CustomerBillingWorkflow` for each customer. This code follows the Temporal Ruby documentation. On October 18, 2026, it ran with the `temporalio` gem in the Temporal time-skipping test environment: three updates reached the billing API in order, and a failed push ran again with the same key. The Continue-As-New branch did not run in that check. The Solid Objects test suite does not run it.
|
|
63
|
+
|
|
64
|
+
```ruby
|
|
65
|
+
require "temporalio/activity"
|
|
66
|
+
require "temporalio/retry_policy"
|
|
67
|
+
require "temporalio/workflow"
|
|
68
|
+
|
|
69
|
+
class PushSubscriptionActivity < Temporalio::Activity::Definition
|
|
70
|
+
def execute(update)
|
|
71
|
+
BillingApi.push_subscription(
|
|
72
|
+
idempotency_key: update.fetch("key"),
|
|
73
|
+
customer_id: update.fetch("customer_id"),
|
|
74
|
+
version: update.fetch("version"),
|
|
75
|
+
plan: update.fetch("plan")
|
|
76
|
+
)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
class CustomerBillingWorkflow < Temporalio::Workflow::Definition
|
|
81
|
+
PUSH_RETRY_POLICY = Temporalio::RetryPolicy.new(initial_interval: 120, backoff_coefficient: 2.0, max_interval: 3600)
|
|
82
|
+
|
|
83
|
+
workflow_query_attr_reader :last_synced_version
|
|
84
|
+
|
|
85
|
+
workflow_init
|
|
86
|
+
def initialize(state)
|
|
87
|
+
@last_synced_version = state.fetch("last_synced_version")
|
|
88
|
+
@pending = state.fetch("pending")
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def execute(_state)
|
|
92
|
+
loop do
|
|
93
|
+
Temporalio::Workflow.wait_condition { @pending.any? || Temporalio::Workflow.continue_as_new_suggested }
|
|
94
|
+
break if Temporalio::Workflow.continue_as_new_suggested
|
|
95
|
+
|
|
96
|
+
update = @pending.first
|
|
97
|
+
Temporalio::Workflow.execute_activity(
|
|
98
|
+
PushSubscriptionActivity, update,
|
|
99
|
+
start_to_close_timeout: 30, retry_policy: PUSH_RETRY_POLICY
|
|
100
|
+
)
|
|
101
|
+
@last_synced_version = update.fetch("version")
|
|
102
|
+
@pending.shift
|
|
103
|
+
end
|
|
104
|
+
Temporalio::Workflow.wait_condition { Temporalio::Workflow.all_handlers_finished? }
|
|
105
|
+
raise Temporalio::Workflow::ContinueAsNewError.new(
|
|
106
|
+
{ "last_synced_version" => @last_synced_version, "pending" => @pending }
|
|
107
|
+
)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
workflow_signal
|
|
111
|
+
def update_subscription(update)
|
|
112
|
+
newest_version = @pending.last&.fetch("version") || @last_synced_version
|
|
113
|
+
@pending << update if update.fetch("version") > newest_version
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The Rails app sends each update with Signal-With-Start. It starts the workflow if it does not run yet. `TEMPORAL_CLIENT` is a `Temporalio::Client` that an initializer connects:
|
|
119
|
+
|
|
120
|
+
```ruby
|
|
121
|
+
operation = Temporalio::Client::WithStartWorkflowOperation.new(
|
|
122
|
+
CustomerBillingWorkflow, { "last_synced_version" => 0, "pending" => [] },
|
|
123
|
+
id: "billing-#{customer.id}", task_queue: "billing"
|
|
124
|
+
)
|
|
125
|
+
TEMPORAL_CLIENT.signal_with_start_workflow(
|
|
126
|
+
CustomerBillingWorkflow.update_subscription,
|
|
127
|
+
{ "key" => "billing-#{customer.id}-v#{subscription.version}", "customer_id" => customer.id.to_s,
|
|
128
|
+
"version" => subscription.version, "plan" => subscription.plan },
|
|
129
|
+
start_workflow_operation: operation
|
|
130
|
+
)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
A worker process runs the workflow and the activity:
|
|
134
|
+
|
|
135
|
+
```ruby
|
|
136
|
+
Temporalio::Worker.new(
|
|
137
|
+
client: TEMPORAL_CLIENT, task_queue: "billing",
|
|
138
|
+
workflows: [CustomerBillingWorkflow], activities: [PushSubscriptionActivity]
|
|
139
|
+
).run(shutdown_signals: ["SIGINT"])
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
What this code gets from Temporal:
|
|
143
|
+
|
|
144
|
+
- One workflow runs for each customer, because the workflow ID holds the customer ID.
|
|
145
|
+
- The signal handler waits for nothing, so the updates go into `@pending` in the order that Temporal received them.
|
|
146
|
+
- The main loop pushes one update at a time. While the activity retries, newer updates wait, so the order holds.
|
|
147
|
+
- The retry policy waits 2 minutes, then 4, then 8, up to 60 minutes, with no limit on attempts.
|
|
148
|
+
|
|
149
|
+
What to know:
|
|
150
|
+
|
|
151
|
+
- Workflow code must be deterministic. It cannot read Active Record or call the billing API. The activity does that.
|
|
152
|
+
- The state (`@pending` and `@last_synced_version`) lives in the event history, not in your tables. The app reads `last_synced_version` with a query.
|
|
153
|
+
- Temporal counts the attempts of each activity. This workflow does not copy the retry count or the next retry time into its own state.
|
|
154
|
+
- Each signal and each activity adds events to the history. The history is "limited to 51,200 Events or 50 MB", so the workflow continues as new when Temporal suggests it. It carries the pending updates into the new run.
|
|
155
|
+
- Activities run at least once. The docs say that an activity "may be executed multiple times". The billing API must accept the idempotency key.
|
|
156
|
+
- You operate a Temporal Service, or you use Temporal Cloud, and you run a worker process beside the Rails app.
|
|
157
|
+
|
|
158
|
+
### With Solid Objects
|
|
159
|
+
|
|
160
|
+
There is one `CustomerBillingSync` actor for each customer ID.
|
|
161
|
+
|
|
162
|
+
```ruby
|
|
163
|
+
class CustomerBillingSync < SolidObjects::Actor
|
|
164
|
+
MAXIMUM_BACKOFF_MINUTES = 60
|
|
165
|
+
|
|
166
|
+
attribute :last_synced_version, default: 0
|
|
167
|
+
attribute :pending, default: -> { [] }
|
|
168
|
+
attribute :pushing, default: false
|
|
169
|
+
attribute :retry_count, default: 0
|
|
170
|
+
attribute :next_retry_at, default: nil
|
|
171
|
+
|
|
172
|
+
def update_subscription(version:, plan:)
|
|
173
|
+
return newest_version if version <= newest_version
|
|
174
|
+
|
|
175
|
+
self.pending = pending + [ { "version" => version, "plan" => plan, "key" => "billing-#{actor_id}-v#{version}" } ]
|
|
176
|
+
push_next unless pushing || next_retry_at
|
|
177
|
+
version
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def pushed(effect_id:, arguments:, result:)
|
|
181
|
+
self.pushing = false
|
|
182
|
+
self.last_synced_version = arguments.fetch("version")
|
|
183
|
+
self.pending = pending.drop(1)
|
|
184
|
+
self.retry_count = 0
|
|
185
|
+
self.next_retry_at = nil
|
|
186
|
+
push_next
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def push_failed(effect_id:, arguments:, error:)
|
|
190
|
+
self.pushing = false
|
|
191
|
+
self.retry_count += 1
|
|
192
|
+
retry_at = [ 2**retry_count, MAXIMUM_BACKOFF_MINUTES ].min.minutes.from_now
|
|
193
|
+
self.next_retry_at = retry_at.iso8601
|
|
194
|
+
schedule(at: retry_at, key: "retry").retry_push
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def retry_push
|
|
198
|
+
self.next_retry_at = nil
|
|
199
|
+
push_next unless pushing
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
private
|
|
203
|
+
|
|
204
|
+
def newest_version
|
|
205
|
+
pending.last&.fetch("version") || last_synced_version
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def push_next
|
|
209
|
+
update = pending.first
|
|
210
|
+
return unless update
|
|
211
|
+
|
|
212
|
+
self.pushing = true
|
|
213
|
+
emit :push_subscription,
|
|
214
|
+
idempotency_key: update.fetch("key"),
|
|
215
|
+
customer_id: actor_id,
|
|
216
|
+
version: update.fetch("version"),
|
|
217
|
+
plan: update.fetch("plan"),
|
|
218
|
+
on_success: :pushed,
|
|
219
|
+
on_failure: :push_failed
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
The initializer registers the effect that calls the billing API:
|
|
225
|
+
|
|
226
|
+
```ruby
|
|
227
|
+
SolidObjects.register_effect(:push_subscription) do |arguments, _context|
|
|
228
|
+
BillingApi.push_subscription(
|
|
229
|
+
idempotency_key: arguments.fetch("idempotency_key"),
|
|
230
|
+
customer_id: arguments.fetch("customer_id"),
|
|
231
|
+
version: arguments.fetch("version"),
|
|
232
|
+
plan: arguments.fetch("plan")
|
|
233
|
+
)
|
|
234
|
+
end
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
The app sends each update with `async`:
|
|
238
|
+
|
|
239
|
+
```ruby
|
|
240
|
+
CustomerBillingSync.ref(customer.id.to_s)
|
|
241
|
+
.async(idempotency_key: "subscription-#{subscription.id}-v#{subscription.version}", authorization_context: Current.user)
|
|
242
|
+
.update_subscription(version: subscription.version, plan: subscription.plan)
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
The generated policies deny every call. Allow this call in your `authorize_message` policy. See [authorization policies](../authorization.md).
|
|
246
|
+
|
|
247
|
+
How it works:
|
|
248
|
+
|
|
249
|
+
- The runtime stores each message in SQL before `async` returns. Messages for one customer run one at a time, in the order that the runtime stores them.
|
|
250
|
+
- `update_subscription` appends the update to `pending`. It ignores a version that is not newer than the newest one it knows, so a repeated delivery changes nothing.
|
|
251
|
+
- `push_next` stages one effect for the oldest pending update. `pushing` stays true until that effect succeeds or fails. So the billing API gets the versions in order, one at a time.
|
|
252
|
+
- Each pending update carries its own idempotency key. So a billing API that accepts the key applies an update once, even when a crash runs the effect again.
|
|
253
|
+
- If every effect attempt fails, `push_failed` counts the failure, stores the next retry time, and schedules `retry_push` with backoff: 2, 4, 8 minutes, up to 60 minutes. The update keeps its place.
|
|
254
|
+
- The state is in actor attributes, and the reminder is a row in the database. Both survive a deploy or a restart.
|
|
255
|
+
|
|
256
|
+
### What the tests prove
|
|
257
|
+
|
|
258
|
+
[The tests](../../test/compare/customer_billing_sync_test.rb) show these results:
|
|
259
|
+
|
|
260
|
+
- Three updates for one customer reach the billing API one at a time, as versions 1, 2, and 3.
|
|
261
|
+
- Two customers each have a staged push at the same time. One customer does not wait for the other.
|
|
262
|
+
- A push that runs again after a lost response, or after the backoff, uses the same idempotency key, and the billing API applies it once.
|
|
263
|
+
- A newer update that arrives during the backoff waits for the retry.
|
|
264
|
+
- After the test resets the caller process and runs the reminders that are due 3 minutes later, the reminder runs and the push succeeds.
|
|
265
|
+
|
|
266
|
+
## Game rooms with turn timers in each
|
|
267
|
+
|
|
268
|
+
The task: turn-based game rooms in a Rails 8 app on PostgreSQL. Players send moves over Action Cable, and the app runs on several servers. The moves for one room must apply strictly in order. The room state must survive deploys. Each turn has a 60-second timer that must fire even if the server that started it restarts.
|
|
269
|
+
|
|
270
|
+
### With the Temporal Ruby SDK
|
|
271
|
+
|
|
272
|
+
There is one `GameRoomWorkflow` for each room. This code also ran in the Temporal time-skipping test environment on October 18, 2026. A move out of turn was rejected, and the timer skipped a turn after 60 seconds. The Continue-As-New branch did not run in that check.
|
|
273
|
+
|
|
274
|
+
```ruby
|
|
275
|
+
require "temporalio/workflow"
|
|
276
|
+
|
|
277
|
+
class GameRoomWorkflow < Temporalio::Workflow::Definition
|
|
278
|
+
TURN_SECONDS = 60
|
|
279
|
+
|
|
280
|
+
workflow_query_attr_reader :turn_number, :skipped_turns
|
|
281
|
+
|
|
282
|
+
workflow_init
|
|
283
|
+
def initialize(state)
|
|
284
|
+
@players = state.fetch("players")
|
|
285
|
+
@turn_number = state.fetch("turn_number")
|
|
286
|
+
@moves = state.fetch("moves")
|
|
287
|
+
@skipped_turns = state.fetch("skipped_turns")
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
def execute(_state)
|
|
291
|
+
loop do
|
|
292
|
+
break if Temporalio::Workflow.continue_as_new_suggested
|
|
293
|
+
|
|
294
|
+
turn = @turn_number
|
|
295
|
+
Temporalio::Workflow.timeout(TURN_SECONDS) do
|
|
296
|
+
Temporalio::Workflow.wait_condition { @turn_number > turn }
|
|
297
|
+
end
|
|
298
|
+
rescue Timeout::Error
|
|
299
|
+
@skipped_turns << turn
|
|
300
|
+
@turn_number += 1
|
|
301
|
+
end
|
|
302
|
+
Temporalio::Workflow.wait_condition { Temporalio::Workflow.all_handlers_finished? }
|
|
303
|
+
raise Temporalio::Workflow::ContinueAsNewError.new(
|
|
304
|
+
{ "players" => @players, "turn_number" => @turn_number, "moves" => @moves, "skipped_turns" => @skipped_turns }
|
|
305
|
+
)
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
workflow_update_validator(:play)
|
|
309
|
+
def validate_play(move)
|
|
310
|
+
return if move.fetch("turn_number") == @turn_number && move.fetch("player_id") == current_player
|
|
311
|
+
|
|
312
|
+
raise Temporalio::Error::ApplicationError, "It is not your turn"
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
workflow_update
|
|
316
|
+
def play(move)
|
|
317
|
+
@moves << move
|
|
318
|
+
@turn_number += 1
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
private
|
|
322
|
+
|
|
323
|
+
def current_player
|
|
324
|
+
@players[@turn_number % @players.size]
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
- An update with a validator can reject a move, and the caller gets the error. A signal cannot do that. The server answers a signal "without waiting for the Workflow to process the Signal".
|
|
330
|
+
- The workflow continues as new when Temporal suggests it, and carries the room state into the new run. So a long game stays inside the history limit.
|
|
331
|
+
- `Temporalio::Workflow.timeout` starts a durable timer. "Timers are persisted", so the timer fires after a worker restart.
|
|
332
|
+
- The Action Cable channel calls `execute_update` on the workflow handle. The docs say that a client that sends an update "must wait until the Server delivers the Update to a Worker".
|
|
333
|
+
|
|
334
|
+
### With Solid Objects
|
|
335
|
+
|
|
336
|
+
There is one `GameRoom` actor for each room.
|
|
337
|
+
|
|
338
|
+
```ruby
|
|
339
|
+
class GameRoom < SolidObjects::Actor
|
|
340
|
+
TURN_DURATION = 60.seconds
|
|
341
|
+
|
|
342
|
+
attribute :players, default: -> { [] }
|
|
343
|
+
attribute :turn_number, default: 0
|
|
344
|
+
attribute :moves, default: -> { [] }
|
|
345
|
+
attribute :skipped_turns, default: -> { [] }
|
|
346
|
+
|
|
347
|
+
def start(players:)
|
|
348
|
+
return turn_number if self.players.any?
|
|
349
|
+
reject(:not_enough_players, "The game needs two players") if players.uniq.size < 2
|
|
350
|
+
|
|
351
|
+
self.players = players.uniq
|
|
352
|
+
start_turn_timer
|
|
353
|
+
turn_number
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
def play(player_id:, move:, turn_number:)
|
|
357
|
+
reject(:not_started, "The game has not started") if players.empty?
|
|
358
|
+
reject(:stale_turn, "That turn already ended") unless turn_number == self.turn_number
|
|
359
|
+
reject(:not_your_turn, "It is not your turn") unless player_id == current_player
|
|
360
|
+
|
|
361
|
+
self.moves = moves + [ { "player_id" => player_id, "move" => move, "turn_number" => turn_number } ]
|
|
362
|
+
next_turn
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
def turn_timeout(turn_number:)
|
|
366
|
+
return self.turn_number unless turn_number == self.turn_number
|
|
367
|
+
|
|
368
|
+
self.skipped_turns = skipped_turns + [ turn_number ]
|
|
369
|
+
next_turn
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
private
|
|
373
|
+
|
|
374
|
+
def current_player
|
|
375
|
+
players[turn_number % players.size]
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
def next_turn
|
|
379
|
+
self.turn_number += 1
|
|
380
|
+
start_turn_timer
|
|
381
|
+
turn_number
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
def start_turn_timer
|
|
385
|
+
schedule(at: TURN_DURATION.from_now).turn_timeout(turn_number:)
|
|
386
|
+
end
|
|
387
|
+
end
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
- `reject` returns an error to a direct call, for example `GameRoom.ref(room_id).play(player_id:, move:, turn_number:)` from the Action Cable channel. The rejected move changes nothing.
|
|
391
|
+
- With no key, `schedule(at:)` gives an actor one alarm for each operation. Each new turn moves the alarm, so one room has one timer.
|
|
392
|
+
- The reminder is a row in the database. Another process runs it after a restart.
|
|
393
|
+
|
|
394
|
+
[The tests](../../test/compare/game_room_test.rb) show that moves apply in the order they arrived, that a move out of turn or for an old turn is rejected, that a move moves the timer, that an old timeout behind a move does not skip the next turn, and that the timer skips the turn after a restart.
|
|
395
|
+
|
|
396
|
+
## Questions that teams ask
|
|
397
|
+
|
|
398
|
+
**Is the Temporal Ruby SDK generally available?** Yes. Temporal announced general availability on October 1, 2025. The GitHub release 1.0.0 says: "With this 1.0.0 release, the Ruby SDK is now considered stable." The README marks two sections as experimental: FIPS support and type signatures.
|
|
399
|
+
|
|
400
|
+
**Is Solid Objects mature enough?** Here are the facts:
|
|
401
|
+
|
|
402
|
+
- Version 1.0.0: October 13, 2026. The public API follows [semantic versioning](../versioning.md).
|
|
403
|
+
- [Maintenance and continuity](../maintenance.md) tells you who maintains the project and how a release is made.
|
|
404
|
+
- One first-party application with more than 100,000 users runs it in production. That is a count of users, not a measure of load.
|
|
405
|
+
- The [benchmarks](../benchmarks.md) are development measurements. [Versioning](../versioning.md) states what version 1.0 does not claim.
|
|
406
|
+
|
|
407
|
+
The Temporal Ruby SDK has been generally available since October 2025. If a longer history matters more than keeping the state in your own database, choose Temporal.
|
|
408
|
+
|
|
409
|
+
**Does it need another process?** Both do. Temporal needs a Temporal Service, or Temporal Cloud, and a worker process. Solid Objects needs `bundle exec solid_objects start`, which runs async messages, effects, and reminders. While that process is down, pending work stays in SQL.
|
|
410
|
+
|
|
411
|
+
**Is delivery exactly once?** Not for external calls, in either. Temporal runs workflow code "exactly once and to completion", but an activity "may be executed multiple times". In Solid Objects, a turn can run again after a crash, and effects run at least once. Give each external call a stable idempotency key. See [correctness and delivery semantics](../correctness.md).
|
|
412
|
+
|
|
413
|
+
**Can I use both?** Yes. Use Temporal for long workflows of many steps. Use Solid Objects for state for each key that many requests change in order. A Temporal activity can send a message to an actor.
|
|
414
|
+
|
|
415
|
+
## Sources
|
|
416
|
+
|
|
417
|
+
Checked October 18, 2026:
|
|
418
|
+
|
|
419
|
+
- [Temporal Ruby SDK general availability](https://temporal.io/changelog/ruby-sdk-generally-available)
|
|
420
|
+
- [Temporal Ruby SDK public preview](https://temporal.io/changelog/ruby-sdk-public-preview)
|
|
421
|
+
- [Ruby SDK release 1.0.0](https://github.com/temporalio/sdk-ruby/releases/tag/v1.0.0)
|
|
422
|
+
- [Ruby SDK README](https://github.com/temporalio/sdk-ruby)
|
|
423
|
+
- [Temporal Ruby workflow basics](https://docs.temporal.io/develop/ruby/workflows/basics)
|
|
424
|
+
- [Temporal Ruby message passing](https://docs.temporal.io/develop/ruby/workflows/message-passing)
|
|
425
|
+
- [Temporal Ruby timers](https://docs.temporal.io/develop/ruby/workflows/timers)
|
|
426
|
+
- [Temporal Ruby Continue-As-New](https://docs.temporal.io/develop/ruby/workflows/continue-as-new)
|
|
427
|
+
- [Temporal Ruby and Rails](https://docs.temporal.io/develop/ruby/integrations/rails-integration)
|
|
428
|
+
- [Temporal message handling](https://docs.temporal.io/handling-messages)
|
|
429
|
+
- [Temporal retry policies](https://docs.temporal.io/encyclopedia/retry-policies)
|
|
430
|
+
- [Temporal activity definition](https://docs.temporal.io/activity-definition)
|
|
431
|
+
- [Temporal workflow execution limits](https://docs.temporal.io/workflow-execution/limits)
|
|
432
|
+
- [Temporal workflow IDs](https://docs.temporal.io/workflow-execution/workflowid-runid)
|
|
433
|
+
- [Temporal Service persistence](https://docs.temporal.io/temporal-service/persistence)
|
|
434
|
+
- [What is Temporal?](https://docs.temporal.io/temporal)
|
|
435
|
+
|
|
436
|
+
## More information
|
|
437
|
+
|
|
438
|
+
- [All comparisons](../comparisons.md)
|
|
439
|
+
- [Solid Queue limits_concurrency and Solid Objects](solid-queue.md)
|
|
440
|
+
- [Run jobs in order for each customer in Rails](../guides/ordered-jobs.md)
|
|
441
|
+
- [Guide for coding agents](../agents.md)
|
data/docs/comparisons.md
CHANGED
|
@@ -6,12 +6,14 @@ Each page compares Solid Objects with one tool on one real task. Each page says
|
|
|
6
6
|
| --- | --- | --- |
|
|
7
7
|
| [Solid Queue limits_concurrency and Solid Objects](compare/solid-queue.md) | Solid Queue, the Rails 8 default job backend | Ordered billing sync for each customer |
|
|
8
8
|
| [GoodJob concurrency controls and Solid Objects](compare/good-job.md) | GoodJob, a PostgreSQL job backend | Ordered billing sync for each customer |
|
|
9
|
+
| [Temporal Ruby SDK and Solid Objects](compare/temporal.md) | Temporal, a durable workflow engine (the `temporalio` gem) | Ordered billing sync for each customer, and game rooms with turn timers |
|
|
9
10
|
|
|
10
11
|
## Choose the smallest tool that works
|
|
11
12
|
|
|
12
13
|
- The whole rule fits in one request: use a row lock (`with_lock`), a constraint, or a short transaction.
|
|
13
14
|
- Independent background work: use a job queue such as Solid Queue or GoodJob.
|
|
14
15
|
- One job at a time for each key, order not important: use the concurrency controls of your job queue.
|
|
16
|
+
- A long workflow of many steps, with an event history to replay: use a workflow engine such as Temporal.
|
|
15
17
|
- Order for each key, state for each key, reminders, and recovery after a restart: use an actor for each key.
|
|
16
18
|
|
|
17
19
|
The problem guides start from the same choices:
|
data/docs/reminders.md
CHANGED
|
@@ -13,8 +13,42 @@ def schedule_evaluation
|
|
|
13
13
|
end
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
A recurring reminder that comes due late, for example after an outage, uses
|
|
17
|
+
its `missed:` policy. The default is `:latest`. The policy can be a symbol or
|
|
18
|
+
a string.
|
|
19
|
+
|
|
20
|
+
- `missed: :latest` coalesces missed occurrences (the JS PRD's `run_once`). The
|
|
21
|
+
scheduler enqueues one occurrence and advances to the first scheduled time
|
|
22
|
+
after now.
|
|
23
|
+
- `missed: :all` enqueues each missed occurrence (the JS PRD's `catch_up`). The
|
|
24
|
+
scheduler advances one interval at a time, even into the past, so each
|
|
25
|
+
missed occurrence becomes its own message on a later scheduler pass.
|
|
26
|
+
- `missed: :skip` drops missed occurrences and waits for the next scheduled
|
|
27
|
+
time. An occurrence that is late but still before the next scheduled time
|
|
28
|
+
runs. Once a later scheduled time has also passed, the scheduler enqueues
|
|
29
|
+
nothing and advances to the first scheduled time after now.
|
|
30
|
+
|
|
31
|
+
A one-shot reminder has no next scheduled time, so it fires once when it is
|
|
32
|
+
due under every policy.
|
|
33
|
+
|
|
34
|
+
## When a reminder fires
|
|
35
|
+
|
|
36
|
+
`schedule(at:)` stores `at` as the reminder's `next_run_at`. The scheduler
|
|
37
|
+
treats a reminder as due when `next_run_at` is on or before now. Now is the
|
|
38
|
+
time passed to `run_due_reminders(now:)` in a test, and otherwise the database
|
|
39
|
+
clock, which the scheduler reads and converts to UTC. A due reminder becomes an
|
|
40
|
+
ordinary internal mailbox message, so retry and retention of a fired reminder
|
|
41
|
+
follow that message. Time zone and clock skew are not a documented guarantee.
|
|
42
|
+
|
|
43
|
+
A fired reminder is an internal message, so `authorize_message` is not called
|
|
44
|
+
for it. An external enqueue of the same operation still is.
|
|
45
|
+
|
|
46
|
+
If the actor no longer declares the reminder's operation when it comes due,
|
|
47
|
+
the scheduler enqueues nothing and pauses the reminder. Its status becomes
|
|
48
|
+
`"paused"` and its `error_class` is `"SolidObjects::UnknownMessage"`. A paused
|
|
49
|
+
reminder is not claimed again. Scheduling the same name again arms it. A
|
|
50
|
+
failure of an occurrence that was already enqueued does not pause the
|
|
51
|
+
reminder: retries and dead letters stay on that message.
|
|
18
52
|
|
|
19
53
|
## A schedule call needs an operation
|
|
20
54
|
|
|
@@ -157,7 +191,19 @@ of an actor removes its reminders.
|
|
|
157
191
|
|
|
158
192
|
`reminder` returns the status of one reminder, or `nil`. `reminders` lists
|
|
159
193
|
every key of one operation. Both include the changes that the current turn
|
|
160
|
-
staged.
|
|
194
|
+
staged. A status reports `next_run_at`, `interval_seconds`, `missed_policy`,
|
|
195
|
+
and `status`, and the run history of the reminder:
|
|
196
|
+
|
|
197
|
+
- `occurrence` counts the times the scheduler enqueued the reminder. It starts
|
|
198
|
+
at 0. A window that `:skip` drops and a retry of an enqueued message do not
|
|
199
|
+
count.
|
|
200
|
+
- `last_run_at` is the scheduler's now when it last enqueued the reminder, or
|
|
201
|
+
`nil` if it never has. It is not when the operation finished.
|
|
202
|
+
- `error_class` names the error that paused the reminder, or is `nil`.
|
|
203
|
+
|
|
204
|
+
Scheduling a name that already exists, including a one-shot that already
|
|
205
|
+
fired, keeps `occurrence` and `last_run_at`, clears `error_class`, and sets the
|
|
206
|
+
status to `"scheduled"`. The read in the same turn shows the same history.
|
|
161
207
|
|
|
162
208
|
Self-scheduling actors should also have a low-frequency application reconciler.
|
|
163
209
|
It may read `SolidObjects::Instance.states_for`, `.without_pending_work`, and
|
data/docs/virtual-actors.md
CHANGED
|
@@ -12,8 +12,8 @@ State and mailboxes live in the SQLite, PostgreSQL, or MySQL database that the
|
|
|
12
12
|
Rails application already uses. Redis and a separate actor service are not
|
|
13
13
|
necessary.
|
|
14
14
|
|
|
15
|
-
Solid Objects 1.0 promises a stable public API.
|
|
16
|
-
|
|
15
|
+
Solid Objects 1.0 promises a stable public API. [Versioning](versioning.md)
|
|
16
|
+
states the limits of that promise. Read
|
|
17
17
|
[Compatibility and maturity](#compatibility-and-maturity) before you choose it.
|
|
18
18
|
|
|
19
19
|
## What a virtual actor is
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# rbs_inline: enabled
|
|
2
|
+
|
|
3
|
+
class GameRoom < SolidObjects::Actor
|
|
4
|
+
TURN_DURATION = 60.seconds
|
|
5
|
+
|
|
6
|
+
attribute :players, default: -> { [] }
|
|
7
|
+
attribute :turn_number, default: 0
|
|
8
|
+
attribute :moves, default: -> { [] }
|
|
9
|
+
attribute :skipped_turns, default: -> { [] }
|
|
10
|
+
|
|
11
|
+
def start(players:)
|
|
12
|
+
return turn_number if self.players.any?
|
|
13
|
+
reject(:not_enough_players, "The game needs two players") if players.uniq.size < 2
|
|
14
|
+
|
|
15
|
+
self.players = players.uniq
|
|
16
|
+
start_turn_timer
|
|
17
|
+
turn_number
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def play(player_id:, move:, turn_number:)
|
|
21
|
+
reject(:not_started, "The game has not started") if players.empty?
|
|
22
|
+
reject(:stale_turn, "That turn already ended") unless turn_number == self.turn_number
|
|
23
|
+
reject(:not_your_turn, "It is not your turn") unless player_id == current_player
|
|
24
|
+
|
|
25
|
+
self.moves = moves + [ { "player_id" => player_id, "move" => move, "turn_number" => turn_number } ]
|
|
26
|
+
next_turn
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def turn_timeout(turn_number:)
|
|
30
|
+
return self.turn_number unless turn_number == self.turn_number
|
|
31
|
+
|
|
32
|
+
self.skipped_turns = skipped_turns + [ turn_number ]
|
|
33
|
+
next_turn
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def current_player
|
|
39
|
+
players[turn_number % players.size]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def next_turn
|
|
43
|
+
self.turn_number += 1
|
|
44
|
+
start_turn_timer
|
|
45
|
+
turn_number
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def start_turn_timer
|
|
49
|
+
schedule(at: TURN_DURATION.from_now).turn_timeout(turn_number:)
|
|
50
|
+
end
|
|
51
|
+
end
|
data/lib/solid_objects/actor.rb
CHANGED
|
@@ -17,7 +17,8 @@ module SolidObjects
|
|
|
17
17
|
UnscheduleIntent = Data.define(:name)
|
|
18
18
|
UnscheduleAllIntent = Data.define(:operation)
|
|
19
19
|
ReminderStatus = Data.define(:name, :operation, :key, :next_run_at, :interval_seconds,
|
|
20
|
-
:missed_policy, :occurrence, :status, :handle)
|
|
20
|
+
:missed_policy, :occurrence, :status, :handle, :last_run_at, :error_class)
|
|
21
|
+
MISSED_POLICIES = %w[latest all skip].freeze
|
|
21
22
|
OutboundMessageIntent = Data.define(:actor_type, :actor_id, :operation, :arguments, :available_at, :idempotency_key)
|
|
22
23
|
|
|
23
24
|
class << self
|
|
@@ -256,8 +257,8 @@ module SolidObjects
|
|
|
256
257
|
raise ArgumentError, "reminder interval must be positive"
|
|
257
258
|
end
|
|
258
259
|
missed_policy = missed.to_s
|
|
259
|
-
unless
|
|
260
|
-
raise ArgumentError, "missed reminder policy must be all or
|
|
260
|
+
unless MISSED_POLICIES.include?(missed_policy)
|
|
261
|
+
raise ArgumentError, "missed reminder policy must be latest, all, or skip"
|
|
261
262
|
end
|
|
262
263
|
reminder_key = validated_reminder_key(key)
|
|
263
264
|
call = ScheduleCall.new(at:, key: reminder_key)
|
|
@@ -338,19 +339,27 @@ module SolidObjects
|
|
|
338
339
|
end
|
|
339
340
|
|
|
340
341
|
# The view is the committed schedule with this turn's staged intents applied
|
|
341
|
-
# in order, so a read agrees with what the commit will leave behind.
|
|
342
|
+
# in order, so a read agrees with what the commit will leave behind. A
|
|
343
|
+
# completed one-shot is not reported, but one this turn schedules again is in
|
|
344
|
+
# the view until the intents are applied, because the commit reuses its row
|
|
345
|
+
# and keeps its run history.
|
|
342
346
|
# @rbs () -> Hash[String, ReminderStatus]
|
|
343
347
|
def reminder_view
|
|
344
|
-
reminder_intents.each_with_object(committed_reminders) do |intent,
|
|
345
|
-
apply_reminder_intent(
|
|
348
|
+
view = reminder_intents.each_with_object(committed_reminders) do |intent, staged|
|
|
349
|
+
apply_reminder_intent(staged, intent)
|
|
346
350
|
end
|
|
351
|
+
view.delete_if { |_name, status| status.status == "completed" }
|
|
347
352
|
end
|
|
348
353
|
|
|
349
354
|
# @rbs () -> Hash[String, ReminderStatus]
|
|
350
355
|
def committed_reminders
|
|
351
356
|
return {} unless instance_id
|
|
352
357
|
|
|
353
|
-
|
|
358
|
+
# Completed rows only matter for names this turn schedules again, and an
|
|
359
|
+
# actor that keys a one-shot per item accumulates them.
|
|
360
|
+
rearmed = reminder_intents.filter_map { |intent| intent.name if intent.is_a?(ReminderIntent) }
|
|
361
|
+
rows = Reminder.where(instance_id:)
|
|
362
|
+
rows.where.not(status: "completed").or(rows.where(name: rearmed)).each_with_object({}) do |row, view|
|
|
354
363
|
view[row.name] = reminder_status(
|
|
355
364
|
name: row.name,
|
|
356
365
|
operation: row.operation,
|
|
@@ -358,7 +367,9 @@ module SolidObjects
|
|
|
358
367
|
interval_seconds: row.interval_seconds,
|
|
359
368
|
missed_policy: row.missed_policy,
|
|
360
369
|
occurrence: row.occurrence,
|
|
361
|
-
status: row.status
|
|
370
|
+
status: row.status,
|
|
371
|
+
last_run_at: row.last_run_at,
|
|
372
|
+
error_class: row.error_class
|
|
362
373
|
)
|
|
363
374
|
end
|
|
364
375
|
end
|
|
@@ -368,19 +379,24 @@ module SolidObjects
|
|
|
368
379
|
return view.delete_if { |_name, status| status.operation == intent.operation } if intent.is_a?(UnscheduleAllIntent)
|
|
369
380
|
return view.delete(intent.name) if intent.is_a?(UnscheduleIntent)
|
|
370
381
|
|
|
382
|
+
# A replace moves the alarm but keeps its run history, and clears the
|
|
383
|
+
# error that paused it, as the commit will.
|
|
384
|
+
existing = view[intent.name]
|
|
371
385
|
view[intent.name] = reminder_status(
|
|
372
386
|
name: intent.name,
|
|
373
387
|
operation: intent.operation,
|
|
374
388
|
next_run_at: intent.at,
|
|
375
389
|
interval_seconds: intent.interval_seconds,
|
|
376
390
|
missed_policy: intent.missed_policy,
|
|
377
|
-
occurrence:
|
|
378
|
-
status: "scheduled"
|
|
391
|
+
occurrence: existing&.occurrence || 0,
|
|
392
|
+
status: "scheduled",
|
|
393
|
+
last_run_at: existing&.last_run_at,
|
|
394
|
+
error_class: nil
|
|
379
395
|
)
|
|
380
396
|
end
|
|
381
397
|
|
|
382
|
-
# @rbs (name: String, operation: String, next_run_at: Time?, interval_seconds: untyped, missed_policy: String, occurrence: Integer, status: String) -> ReminderStatus
|
|
383
|
-
def reminder_status(name:, operation:, next_run_at:, interval_seconds:, missed_policy:, occurrence:, status:)
|
|
398
|
+
# @rbs (name: String, operation: String, next_run_at: Time?, interval_seconds: untyped, missed_policy: String, occurrence: Integer, status: String, last_run_at: Time?, error_class: String?) -> ReminderStatus
|
|
399
|
+
def reminder_status(name:, operation:, next_run_at:, interval_seconds:, missed_policy:, occurrence:, status:, last_run_at:, error_class:)
|
|
384
400
|
ReminderStatus.new(
|
|
385
401
|
name:,
|
|
386
402
|
operation:,
|
|
@@ -390,7 +406,9 @@ module SolidObjects
|
|
|
390
406
|
missed_policy:,
|
|
391
407
|
occurrence:,
|
|
392
408
|
status:,
|
|
393
|
-
handle: { REMINDER_HANDLE_KEY => name }
|
|
409
|
+
handle: { REMINDER_HANDLE_KEY => name },
|
|
410
|
+
last_run_at:,
|
|
411
|
+
error_class:
|
|
394
412
|
)
|
|
395
413
|
end
|
|
396
414
|
|
data/lib/solid_objects/doctor.rb
CHANGED
|
@@ -76,7 +76,7 @@ module SolidObjects
|
|
|
76
76
|
id message_id instance_id process_id activation_token
|
|
77
77
|
activation_generation claimed_at
|
|
78
78
|
],
|
|
79
|
-
reminders: %w[id instance_id operation next_run_at status],
|
|
79
|
+
reminders: %w[id instance_id operation next_run_at status last_run_at error_class],
|
|
80
80
|
effects: %w[
|
|
81
81
|
id message_id instance_id effect_id status available_at
|
|
82
82
|
success_operation failure_operation
|
|
@@ -293,6 +293,9 @@ module SolidObjects
|
|
|
293
293
|
|
|
294
294
|
reminder = Reminder.find_or_initialize_by(instance:, name: intent.name)
|
|
295
295
|
previous_run_at = reminder.next_run_at
|
|
296
|
+
# A move keeps occurrence and last_run_at, which are the alarm's run
|
|
297
|
+
# history, and clears error_class, which explained a pause the move
|
|
298
|
+
# ends.
|
|
296
299
|
reminder.assign_attributes(
|
|
297
300
|
actor_type: instance.actor_type,
|
|
298
301
|
actor_id: instance.actor_id,
|
|
@@ -302,6 +305,7 @@ module SolidObjects
|
|
|
302
305
|
interval_seconds: intent.interval_seconds,
|
|
303
306
|
missed_policy: intent.missed_policy,
|
|
304
307
|
status: "scheduled",
|
|
308
|
+
error_class: nil,
|
|
305
309
|
claimed_by: nil,
|
|
306
310
|
claimed_at: nil
|
|
307
311
|
)
|
|
@@ -41,38 +41,44 @@ module SolidObjects
|
|
|
41
41
|
relations << default_relation
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
+
# Messages that no live row points at. Each guard is a correlated NOT EXISTS
|
|
45
|
+
# rather than NOT IN, so the database can answer it with an index probe on
|
|
46
|
+
# the referencing table, even for the `status !=` guards that NOT IN could
|
|
47
|
+
# only answer by scanning, and a NULL in the referencing column cannot make
|
|
48
|
+
# the predicate unknown.
|
|
49
|
+
#
|
|
44
50
|
# @rbs () -> ActiveRecord::Relation[Message]
|
|
45
51
|
def prunable
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
.where.not(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
id: Effect
|
|
57
|
-
.where.not(status: "completed")
|
|
58
|
-
.select(:message_id)
|
|
59
|
-
)
|
|
60
|
-
.where.not(
|
|
61
|
-
id: Broadcast
|
|
62
|
-
.where.not(status: "delivered")
|
|
63
|
-
.select(:message_id)
|
|
52
|
+
[
|
|
53
|
+
[ ReadyMessage.all, :message_id ],
|
|
54
|
+
[ ClaimedMessage.all, :message_id ],
|
|
55
|
+
[ DeadLetter.all, :message_id ],
|
|
56
|
+
[ DeadLetter.where.not(retried_message_id: nil), :retried_message_id ],
|
|
57
|
+
[ Effect.where.not(status: "completed"), :message_id ],
|
|
58
|
+
[ Broadcast.where.not(status: "delivered"), :message_id ]
|
|
59
|
+
].reduce(Message.all) do |messages, (references, column)|
|
|
60
|
+
messages.where.not(
|
|
61
|
+
references.where(references.arel_table[column].eq(Message.arel_table[:id])).select(1).arel.exists
|
|
64
62
|
)
|
|
63
|
+
end
|
|
65
64
|
end
|
|
66
65
|
|
|
66
|
+
# Pages by primary key so each batch resumes after the previous one instead
|
|
67
|
+
# of re-walking rows that are still protected. A short page is the last one.
|
|
68
|
+
#
|
|
67
69
|
# @rbs (ActiveRecord::Relation[Message]) -> Integer
|
|
68
70
|
def prune_relation(relation)
|
|
69
71
|
deleted = 0
|
|
72
|
+
last_id = 0
|
|
70
73
|
|
|
71
74
|
loop do
|
|
72
|
-
message_ids = relation.limit(batch_size).pluck(:id)
|
|
75
|
+
message_ids = relation.where(id: (last_id + 1)..).order(:id).limit(batch_size).pluck(:id)
|
|
73
76
|
break if message_ids.empty?
|
|
74
77
|
|
|
75
78
|
deleted += Message.where(id: message_ids).delete_all
|
|
79
|
+
break if message_ids.size < batch_size
|
|
80
|
+
|
|
81
|
+
last_id = message_ids.last
|
|
76
82
|
end
|
|
77
83
|
|
|
78
84
|
deleted
|
|
@@ -127,11 +127,14 @@ module SolidObjects
|
|
|
127
127
|
end
|
|
128
128
|
end
|
|
129
129
|
|
|
130
|
-
#
|
|
130
|
+
# Returns the enqueued message, :skipped when a skip reminder dropped a
|
|
131
|
+
# missed window, :paused when its operation is unknown, or nil when the
|
|
132
|
+
# reminder or its actor is gone. Anything but nil is scheduler work.
|
|
133
|
+
# @rbs (Reminder, now: Time?) -> (MessageReference | :skipped | :paused)?
|
|
131
134
|
def enqueue(reminder, now:)
|
|
132
135
|
actor_class = SolidObjects.registry.fetch(reminder.actor_type)
|
|
133
136
|
unless actor_class.definition.messages.key?(reminder.operation.to_sym)
|
|
134
|
-
|
|
137
|
+
return pause(reminder, UnknownMessage.new("unknown reminder operation #{reminder.operation.inspect}"))
|
|
135
138
|
end
|
|
136
139
|
|
|
137
140
|
mailbox = Mailbox.new(database_adapter:)
|
|
@@ -143,6 +146,8 @@ module SolidObjects
|
|
|
143
146
|
next unless locked_reminder
|
|
144
147
|
verify_claim!(locked_reminder)
|
|
145
148
|
schedule_now = now || database_adapter.database_now
|
|
149
|
+
next skip_missed_window(locked_reminder, schedule_now) if missed_window?(locked_reminder, schedule_now)
|
|
150
|
+
|
|
146
151
|
message = mailbox.enqueue_in_transaction(
|
|
147
152
|
reference: Reference.new(actor_type: instance.actor_type, actor_id: instance.actor_id),
|
|
148
153
|
operation: locked_reminder.operation,
|
|
@@ -155,13 +160,14 @@ module SolidObjects
|
|
|
155
160
|
locked_reminder.update!(
|
|
156
161
|
status: recurring ? "scheduled" : "completed",
|
|
157
162
|
occurrence: locked_reminder.occurrence + 1,
|
|
163
|
+
last_run_at: schedule_now,
|
|
158
164
|
next_run_at: recurring ? next_run_at(locked_reminder, schedule_now) : locked_reminder.next_run_at,
|
|
159
165
|
claimed_by: nil,
|
|
160
166
|
claimed_at: nil
|
|
161
167
|
)
|
|
162
168
|
message
|
|
163
169
|
end
|
|
164
|
-
return unless message
|
|
170
|
+
return message unless message.is_a?(Message)
|
|
165
171
|
|
|
166
172
|
mailbox.announce(message)
|
|
167
173
|
SolidObjects.instrument(
|
|
@@ -179,6 +185,39 @@ module SolidObjects
|
|
|
179
185
|
MessageReference.from_message(message)
|
|
180
186
|
end
|
|
181
187
|
|
|
188
|
+
# A skip reminder runs an occurrence that is late inside its own slot, but
|
|
189
|
+
# once a later aligned time has also passed, every occurrence up to now is
|
|
190
|
+
# missed: none is enqueued, and the reminder waits for the next aligned
|
|
191
|
+
# time after now. One-shots have no next time, so they always fire.
|
|
192
|
+
# @rbs (Reminder, Time) -> bool
|
|
193
|
+
def missed_window?(reminder, now)
|
|
194
|
+
return false unless reminder.missed_policy == "skip" && reminder.interval_seconds.present?
|
|
195
|
+
|
|
196
|
+
now >= reminder.next_run_at + reminder.interval_seconds.to_f
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# @rbs (Reminder, Time) -> :skipped
|
|
200
|
+
def skip_missed_window(reminder, now)
|
|
201
|
+
reminder.update!(next_run_at: next_run_at(reminder, now), claimed_by: nil, claimed_at: nil)
|
|
202
|
+
:skipped
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
# A reminder whose operation is unknown cannot become a message, so it is
|
|
206
|
+
# paused with the error recorded rather than left scheduled, where every
|
|
207
|
+
# scheduler pass would claim it and fail again. Only a new schedule of the
|
|
208
|
+
# same name arms it again.
|
|
209
|
+
# @rbs (Reminder, StandardError) -> (:paused | nil)
|
|
210
|
+
def pause(reminder, error)
|
|
211
|
+
database_adapter.transaction do
|
|
212
|
+
locked_reminder = Reminder.lock.find_by(id: reminder.id)
|
|
213
|
+
next unless locked_reminder
|
|
214
|
+
verify_claim!(locked_reminder)
|
|
215
|
+
|
|
216
|
+
locked_reminder.update!(status: "paused", error_class: error.class.name, claimed_by: nil, claimed_at: nil)
|
|
217
|
+
:paused
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
182
221
|
# @rbs (Reminder) -> void
|
|
183
222
|
def release(reminder)
|
|
184
223
|
Reminder
|
|
@@ -193,6 +232,8 @@ module SolidObjects
|
|
|
193
232
|
raise LostActivation, "reminder claim changed"
|
|
194
233
|
end
|
|
195
234
|
|
|
235
|
+
# latest and skip advance to the first aligned time after now; all advances
|
|
236
|
+
# one interval, even into the past, so each missed occurrence is enqueued.
|
|
196
237
|
# @rbs (Reminder, Time) -> Time
|
|
197
238
|
def next_run_at(reminder, now)
|
|
198
239
|
interval = reminder.interval_seconds.to_f
|
|
@@ -135,14 +135,20 @@ module SolidObjects
|
|
|
135
135
|
|
|
136
136
|
attr_reader handle(): untyped
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
| (name: untyped, operation: untyped, key: untyped, next_run_at: untyped, interval_seconds: untyped, missed_policy: untyped, occurrence: untyped, status: untyped, handle: untyped) -> instance
|
|
138
|
+
attr_reader last_run_at(): untyped
|
|
140
139
|
|
|
141
|
-
|
|
140
|
+
attr_reader error_class(): untyped
|
|
142
141
|
|
|
143
|
-
def
|
|
142
|
+
def self.new: (untyped name, untyped operation, untyped key, untyped next_run_at, untyped interval_seconds, untyped missed_policy, untyped occurrence, untyped status, untyped handle, untyped last_run_at, untyped error_class) -> instance
|
|
143
|
+
| (name: untyped, operation: untyped, key: untyped, next_run_at: untyped, interval_seconds: untyped, missed_policy: untyped, occurrence: untyped, status: untyped, handle: untyped, last_run_at: untyped, error_class: untyped) -> instance
|
|
144
|
+
|
|
145
|
+
def self.members: () -> [ :name, :operation, :key, :next_run_at, :interval_seconds, :missed_policy, :occurrence, :status, :handle, :last_run_at, :error_class ]
|
|
146
|
+
|
|
147
|
+
def members: () -> [ :name, :operation, :key, :next_run_at, :interval_seconds, :missed_policy, :occurrence, :status, :handle, :last_run_at, :error_class ]
|
|
144
148
|
end
|
|
145
149
|
|
|
150
|
+
MISSED_POLICIES: untyped
|
|
151
|
+
|
|
146
152
|
class OutboundMessageIntent < Data
|
|
147
153
|
attr_reader actor_type(): untyped
|
|
148
154
|
|
|
@@ -291,7 +297,10 @@ module SolidObjects
|
|
|
291
297
|
def handle_name: (reminder_handle, key: untyped) -> String
|
|
292
298
|
|
|
293
299
|
# The view is the committed schedule with this turn's staged intents applied
|
|
294
|
-
# in order, so a read agrees with what the commit will leave behind.
|
|
300
|
+
# in order, so a read agrees with what the commit will leave behind. A
|
|
301
|
+
# completed one-shot is not reported, but one this turn schedules again is in
|
|
302
|
+
# the view until the intents are applied, because the commit reuses its row
|
|
303
|
+
# and keeps its run history.
|
|
295
304
|
# @rbs () -> Hash[String, ReminderStatus]
|
|
296
305
|
def reminder_view: () -> Hash[String, ReminderStatus]
|
|
297
306
|
|
|
@@ -301,8 +310,8 @@ module SolidObjects
|
|
|
301
310
|
# @rbs (Hash[String, ReminderStatus], untyped) -> void
|
|
302
311
|
def apply_reminder_intent: (Hash[String, ReminderStatus], untyped) -> void
|
|
303
312
|
|
|
304
|
-
# @rbs (name: String, operation: String, next_run_at: Time?, interval_seconds: untyped, missed_policy: String, occurrence: Integer, status: String) -> ReminderStatus
|
|
305
|
-
def reminder_status: (name: String, operation: String, next_run_at: Time?, interval_seconds: untyped, missed_policy: String, occurrence: Integer, status: String) -> ReminderStatus
|
|
313
|
+
# @rbs (name: String, operation: String, next_run_at: Time?, interval_seconds: untyped, missed_policy: String, occurrence: Integer, status: String, last_run_at: Time?, error_class: String?) -> ReminderStatus
|
|
314
|
+
def reminder_status: (name: String, operation: String, next_run_at: Time?, interval_seconds: untyped, missed_policy: String, occurrence: Integer, status: String, last_run_at: Time?, error_class: String?) -> ReminderStatus
|
|
306
315
|
|
|
307
316
|
# @rbs (name: String, operation: String) -> String?
|
|
308
317
|
def reminder_key_of: (name: String, operation: String) -> String?
|
|
@@ -24,9 +24,18 @@ module SolidObjects
|
|
|
24
24
|
# @rbs () -> Array[ActiveRecord::Relation[Message]]
|
|
25
25
|
def policy_relations: () -> Array[ActiveRecord::Relation[Message]]
|
|
26
26
|
|
|
27
|
+
# Messages that no live row points at. Each guard is a correlated NOT EXISTS
|
|
28
|
+
# rather than NOT IN, so the database can answer it with an index probe on
|
|
29
|
+
# the referencing table, even for the `status !=` guards that NOT IN could
|
|
30
|
+
# only answer by scanning, and a NULL in the referencing column cannot make
|
|
31
|
+
# the predicate unknown.
|
|
32
|
+
#
|
|
27
33
|
# @rbs () -> ActiveRecord::Relation[Message]
|
|
28
34
|
def prunable: () -> ActiveRecord::Relation[Message]
|
|
29
35
|
|
|
36
|
+
# Pages by primary key so each batch resumes after the previous one instead
|
|
37
|
+
# of re-walking rows that are still protected. A short page is the last one.
|
|
38
|
+
#
|
|
30
39
|
# @rbs (ActiveRecord::Relation[Message]) -> Integer
|
|
31
40
|
def prune_relation: (ActiveRecord::Relation[Message]) -> Integer
|
|
32
41
|
|
|
@@ -47,8 +47,28 @@ module SolidObjects
|
|
|
47
47
|
# @rbs (now: Time?) -> Reminder?
|
|
48
48
|
def claim_next: (now: Time?) -> Reminder?
|
|
49
49
|
|
|
50
|
-
#
|
|
51
|
-
|
|
50
|
+
# Returns the enqueued message, :skipped when a skip reminder dropped a
|
|
51
|
+
# missed window, :paused when its operation is unknown, or nil when the
|
|
52
|
+
# reminder or its actor is gone. Anything but nil is scheduler work.
|
|
53
|
+
# @rbs (Reminder, now: Time?) -> (MessageReference | :skipped | :paused)?
|
|
54
|
+
def enqueue: (Reminder, now: Time?) -> (MessageReference | :skipped | :paused)?
|
|
55
|
+
|
|
56
|
+
# A skip reminder runs an occurrence that is late inside its own slot, but
|
|
57
|
+
# once a later aligned time has also passed, every occurrence up to now is
|
|
58
|
+
# missed: none is enqueued, and the reminder waits for the next aligned
|
|
59
|
+
# time after now. One-shots have no next time, so they always fire.
|
|
60
|
+
# @rbs (Reminder, Time) -> bool
|
|
61
|
+
def missed_window?: (Reminder, Time) -> bool
|
|
62
|
+
|
|
63
|
+
# @rbs (Reminder, Time) -> :skipped
|
|
64
|
+
def skip_missed_window: (Reminder, Time) -> :skipped
|
|
65
|
+
|
|
66
|
+
# A reminder whose operation is unknown cannot become a message, so it is
|
|
67
|
+
# paused with the error recorded rather than left scheduled, where every
|
|
68
|
+
# scheduler pass would claim it and fail again. Only a new schedule of the
|
|
69
|
+
# same name arms it again.
|
|
70
|
+
# @rbs (Reminder, StandardError) -> (:paused | nil)
|
|
71
|
+
def pause: (Reminder, StandardError) -> (:paused | nil)
|
|
52
72
|
|
|
53
73
|
# @rbs (Reminder) -> void
|
|
54
74
|
def release: (Reminder) -> void
|
|
@@ -56,6 +76,8 @@ module SolidObjects
|
|
|
56
76
|
# @rbs (Reminder) -> void
|
|
57
77
|
def verify_claim!: (Reminder) -> void
|
|
58
78
|
|
|
79
|
+
# latest and skip advance to the first aligned time after now; all advances
|
|
80
|
+
# one interval, even into the past, so each missed occurrence is enqueued.
|
|
59
81
|
# @rbs (Reminder, Time) -> Time
|
|
60
82
|
def next_run_at: (Reminder, Time) -> Time
|
|
61
83
|
|
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: 1.0
|
|
4
|
+
version: 1.1.0
|
|
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-
|
|
11
|
+
date: 2026-12-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actioncable
|
|
@@ -340,6 +340,7 @@ files:
|
|
|
340
340
|
- db/migrate/20260922000000_add_solid_objects_administration_events.rb
|
|
341
341
|
- db/migrate/20260922000001_add_solid_objects_redrives.rb
|
|
342
342
|
- db/migrate/20260923000000_add_solid_objects_completed_idempotency_keys.rb
|
|
343
|
+
- db/migrate/20261130000000_add_solid_objects_reminder_run_history.rb
|
|
343
344
|
- docs/adr/0001-postgresql-backend.md
|
|
344
345
|
- docs/adr/0002-jsonb-actor-state.md
|
|
345
346
|
- docs/adr/0003-mailbox-ordering.md
|
|
@@ -359,6 +360,7 @@ files:
|
|
|
359
360
|
- docs/benchmarks.md
|
|
360
361
|
- docs/compare/good-job.md
|
|
361
362
|
- docs/compare/solid-queue.md
|
|
363
|
+
- docs/compare/temporal.md
|
|
362
364
|
- docs/comparisons.md
|
|
363
365
|
- docs/correctness.md
|
|
364
366
|
- docs/dashboard.md
|
|
@@ -403,6 +405,7 @@ files:
|
|
|
403
405
|
- examples/at_least_once/sink.rb
|
|
404
406
|
- examples/compare/customer_billing_sync/customer_billing_sync.rb
|
|
405
407
|
- examples/compare/customer_billing_sync/solid_objects.rb
|
|
408
|
+
- examples/compare/game_room/game_room.rb
|
|
406
409
|
- examples/guides/expiring_reservations/seat_inventory.rb
|
|
407
410
|
- examples/guides/ordered_jobs/account.rb
|
|
408
411
|
- examples/guides/ordered_jobs/apply_entry_job.rb
|