Skip to content

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Mar 22, 2024
1 parent ccb42ef commit fba1a14
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 39 deletions.
2 changes: 1 addition & 1 deletion falcon.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "async-http", "~> 0.57"
spec.add_dependency "async-http-cache", "~> 0.4.0"
spec.add_dependency "async-io", "~> 1.22"
spec.add_dependency "async-service", "~> 0.8.0"
spec.add_dependency "async-service", "~> 0.9.0"
spec.add_dependency "bundler"
spec.add_dependency "localhost", "~> 1.1"
spec.add_dependency "openssl", "~> 3.0"
Expand Down
5 changes: 3 additions & 2 deletions lib/falcon/command/serve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

require_relative '../server'
require_relative '../endpoint'
require_relative '../configuration'
require_relative '../service/server'
require_relative '../environment/rackup'
require_relative '../environments/rackup'

require 'async/container'
require 'async/http/client'
Expand Down Expand Up @@ -53,7 +54,7 @@ def endpoint_options

def environment
Async::Service::Environment.new(Falcon::Service::Server::Environment).with(
Falcon::Environment::Rackup,
Falcon::Environments::Rackup,

root: Dir.pwd,

Expand Down
2 changes: 1 addition & 1 deletion lib/falcon/command/virtual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def environment
configuration_paths: self.paths,
bind_insecure: @options[:bind_insecure],
bind_secure: @options[:bind_secure],
timeout: @options[:timeout]
timeout: @options[:timeout],
)
end

Expand Down
20 changes: 5 additions & 15 deletions lib/falcon/environments/rack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,14 @@
# Released under the MIT License.
# Copyright, 2019-2023, by Samuel Williams.

require 'rack/builder'
require_relative '../server'
require_relative '../environments'
require_relative '../service/application'
require_relative 'rackup'

module Falcon
module Environment
module Environments
module Rack
def rackup_path
'config.ru'
end

def rack_app
::Rack::Builder.parse_file(rackup_path)
end

def middleware
::Falcon::Server.middleware(rack_app, verbose: verbose, cache: cache)
end
include Service::Application::Environment
include Rackup
end

LEGACY_ENVIRONMENTS[:rack] = Rack
Expand Down
26 changes: 26 additions & 0 deletions lib/falcon/environments/rackup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2019-2023, by Samuel Williams.

require 'rack/builder'
require_relative '../server'
require_relative '../environments'

module Falcon
module Environments
module Rackup
def rackup_path
'config.ru'
end

def rack_app
::Rack::Builder.parse_file(rackup_path)
end

def middleware
::Falcon::Server.middleware(rack_app, verbose: verbose, cache: cache)
end
end
end
end
20 changes: 5 additions & 15 deletions lib/falcon/service/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Copyright, 2020, by Daniel Evans.

require_relative 'proxy'
require_relative '../proxy_endpoint'

require 'async/http/endpoint'
require 'async/io/shared_endpoint'
Expand Down Expand Up @@ -72,26 +73,15 @@ def initialize(...)
@bound_endpoint = nil
end

# The middleware that will be served by this application.
# @returns [Protocol::HTTP::Middleware]
def middleware
# In a multi-threaded container, we don't want to modify the shared evaluator's cache, so we create a new evaluator:
@environment.evaluator.middleware
end

# Number of instances to start.
# @returns [Integer | nil]
def count
@environment.evaluator.count
end

# Prepare the bound endpoint for the application instances.
# Invoke {preload!} to load shared resources into the parent process.
def start
Console.logger.info(self) {"Binding to #{self.endpoint}..."}
endpoint = @evaluator.endpoint

Console.logger.info(self) {"Binding to #{endpoint}..."}

@bound_endpoint = Async::Reactor.run do
Async::IO::SharedEndpoint.bound(self.endpoint)
Async::IO::SharedEndpoint.bound(endpoint)
end.wait

preload!
Expand Down
7 changes: 2 additions & 5 deletions lib/falcon/service/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def self.included(target)
def initialize(...)
super

@endpoint = nil
@bound_endpoint = nil
end

Expand All @@ -82,10 +81,10 @@ def preload!

# Prepare the bound endpoint for the server.
def start
@endpoint ||= @evaluator.endpoint
endpoint = @evaluator.endpoint

Sync do
@bound_endpoint = @endpoint.bound
@bound_endpoint = endpoint.bound
end

preload!
Expand Down Expand Up @@ -122,8 +121,6 @@ def stop(...)
@bound_endpoint = nil
end

@endpoint = nil

super
end
end
Expand Down

0 comments on commit fba1a14

Please sign in to comment.