solid_objects 1.0.6 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 630f03cacb897bac8d3e67f4498f2c1b2dd58c972230527caf66974ebb4e14a0
4
- data.tar.gz: 51bb6bd5440bb3e927815f068e8783034469c43f42ec897b0089bcaa4ffda169
3
+ metadata.gz: d4c2d5ded9cb5fb992d0e7897fc48f3180cf2ac6ee3fe4fe7027de36d5979c7f
4
+ data.tar.gz: 261f9f94db83d5cbd69561a81284b53e9764e26eeb5b107bd47d379beebbafc6
5
5
  SHA512:
6
- metadata.gz: 5a52e9ca0d3dfbe3732bc9a9cadabc99fe5073421e4c0135530f62fb61035d4d6e07be641cbf689c007e8acab8425e7b8f6fe7db242f8fb1628e2d94e3687f05
7
- data.tar.gz: 0fce63f15c0c6a52a1591a2f85cda0841e7a55ccfa9c0820abc45c0850c22e8c6138852816a5192da3476a1856ccb577998f6a031adf23c6db38c224ec34ccb8
6
+ metadata.gz: 8c98fd43013596c1547f250853629682a226df921e2385f84ad4f284c80e0b00e19986520aef90a804ac8994c302e6ce00fec0e2ef38469c8a3017356275004b
7
+ data.tar.gz: b55c442043e25269b449f712f187bef86ba4c2e39561d017a83254d8c0fc85ca4d559d95128c1bd42cdb95620370899a1dbbb49f639e100b28de7defb9d46ec0
data/CHANGELOG.md CHANGED
@@ -2,6 +2,55 @@
2
2
 
3
3
  ## Unreleased
4
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
+
5
54
  ## 1.0.6 - 2026-11-08
6
55
 
7
56
  - Add `docs/compare/temporal.md`, a comparison with the Temporal Ruby SDK.
@@ -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. Recurring catch-up is configurable:
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/reminders.md CHANGED
@@ -13,8 +13,42 @@ def schedule_evaluation
13
13
  end
14
14
  ```
15
15
 
16
- Use `missed: :latest` to coalesce missed occurrences or `missed: :all` to
17
- enqueue each one.
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
@@ -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 %w[all latest].include?(missed_policy)
260
- raise ArgumentError, "missed reminder policy must be all or latest"
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, view|
345
- apply_reminder_intent(view, 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
- Reminder.where(instance_id:).where.not(status: "completed").each_with_object({}) do |row, view|
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: view[intent.name]&.occurrence || 0,
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
 
@@ -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
- Message
47
- .where.not(id: ReadyMessage.select(:message_id))
48
- .where.not(id: ClaimedMessage.select(:message_id))
49
- .where.not(id: DeadLetter.select(:message_id))
50
- .where.not(
51
- id: DeadLetter
52
- .where.not(retried_message_id: nil)
53
- .select(:retried_message_id)
54
- )
55
- .where.not(
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
- # @rbs (Reminder, now: Time?) -> MessageReference?
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
- raise UnknownMessage, "unknown reminder operation #{reminder.operation.inspect}"
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
@@ -1,5 +1,5 @@
1
1
  # rbs_inline: enabled
2
2
 
3
3
  module SolidObjects
4
- VERSION = "1.0.6"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -135,14 +135,20 @@ module SolidObjects
135
135
 
136
136
  attr_reader handle(): untyped
137
137
 
138
- 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) -> instance
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
- def self.members: () -> [ :name, :operation, :key, :next_run_at, :interval_seconds, :missed_policy, :occurrence, :status, :handle ]
140
+ attr_reader error_class(): untyped
142
141
 
143
- def members: () -> [ :name, :operation, :key, :next_run_at, :interval_seconds, :missed_policy, :occurrence, :status, :handle ]
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
- # @rbs (Reminder, now: Time?) -> MessageReference?
51
- def enqueue: (Reminder, now: Time?) -> MessageReference?
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.6
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-08 00:00:00.000000000 Z
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