Skip to content

Commit 46646c4

Browse files
committed
Add puma example.
1 parent 61f2688 commit 46646c4

File tree

6 files changed

+107
-0
lines changed

6 files changed

+107
-0
lines changed

examples/puma/application.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require "async/container"
5+
require "console"
6+
7+
# Console.logger.debug!
8+
9+
class Application < Async::Container::Controller
10+
def setup(container)
11+
container.spawn(name: "Web") do |instance|
12+
instance.exec("bundle", "exec", "puma", "-C", "puma.rb", ready: false)
13+
end
14+
end
15+
end
16+
17+
Application.new.run

examples/puma/config.ru

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
run do |env|
2+
[200, {"content-type" => "text/plain"}, ["Hello World"]]
3+
end

examples/puma/gems.locked

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
PATH
2+
remote: ../..
3+
specs:
4+
async-container (0.18.3)
5+
async (~> 2.10)
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
async (2.21.1)
11+
console (~> 1.29)
12+
fiber-annotation
13+
io-event (~> 1.6, >= 1.6.5)
14+
console (1.29.2)
15+
fiber-annotation
16+
fiber-local (~> 1.1)
17+
json
18+
fiber-annotation (0.2.0)
19+
fiber-local (1.1.0)
20+
fiber-storage
21+
fiber-storage (1.0.0)
22+
io-event (1.7.5)
23+
json (2.9.1)
24+
nio4r (2.7.4)
25+
puma (6.5.0)
26+
nio4r (~> 2.0)
27+
rack (3.1.8)
28+
29+
PLATFORMS
30+
ruby
31+
x86_64-linux
32+
33+
DEPENDENCIES
34+
async-container!
35+
puma
36+
rack (~> 3)
37+
38+
BUNDLED WITH
39+
2.5.22

examples/puma/gems.rb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source "https://rubygems.org"
2+
3+
gem "async-container", path: "../.."
4+
5+
gem "puma"
6+
gem "rack", "~> 3"

examples/puma/puma.rb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
on_booted do
2+
require "async/container/notify"
3+
4+
notify = Async::Container::Notify.open!
5+
notify.ready!
6+
end

examples/puma/readme.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Puma Example
2+
3+
This example shows how to start Puma in a container, using `on_boot` for process readiness.
4+
5+
## Usage
6+
7+
```
8+
> bundle exec ./application.rb
9+
0.0s info: Async::Container::Notify::Console [oid=0x474] [ec=0x488] [pid=196250] [2024-12-22 16:53:08 +1300]
10+
| {:status=>"Initializing..."}
11+
0.0s info: Application [oid=0x4b0] [ec=0x488] [pid=196250] [2024-12-22 16:53:08 +1300]
12+
| Controller starting...
13+
Puma starting in single mode...
14+
* Puma version: 6.5.0 ("Sky's Version")
15+
* Ruby version: ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x86_64-linux]
16+
* Min threads: 0
17+
* Max threads: 5
18+
* Environment: development
19+
* PID: 196252
20+
* Listening on http://0.0.0.0:9292
21+
Use Ctrl-C to stop
22+
0.12s info: Async::Container::Notify::Console [oid=0x474] [ec=0x488] [pid=196250] [2024-12-22 16:53:08 +1300]
23+
| {:ready=>true}
24+
0.12s info: Application [oid=0x4b0] [ec=0x488] [pid=196250] [2024-12-22 16:53:08 +1300]
25+
| Controller started...
26+
^C21.62s info: Async::Container::Group [oid=0x4ec] [ec=0x488] [pid=196250] [2024-12-22 16:53:30 +1300]
27+
| Stopping all processes...
28+
| {
29+
| "timeout": true
30+
| }
31+
21.62s info: Async::Container::Group [oid=0x4ec] [ec=0x488] [pid=196250] [2024-12-22 16:53:30 +1300]
32+
| Sending interrupt to 1 running processes...
33+
- Gracefully stopping, waiting for requests to finish
34+
=== puma shutdown: 2024-12-22 16:53:30 +1300 ===
35+
- Goodbye!
36+
```

0 commit comments

Comments
 (0)