Skip to content

Commit

Permalink
Add puma example.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Dec 22, 2024
1 parent 61f2688 commit 46646c4
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 deletions.
17 changes: 17 additions & 0 deletions examples/puma/application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "async/container"
require "console"

# Console.logger.debug!

class Application < Async::Container::Controller
def setup(container)
container.spawn(name: "Web") do |instance|
instance.exec("bundle", "exec", "puma", "-C", "puma.rb", ready: false)
end
end
end

Application.new.run
3 changes: 3 additions & 0 deletions examples/puma/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
run do |env|
[200, {"content-type" => "text/plain"}, ["Hello World"]]
end
39 changes: 39 additions & 0 deletions examples/puma/gems.locked
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
PATH
remote: ../..
specs:
async-container (0.18.3)
async (~> 2.10)

GEM
remote: https://rubygems.org/
specs:
async (2.21.1)
console (~> 1.29)
fiber-annotation
io-event (~> 1.6, >= 1.6.5)
console (1.29.2)
fiber-annotation
fiber-local (~> 1.1)
json
fiber-annotation (0.2.0)
fiber-local (1.1.0)
fiber-storage
fiber-storage (1.0.0)
io-event (1.7.5)
json (2.9.1)
nio4r (2.7.4)
puma (6.5.0)
nio4r (~> 2.0)
rack (3.1.8)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
async-container!
puma
rack (~> 3)

BUNDLED WITH
2.5.22
6 changes: 6 additions & 0 deletions examples/puma/gems.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source "https://rubygems.org"

gem "async-container", path: "../.."

gem "puma"
gem "rack", "~> 3"
6 changes: 6 additions & 0 deletions examples/puma/puma.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
on_booted do
require "async/container/notify"

notify = Async::Container::Notify.open!
notify.ready!
end
36 changes: 36 additions & 0 deletions examples/puma/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Puma Example

This example shows how to start Puma in a container, using `on_boot` for process readiness.

## Usage

```
> bundle exec ./application.rb
0.0s info: Async::Container::Notify::Console [oid=0x474] [ec=0x488] [pid=196250] [2024-12-22 16:53:08 +1300]
| {:status=>"Initializing..."}
0.0s info: Application [oid=0x4b0] [ec=0x488] [pid=196250] [2024-12-22 16:53:08 +1300]
| Controller starting...
Puma starting in single mode...
* Puma version: 6.5.0 ("Sky's Version")
* Ruby version: ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x86_64-linux]
* Min threads: 0
* Max threads: 5
* Environment: development
* PID: 196252
* Listening on http://0.0.0.0:9292
Use Ctrl-C to stop
0.12s info: Async::Container::Notify::Console [oid=0x474] [ec=0x488] [pid=196250] [2024-12-22 16:53:08 +1300]
| {:ready=>true}
0.12s info: Application [oid=0x4b0] [ec=0x488] [pid=196250] [2024-12-22 16:53:08 +1300]
| Controller started...
^C21.62s info: Async::Container::Group [oid=0x4ec] [ec=0x488] [pid=196250] [2024-12-22 16:53:30 +1300]
| Stopping all processes...
| {
| "timeout": true
| }
21.62s info: Async::Container::Group [oid=0x4ec] [ec=0x488] [pid=196250] [2024-12-22 16:53:30 +1300]
| Sending interrupt to 1 running processes...
- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2024-12-22 16:53:30 +1300 ===
- Goodbye!
```

0 comments on commit 46646c4

Please sign in to comment.