Rename class Diversipub::PumaTask to Diversipub::Tasks::HTTP
This commit is contained in:
parent
1364cc070f
commit
3755b56cb6
4 changed files with 83 additions and 77 deletions
|
@ -12,10 +12,11 @@ require 'rack/handler/puma'
|
|||
require 'rack/protection'
|
||||
|
||||
require_relative 'diversipub/main'
|
||||
require_relative 'diversipub/puma_task'
|
||||
require_relative 'diversipub/rack_app'
|
||||
require_relative 'diversipub/version'
|
||||
|
||||
require_relative 'diversipub/tasks/http'
|
||||
|
||||
##
|
||||
# A publishing platform for HTTP, Gemini, ActivityPub, RSS, Atom, and others.
|
||||
#
|
||||
|
|
|
@ -29,8 +29,7 @@ module Diversipub
|
|||
|
||||
def run
|
||||
debug_output
|
||||
|
||||
puma_task.join_thread
|
||||
tasks.each(&:join_thread)
|
||||
true
|
||||
end
|
||||
|
||||
|
@ -46,12 +45,12 @@ module Diversipub
|
|||
end
|
||||
|
||||
def stop_gracefully
|
||||
puma_task.stop_gracefully
|
||||
tasks.each(&:stop_gracefully)
|
||||
nil
|
||||
end
|
||||
|
||||
def stop_urgently
|
||||
puma_task.stop_urgently
|
||||
tasks.each(&:stop_urgently)
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -94,8 +93,12 @@ module Diversipub
|
|||
end
|
||||
end
|
||||
|
||||
def puma_task
|
||||
@puma_task ||= PumaTask.new self
|
||||
def tasks
|
||||
@tasks ||= [http_task].freeze
|
||||
end
|
||||
|
||||
def http_task
|
||||
@http_task ||= Tasks::HTTP.new self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Diversipub
|
||||
##
|
||||
# Puma web server task runner.
|
||||
#
|
||||
class PumaTask
|
||||
def initialize(main)
|
||||
@main = main
|
||||
end
|
||||
|
||||
def join_thread
|
||||
thread.join
|
||||
nil
|
||||
end
|
||||
|
||||
def stop_gracefully
|
||||
puma.stop
|
||||
nil
|
||||
end
|
||||
|
||||
alias stop_urgently stop_gracefully
|
||||
|
||||
private
|
||||
|
||||
def thread
|
||||
@thread ||= Thread.start { puma.run }
|
||||
end
|
||||
|
||||
def puma
|
||||
@puma ||= Puma::Launcher.new(
|
||||
puma_config,
|
||||
log_writer: puma_log_writer,
|
||||
)
|
||||
end
|
||||
|
||||
def puma_config
|
||||
@puma_config ||= Puma::Configuration.new puma_options.dup
|
||||
end
|
||||
|
||||
def puma_options
|
||||
@puma_options ||= {
|
||||
app: rack_app,
|
||||
binds: ['tcp://127.0.0.1:9292'].freeze,
|
||||
environment: 'production',
|
||||
log_requests: true,
|
||||
logger: puma_logger,
|
||||
rackup: nil,
|
||||
tag: 'diversipub',
|
||||
tcp_host: '127.0.0.1',
|
||||
tcp_port: 9292,
|
||||
workers: 0,
|
||||
}.freeze
|
||||
end
|
||||
|
||||
def puma_log_writer
|
||||
@puma_log_writer ||= Puma::LogWriter.new @main.stderr, @main.stderr
|
||||
end
|
||||
|
||||
def puma_logger
|
||||
@puma_logger ||= Logger.new(@main.stderr).tap do |puma_logger|
|
||||
puma_logger.level = Logger::DEBUG
|
||||
end
|
||||
end
|
||||
|
||||
def rack_app
|
||||
@rack_app ||= RackApp.new @main
|
||||
end
|
||||
end
|
||||
end
|
72
lib/diversipub/tasks/http.rb
Normal file
72
lib/diversipub/tasks/http.rb
Normal file
|
@ -0,0 +1,72 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Diversipub
|
||||
module Tasks
|
||||
##
|
||||
# HTTP server task runner.
|
||||
#
|
||||
class HTTP
|
||||
def initialize(main)
|
||||
@main = main
|
||||
end
|
||||
|
||||
def join_thread
|
||||
thread.join
|
||||
nil
|
||||
end
|
||||
|
||||
def stop_gracefully
|
||||
puma.stop
|
||||
nil
|
||||
end
|
||||
|
||||
alias stop_urgently stop_gracefully
|
||||
|
||||
private
|
||||
|
||||
def thread
|
||||
@thread ||= Thread.start { puma.run }
|
||||
end
|
||||
|
||||
def puma
|
||||
@puma ||= Puma::Launcher.new(
|
||||
puma_config,
|
||||
log_writer: puma_log_writer,
|
||||
)
|
||||
end
|
||||
|
||||
def puma_config
|
||||
@puma_config ||= Puma::Configuration.new puma_options.dup
|
||||
end
|
||||
|
||||
def puma_options
|
||||
@puma_options ||= {
|
||||
app: rack_app,
|
||||
binds: ['tcp://127.0.0.1:9292'].freeze,
|
||||
environment: 'production',
|
||||
log_requests: true,
|
||||
logger: puma_logger,
|
||||
rackup: nil,
|
||||
tag: 'diversipub',
|
||||
tcp_host: '127.0.0.1',
|
||||
tcp_port: 9292,
|
||||
workers: 0,
|
||||
}.freeze
|
||||
end
|
||||
|
||||
def puma_log_writer
|
||||
@puma_log_writer ||= Puma::LogWriter.new @main.stderr, @main.stderr
|
||||
end
|
||||
|
||||
def puma_logger
|
||||
@puma_logger ||= Logger.new(@main.stderr).tap do |puma_logger|
|
||||
puma_logger.level = Logger::DEBUG
|
||||
end
|
||||
end
|
||||
|
||||
def rack_app
|
||||
@rack_app ||= RackApp.new @main
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue