Skip to content

Commit

Permalink
Move "server" logic to new "server" class
Browse files Browse the repository at this point in the history
  • Loading branch information
zachahn committed Dec 4, 2024
1 parent b202ad5 commit 6b6c7cf
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 33 deletions.
3 changes: 2 additions & 1 deletion exe/disqualified
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
require_relative "../lib/disqualified"
require_relative "../lib/disqualified/cli"

Disqualified::CLI.run
cli = Disqualified::CLI.new
cli.run
1 change: 1 addition & 0 deletions lib/disqualified.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ module Disqualified
require_relative "disqualified/main"
require_relative "disqualified/pool"
require_relative "disqualified/sequence"
require_relative "disqualified/server"
require_relative "disqualified/version"
34 changes: 2 additions & 32 deletions lib/disqualified/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

class Disqualified::CLI
extend T::Sig
include Disqualified::Logging

sig { void }
def self.run
cli = new(ARGV)
cli.run
end

class ServerEngine < Rails::Engine
config.before_initialize do
Expand All @@ -28,31 +21,8 @@ def run
option_parser.parse(@original_argv)

server_options = T.must(Disqualified.server_options)
delay_range = server_options.delay_range
error_hooks = server_options.error_hooks
logger = server_options.logger
pool_size = server_options.pool_size

# standard:disable Style/StringLiterals
logger.info { ' ____ _ ___ _____ __' }
logger.info { ' / __ \(_)________ ___ ______ _/ (_) __(_)__ ____/ /' }
logger.info { ' / / / / / ___/ __ `/ / / / __ `/ / / /_/ / _ \/ __ /' }
logger.info { ' / /_/ / (__ ) /_/ / /_/ / /_/ / / / __/ / __/ /_/ /' }
logger.info { '/_____/_/____/\__, /\__,_/\__,_/_/_/_/ /_/\___/\__,_/' }
logger.info { ' /_/' + "v#{Disqualified::VERSION}".rjust(32, " ") }
# standard:enable Style/StringLiterals
logger.info { Disqualified.server_options.to_s }

pool = Disqualified::Pool.new(delay_range:, pool_size:, error_hooks:, logger:) do |args|
args => {promise_index:}
logger.debug { format_log("Disqualified::CLI#run <block>", "##{promise_index}") }
Disqualified::Main.new(error_hooks:, logger:).call
end
pool.run!
rescue Interrupt
pool&.shutdown
puts
puts "Gracefully quitting..."
server = Disqualified::Server.new(server_options)
server.run
end

private
Expand Down
44 changes: 44 additions & 0 deletions lib/disqualified/server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# typed: strict

class Disqualified::Server
extend T::Sig
include Disqualified::Logging

sig { params(server_options: Disqualified::ServerConfiguration).void }
def initialize(server_options)
@server_options = server_options
end

sig { returns(Disqualified::ServerConfiguration) }
attr_reader :server_options

sig { void }
def run
delay_range = server_options.delay_range
error_hooks = server_options.error_hooks
logger = server_options.logger
pool_size = server_options.pool_size

# standard:disable Style/StringLiterals
logger.info { ' ____ _ ___ _____ __' }
logger.info { ' / __ \(_)________ ___ ______ _/ (_) __(_)__ ____/ /' }
logger.info { ' / / / / / ___/ __ `/ / / / __ `/ / / /_/ / _ \/ __ /' }
logger.info { ' / /_/ / (__ ) /_/ / /_/ / /_/ / / / __/ / __/ /_/ /' }
logger.info { '/_____/_/____/\__, /\__,_/\__,_/_/_/_/ /_/\___/\__,_/' }
logger.info { ' /_/' + "v#{Disqualified::VERSION}".rjust(32, " ") }
# standard:enable Style/StringLiterals
logger.info { Disqualified.server_options.to_s }

pool = Disqualified::Pool.new(delay_range:, pool_size:, error_hooks:, logger:) do |args|
args => {promise_index:}
logger.debug { format_log("Disqualified::CLI#run <block>", "##{promise_index}") }
Disqualified::Main.new(error_hooks:, logger:).call
end
pool.run!
rescue Interrupt
puts
puts "Gracefully quitting..."
pool&.shutdown
puts "Bye!"
end
end

0 comments on commit 6b6c7cf

Please sign in to comment.