Module: SimpleAcp::Server::FalconRunner

Defined in:
lib/simple_acp/server/falcon_runner.rb

Overview

Falcon-based server runner using fiber concurrency.

Provides efficient handling of SSE streams and long-lived connections through Async's fiber scheduler.

Examples:

Starting a server

app = server.to_app
FalconRunner.run(app, port: 8000)

Class Method Summary collapse

Class Method Details

.run(app, port: 8000, host: "0.0.0.0", **options) ⇒ void

This method returns an undefined value.

Start the server using Falcon.

Parameters:

  • app (#call) —

    the Rack application

  • port (Integer) (defaults to: 8000) —

    port to bind to (default: 8000)

  • host (String) (defaults to: "0.0.0.0") —

    host to bind to (default: "0.0.0.0")

  • options (Hash) —

    additional options

Options Hash (**options):

  • :count (Integer) —

    number of worker processes



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/simple_acp/server/falcon_runner.rb', line 29

def self.run(app, port: 8000, host: "0.0.0.0", **options)
  endpoint = IO::Endpoint::AddressEndpoint.new(Addrinfo.tcp(host, port))

  puts "ACP Server (Falcon) running on http://#{host}:#{port}"

  server_task = nil

  # Handle interrupt for graceful shutdown
  trap("INT") do
    puts "\nShutting down..."
    Thread.main.raise(Interrupt)
  end

  trap("TERM") do
    puts "\nShutting down..."
    Thread.main.raise(Interrupt)
  end

  begin
    Sync do |task|
      rack_app = Protocol::Rack::Adapter.new(app)
      server = Falcon::Server.new(rack_app, endpoint, protocol: Async::HTTP::Protocol::HTTP1, scheme: "http")

      server_task = server.run
      server_task.wait
    end
  rescue Interrupt
    # Graceful shutdown
  end
end