Skip to content

Commit 39d7707

Browse files
committed
Use Thruster (AnyCabled)
1 parent 06a573a commit 39d7707

8 files changed

Lines changed: 47 additions & 73 deletions

File tree

Gemfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ gem 'cssbundling-rails'
2121
gem 'jsbundling-rails'
2222
gem 'propshaft'
2323

24+
gem 'anycable-thruster'
25+
2426
group :development, :test do
25-
gem 'debug', '~> 1.9'
27+
# FIXME: Fails with Operation not supported by device - <STDIN> when running within Thruster
28+
gem 'debug', '~> 1.9'#, require: false
2629
gem 'rspec-rails', '~> 6.0'
2730
end
2831

@@ -33,9 +36,7 @@ end
3336
group :test do
3437
gem 'capybara'
3538
gem 'cuprite'
36-
37-
# Rack-based AnyCable server implementation
38-
gem 'anycable-rack-server', '~> 0.5'
39+
gem 'childprocess'
3940

4041
gem 'test-prof'
4142
end

Gemfile.lock

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,18 @@ GEM
8383
anycable-core (1.5.0)
8484
anyway_config (~> 2.2)
8585
google-protobuf (~> 3.25)
86-
anycable-rack-server (0.5.1)
87-
anycable (> 1.0.99, < 2.0)
88-
anyway_config (>= 2.1.0)
89-
connection_pool (~> 2.2)
90-
websocket (~> 1.2)
9186
anycable-rails (1.5.1)
9287
anycable (~> 1.5.0)
9388
anycable-rails-core (= 1.5.1)
9489
anycable-rails-core (1.5.1)
9590
actioncable (>= 6.0)
9691
anycable-core (~> 1.5.0)
9792
globalid
93+
anycable-thruster (0.1.3)
94+
anycable-thruster (0.1.3-aarch64-linux)
95+
anycable-thruster (0.1.3-arm64-darwin)
96+
anycable-thruster (0.1.3-x86_64-darwin)
97+
anycable-thruster (0.1.3-x86_64-linux)
9898
anyway_config (2.6.3)
9999
ruby-next-core (~> 1.0)
100100
ast (2.4.2)
@@ -112,6 +112,7 @@ GEM
112112
rack-test (>= 0.6.3)
113113
regexp_parser (>= 1.5, < 3.0)
114114
xpath (~> 3.2)
115+
childprocess (5.0.0)
115116
concurrent-ruby (1.2.3)
116117
connection_pool (2.4.1)
117118
crass (1.0.6)
@@ -320,7 +321,6 @@ GEM
320321
diff-lcs (~> 1.3)
321322
parser (>= 3.3.0)
322323
webrick (1.8.1)
323-
websocket (1.2.10)
324324
websocket-driver (0.7.6)
325325
websocket-extensions (>= 0.1.0)
326326
websocket-extensions (0.1.5)
@@ -339,10 +339,11 @@ PLATFORMS
339339
x86_64-linux
340340

341341
DEPENDENCIES
342-
anycable-rack-server (~> 0.5)
343342
anycable-rails (~> 1.5)
343+
anycable-thruster
344344
bootsnap (>= 1.4.2)
345345
capybara
346+
childprocess
346347
cssbundling-rails
347348
cuprite
348349
daemons (~> 1.3)

Procfile.dev

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
server: bundle exec rails s -p 3000
1+
server: ANYCABLE_OPT="--broadcast_adapter=http --presets=broker --rpc_host=http://localhost:3100/_anycable" HTTP_PORT=3000 TARGET_PORT=3100 bundle exec thrust bin/rails s
22
css: yarn build:css --watch
33
js: yarn build --watch
4-
ws: bin/anycable-go --port=8080 --broadcast_adapter=http --presets=broker --rpc_host=http://localhost:3000/_anycable

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ bin/setup
2424

2525
## Running
2626

