Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Feb 11, 2025
1 parent 317f078 commit 6769ffa
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
4 changes: 4 additions & 0 deletions examples/hello/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
# frozen_string_literal: true

run do |env|
Console.info(self, "Sleeping 10 seconds")
sleep(10)
Console.info(self, "Waking up")

[200, {}, ["Hello World"]]
end
22 changes: 15 additions & 7 deletions examples/hello/falcon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,29 @@
require "falcon/environment/rack"
require "falcon/environment/supervisor"

require_relative "limited"

service "hello.localhost" do
include Falcon::Environment::SelfSignedTLS
include Falcon::Environment::Rack

scheme "http"
protocol {Async::HTTP::Protocol::HTTP}

# endpoint do
# Async::HTTP::Endpoint.for(scheme, "localhost", port: 9292, protocol: protocol)
# end
connection_semaphore {Async::Semaphore.new(1)}

endpoint_options do
super().merge({
wrapper: LimitedAcceptor.new(connection_semaphore)
})
end

count 1

# append preload "preload.rb"
url "http://localhost:8080"

# Process will connect to supervisor to report statistics periodically, otherwise it would be killed.
# report :supervisor
endpoint do
::Async::HTTP::Endpoint.parse(url).with(**endpoint_options)
end
end

service "supervisor" do
Expand Down
17 changes: 17 additions & 0 deletions examples/hello/limited.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class LimitedAcceptor < IO::Endpoint::Wrapper
def initialize(semaphore)
@semaphore = semaphore
end

def async(&block)
::Fiber.schedule(&block)
end

def before_accept(server)
server.wait_readable

Console.info(self, semaphore: @semaphore) {"Acquiring semaphore..."}
@semaphore.acquire
Console.info(self, semaphore: @semaphore) {"Acquired semaphore."}
end
end
18 changes: 13 additions & 5 deletions lib/falcon/environment/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ def count

# Options to use when creating the container.
def container_options
{restart: true, count: self.count, health_check_timeout: 30}.compact
{
restart: true,
count: self.count,
health_check_timeout: 30
}.compact
end

# The host that this server will receive connections for.
Expand All @@ -45,13 +49,17 @@ def timeout
nil
end

def endpoint_options
{
reuse_address: true,
timeout: timeout,
}
end

# The upstream endpoint that will handle incoming requests.
# @returns [Async::HTTP::Endpoint]
def endpoint
::Async::HTTP::Endpoint.parse(url).with(
reuse_address: true,
timeout: timeout,
)
::Async::HTTP::Endpoint.parse(url).with(**endpoint_options)
end

def verbose
Expand Down

0 comments on commit 6769ffa

Please sign in to comment.