Skip to content

Commit 68f340f

Browse files
authored
Merge pull request #52 from cardmagic/docs/require-run-for-pickup
docs: say where async waits with no worker
2 parents 6b3adaf + 430f9a6 commit 68f340f

4 files changed

Lines changed: 60 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
## Unreleased
44

5+
- State where `async` waits when no worker runs. The `async` section of the
6+
README and the runtime section of `docs/operations.md` now say that the
7+
generator and the migrations start no role, so an application that serves
8+
web requests alone leaves the message ready until
9+
`bundle exec solid_objects start` runs the roles. The message is durable
10+
and waits; it is not lost. `test/integration/background_pickup_test.rb`
11+
pins it: the message reads `ready` and the actor state stays empty until a
12+
worker runs. This matches solid-objects-js#22, which reported the same gap
13+
for `runtime.run(signal)` in the Node package.
14+
515
- Add `examples/at_least_once` and `bundle exec rake at_least_once`, an
616
executable proof that the at-least-once clause fires and that the
717
documented remedy absorbs it. One actor turn stages an effect that writes

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,12 @@ message = order.async(
662662
).submit
663663
```
664664

665+
`async` needs a running actor worker. Installing the engine and migrating the
666+
schema starts no role, so a process that only serves web requests leaves the
667+
message ready. Nothing is lost. The message waits until
668+
`bundle exec solid_objects start` runs the roles. See
669+
[Worker requirements](#worker-requirements) for the feature-by-role table.
670+
665671
Use `available_at:` to spread bulk work or delay one message:
666672

667673
```ruby

docs/operations.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ Start all configured roles:
3131
bundle exec solid_objects start
3232
```
3333

34+
The generator and the migrations prepare the database and start nothing. A
35+
process claims ready messages only after this command starts its roles, so an
36+
application that serves web requests alone leaves every `async` message ready.
37+
The message is durable and waits for the first process that runs the roles. A
38+
direct call or an explicit `sync` needs no running role, because the caller's
39+
own path executes it.
40+
3441
The command loads the host application's `app/actors` directories before
3542
starting any runtime role, even when Rails eager loading is disabled. Actors in
3643
the conventional directory do not need initializer references. The targeted
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
require "database_test_helper"
4+
5+
class BackgroundPickupTest < ActiveSupport::TestCase
6+
class MailboxActor < SolidObjects::Actor
7+
actor_type "background-pickup-mailbox"
8+
9+
attribute :delivered, default: 0
10+
11+
def receive
12+
self.delivered += 1
13+
end
14+
end
15+
16+
test "leaves an async message ready until a worker runs the roles" do
17+
message = MailboxActor.ref("inbox").async.receive
18+
19+
assert_equal "ready", message.status
20+
assert_empty SolidObjects::Instance.find_by!(
21+
actor_type: "background-pickup-mailbox", actor_id: "inbox"
22+
).state
23+
24+
worker = SolidObjects::Worker.new
25+
begin
26+
worker.run_until_idle
27+
ensure
28+
worker.stop
29+
end
30+
31+
assert_equal "completed", message.status
32+
assert_equal(
33+
{ "delivered" => 1 },
34+
SolidObjects::Instance.find_by!(actor_type: "background-pickup-mailbox", actor_id: "inbox").state
35+
)
36+
end
37+
end

0 commit comments

Comments
 (0)