27-
Since you need to run multiple processes (Rails, AnyCable-Go), we recommend using a process manager, e.g., [Hivemind](https://github.com/DarthSim/hivemind):
27+
Run Rails server and all secondary processes (CSS/JS bundling):
2828

2929
```sh
30-
hivemind Procfile.dev
30+
bin/dev
3131
```
3232

3333
Then go to [http://localhost:3000/](http://localhost:3000/) and see the application in action.

config/anycable.yml

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,19 @@
1-
# This file contains per-environment settings for AnyCable.
2-
#
3-
# Since AnyCable config is based on anyway_config (https://github.com/palkan/anyway_config), all AnyCable settings
4-
# can be set or overridden through the corresponding environment variables.
5-
# E.g., `rpc_host` is overridden by ANYCABLE_RPC_HOST, `debug` by ANYCABLE_DEBUG etc.
6-
#
7-
# Note that AnyCable recognizes REDIS_URL env variable for Redis pub/sub adapter. If you want to
8-
# use another Redis instance for AnyCable, provide ANYCABLE_REDIS_URL variable.
9-
#
10-
# Read more about AnyCable configuration here: https://docs.anycable.io/#/ruby/configuration
1+
# Read more about AnyCable configuration here: https://docs.anycable.io/ruby/configuration
112
#
123
default: &default
134
# Turn on/off access logs ("Started..." and "Finished...")
145
access_logs_disabled: false
15-
# Persist "dirty" session between RPC calls (might be required for apps using stimulus_reflex <3.0)
16-
# persistent_session_enabled: true
17-
# This is the host and the port to run AnyCable RPC server on.
18-
# You must configure your WebSocket server to connect to it, e.g.:
19-
# $ anycable-go --rpc-host="<rpc hostname>:50051"
20-
rpc_host: "127.0.0.1:50051"
21-
# Whether to enable gRPC level logging or not
22-
log_grpc: false
236
# Use HTTP adapter for a quick start (since redis gem is not present in the project)
247
broadcast_adapter: http
25-
# Use the same channel name for WebSocket server, e.g.:
26-
# $ anycable-go --redis-channel="__anycable__"
27-
redis_channel: "__anycable__"
288
# WebSocket server URL for clients
29-
websocket_url: "ws://localhost:8080/cable"
9+
websocket_url: "/cable"
10+
http_rpc_mount_path: "/_anycable"
3011

3112
development:
3213
<<: *default
33-
http_rpc_mount_path: "/_anycable"
3414

3515
test:
3616
<<: *default
37-
rpc_pool_size: 5
38-
http_broadcast_url: "http://localhost:3023/_anycable_rack_broadcast"
3917

4018
production:
4119
<<: *default

config/environments/test.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@
1111
AnyCable::Rails.extend_adapter!(ActionCable.server.pubsub)
1212
end
1313

14-
# Specify AnyCable WebSocket server URL to use by JS client
15-
config.action_cable.url = "/rack_cable"
16-
# Disable built-in Action Cable
17-
config.action_cable.mount_path = nil
18-
# Run AnyCable Rack server at a custom path
19-
config.any_cable_rack.mount_path = "/rack_cable"
20-
2114
# Settings specified here will take precedence over those in config/application.rb.
2215
config.cache_classes = true
2316

spec/system/support/anycable_setup.rb

Lines changed: 0 additions & 26 deletions
This file was deleted.

spec/system/support/capybara_setup.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
# frozen_string_literal: true
22

3+
# Capybara Thruster integration
4+
require "childprocess"
5+
Capybara.register_server :thruster do |app, port, host, **options|
6+
puma_port = port + 1
7+
8+
# TODO: Figure out how to avoid sleep here
9+
process = ChildProcess.build("bundle", "exec", "thrust", "sleep", "100")
10+
process.environment["TARGET_PORT"] = puma_port.to_s
11+
process.environment["HTTP_PORT"] = port.to_s
12+
13+
# AnyCable options
14+
anycable_options = {rpc_host: "http://localhost:#{puma_port}/_anycable", broadcast_adapter: "http"}
15+
anycable_options.merge!(options[:anycable_options]) if options[:anycable_options]
16+
process.environment["ANYCABLE_OPT"] = anycable_options.reduce(+"") { |acc, (k, v)| "#{acc} --#{k}=#{v}" }
17+
18+
# Additional environment variables
19+
options.fetch(:env, {}).each { |k, v| process.environment[k.to_s] = v.to_s }
20+
21+
process.io.inherit! if options.delete(:debug) == true
22+
process.start
23+
24+
at_exit { process.stop }
25+
26+
Capybara.servers[:puma].call(app, puma_port, host)
27+
end
28+
29+
Capybara.server = :thruster, {debug: ENV["DEBUG"] == "1"}
30+
331
# Capybara settings (not covered by Rails system tests)
432

533
# Don't wait too long in `have_xyz` matchers

0 commit comments

Comments
 (0)