Skip to content

Commit

Permalink
Cleanup namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
zw963 committed Nov 23, 2024
1 parent 3e07e18 commit 84cc6e8
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 40 deletions.
14 changes: 7 additions & 7 deletions src/procodile/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Procodile
@@commands ||= {} of String => Command
end

@@options = {} of Symbol => Proc(OptionParser, Procodile::CLI, Nil)
@@options = {} of Symbol => Proc(OptionParser, CLI, Nil)

{% begin %}
{% for e in COMMANDS %}
Expand All @@ -36,7 +36,7 @@ module Procodile

def initialize
@options = Options.new
@config = uninitialized Procodile::Config
@config = uninitialized Config

{% for e in COMMANDS %}
{% name = e[0] %}
Expand All @@ -61,9 +61,9 @@ module Procodile
end

def self.start_supervisor(
config : Procodile::Config,
config : Config,
options : Options = Options.new,
&after_start : Proc(Procodile::Supervisor, Nil)
&after_start : Proc(Supervisor, Nil)
) : Nil
run_options = Supervisor::RunOptions.new(
respawn: options.respawn?,
Expand Down Expand Up @@ -112,7 +112,7 @@ module Procodile
end

# Clean up procodile.pid and procodile.sock with all unused pid files
private def self.tidy_pids(config : Procodile::Config) : Nil
private def self.tidy_pids(config : Config) : Nil
FileUtils.rm_rf(config.supervisor_pid_path)
FileUtils.rm_rf(config.sock_path)

Expand Down Expand Up @@ -159,7 +159,7 @@ module Procodile
end
end

private def self.options(name : Symbol, &block : Proc(OptionParser, Procodile::CLI, Nil)) : Nil
private def self.options(name : Symbol, &block : Proc(OptionParser, CLI, Nil)) : Nil
@@options[name] = block
end

Expand All @@ -169,7 +169,7 @@ module Procodile
def initialize(
@name : String,
@description : String,
@options : Proc(OptionParser, Procodile::CLI, Nil),
@options : Proc(OptionParser, CLI, Nil),
@callable : Proc(Nil),
)
end
Expand Down
2 changes: 1 addition & 1 deletion src/procodile/commands/help_command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Procodile
end

private def help : Nil
puts "Welcome to Procodile v#{VERSION}".colorize.light_gray.on_magenta
puts "Welcome to Procodile v#{Procodile::VERSION}".colorize.light_gray.on_magenta
puts "For documentation see https://adam.ac/procodile."
puts

Expand Down
2 changes: 1 addition & 1 deletion src/procodile/commands/status_command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module Procodile
end
end

private def print_processes(status : Procodile::ControlClient::ReplyOfStatusCommand) : Nil
private def print_processes(status : ControlClient::ReplyOfStatusCommand) : Nil
puts

status.processes.each_with_index do |process, index|
Expand Down
12 changes: 6 additions & 6 deletions src/procodile/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Procodile
]

@process_list : Hash(String, String)?
@processes : Hash(String, Procodile::Process)?
@processes : Hash(String, Process)?
@options : Option?
@local_options : Option?
@process_options : Hash(String, Process::Option)?
Expand All @@ -38,7 +38,7 @@ module Procodile

FileUtils.mkdir_p(pid_root)

@processes = process_list.each_with_index.each_with_object({} of String => Procodile::Process) do |(h, index), hash|
@processes = process_list.each_with_index.each_with_object({} of String => Process) do |(h, index), hash|
name = h[0]
command = h[1]

Expand Down Expand Up @@ -107,8 +107,8 @@ module Procodile
local_options.exec_prefix || options.exec_prefix
end

def processes : Hash(String, Procodile::Process)
@processes ||= {} of String => Procodile::Process
def processes : Hash(String, Process)
@processes ||= {} of String => Process
end

def process_list : Hash(String, String)
Expand Down Expand Up @@ -187,8 +187,8 @@ module Procodile
"#{procfile_path}.local"
end

private def create_process(name : String, command : String, log_color : Colorize::ColorANSI) : Procodile::Process
process = Procodile::Process.new(self, name, command, options_for_process(name))
private def create_process(name : String, command : String, log_color : Colorize::ColorANSI) : Process
process = Process.new(self, name, command, options_for_process(name))
process.log_color = log_color
process
end
Expand Down
2 changes: 1 addition & 1 deletion src/procodile/control_session.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Procodile
class ControlSession
def initialize(@supervisor : Procodile::Supervisor, @client : UNIXSocket)
def initialize(@supervisor : Supervisor, @client : UNIXSocket)
end

private def start_processes(options : Options) : String
Expand Down
6 changes: 3 additions & 3 deletions src/procodile/instance.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Procodile
# Return a description for this instance
getter description : String { "#{@process.name}.#{@id}" }

def initialize(@supervisor : Procodile::Supervisor, @process : Procodile::Process, @id : Int32)
def initialize(@supervisor : Supervisor, @process : Process, @id : Int32)
@respawns = 0
@stopped = false
end
Expand Down Expand Up @@ -324,7 +324,7 @@ module Procodile
Procodile.log(@process.log_color, description, "Allocated port as #{possible_port}")
@port = possible_port
elsif attempts >= max_attempts
raise Procodile::Error.new "Couldn't allocate port for #{@process.name}"
raise Error.new "Couldn't allocate port for #{@process.name}"
end
end
end
Expand All @@ -344,7 +344,7 @@ module Procodile
server.close
true
else
raise Procodile::Error.new "Invalid network_protocol '#{@process.network_protocol}'"
raise Error.new "Invalid network_protocol '#{@process.network_protocol}'"
end
rescue Socket::BindError
false
Expand Down
8 changes: 4 additions & 4 deletions src/procodile/process.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Procodile
delegate allocate_port_from, proxy_port, to: @options

def initialize(
@config : Procodile::Config,
@config : Config,
@name : String,
@command : String,
@options : Option = Option.new,
Expand Down Expand Up @@ -135,15 +135,15 @@ module Procodile
#
# Generate an array of new instances for this process (based on its quantity)
#
def generate_instances(supervisor : Procodile::Supervisor, quantity : Int32 = self.quantity) : Array(Procodile::Instance)
def generate_instances(supervisor : Supervisor, quantity : Int32 = self.quantity) : Array(Instance)
Array.new(quantity) { create_instance(supervisor) }
end

#
# Create a new instance
#
def create_instance(supervisor : Procodile::Supervisor) : Instance
# supervisor is A Procodile::Supervisor object like this:
def create_instance(supervisor : Supervisor) : Instance
# supervisor is A Supervisor object like this:
# {
# :started_at => 1667297292,
# :pid => 410794,
Expand Down
32 changes: 16 additions & 16 deletions src/procodile/supervisor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ module Procodile

getter config, run_options, tag, tcp_proxy, processes, readers, started_at

def initialize(@config : Procodile::Config, @run_options : RunOptions = RunOptions.new)
@processes = {} of Procodile::Process => Array(Procodile::Instance)
@readers = {} of IO::FileDescriptor => Procodile::Instance
def initialize(@config : Config, @run_options : RunOptions = RunOptions.new)
@processes = {} of Process => Array(Instance)
@readers = {} of IO::FileDescriptor => Instance
@signal_handler = SignalHandler.new
@signal_handler_chan = Channel(Nil).new
@log_listener_chan = Channel(Nil).new
Expand All @@ -28,7 +28,7 @@ module Procodile
@run_options.respawn? != false
end

def start(after_start : Proc(Procodile::Supervisor, Nil)) : Nil
def start(after_start : Proc(Supervisor, Nil)) : Nil
Procodile.log nil, "system", "Procodile supervisor started with PID #{::Process.pid}"
Procodile.log nil, "system", "Application root is #{@config.root}"

Expand Down Expand Up @@ -59,9 +59,9 @@ module Procodile
loop { supervise; sleep 3.seconds }
end

def start_processes(process_names : Array(String)?, options : Options = Options.new) : Array(Procodile::Instance)
def start_processes(process_names : Array(String)?, options : Options = Options.new) : Array(Instance)
@tag = options.tag
instances_started = [] of Procodile::Instance
instances_started = [] of Instance

reload_config

Expand All @@ -77,15 +77,15 @@ module Procodile
instances_started
end

def stop(options : Options = Options.new) : Array(Procodile::Instance)
def stop(options : Options = Options.new) : Array(Instance)
if options.stop_supervisor
@run_options.stop_when_none = true
end

reload_config

processes = options.processes
instances_stopped = [] of Procodile::Instance
instances_stopped = [] of Instance

if processes.nil?
Procodile.log nil, "system", "Stopping all #{@config.app_name} processes"
Expand Down Expand Up @@ -114,10 +114,10 @@ module Procodile
@run_options.foreground?
end

def restart(options : Options = Options.new) : Array(Array(Procodile::Instance | Nil))
def restart(options : Options = Options.new) : Array(Array(Instance | Nil))
wg = WaitGroup.new
@tag = options.tag
instances_restarted = [] of Array(Procodile::Instance?)
instances_restarted = [] of Array(Instance?)
processes = options.processes

reload_config
Expand Down Expand Up @@ -170,7 +170,7 @@ module Procodile
@config.reload
end

def check_concurrency(options : Options = Options.new) : Hash(Symbol, Array(Procodile::Instance))
def check_concurrency(options : Options = Options.new) : Hash(Symbol, Array(Instance))
Procodile.log nil, "system", "Checking process concurrency"

reload_config unless options.reload == false
Expand Down Expand Up @@ -233,7 +233,7 @@ module Procodile

# When the first time start, it is possible @processes[instance.process] is nil
# before the process is started.
@processes[instance.process] ||= [] of Procodile::Instance
@processes[instance.process] ||= [] of Instance

unless @processes[instance.process].includes?(instance)
@processes[instance.process] << instance
Expand Down Expand Up @@ -326,8 +326,8 @@ module Procodile
end
end

private def check_instance_quantities(type : CheckInstanceQuantitiesType = :both, processes : Array(String)? = nil) : Hash(Symbol, Array(Procodile::Instance))
status = {:started => [] of Procodile::Instance, :stopped => [] of Procodile::Instance}
private def check_instance_quantities(type : CheckInstanceQuantitiesType = :both, processes : Array(String)? = nil) : Hash(Symbol, Array(Instance))
status = {:started => [] of Instance, :stopped => [] of Instance}

@processes.each do |process, instances|
next if processes && !processes.includes?(process.name)
Expand Down Expand Up @@ -385,8 +385,8 @@ module Procodile
end
end

private def process_names_to_instances(names : Array(String)) : Array(Procodile::Instance)
names.each_with_object([] of Procodile::Instance) do |name, array|
private def process_names_to_instances(names : Array(String)) : Array(Instance)
names.each_with_object([] of Instance) do |name, array|
if name =~ /\A(.*)\.(\d+)\z/
# app1.1
process_name, id = $1, $2
Expand Down
2 changes: 1 addition & 1 deletion src/procodile/tcp_proxy.cr
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module Procodile

def handle_client(client, server)
process = @listeners[server]
instances = @supervisor.processes[process] || [] of Array(Procodile::Instance)
instances = @supervisor.processes[process] || [] of Array(Instance)
if instances.empty?
Procodile.log nil, "proxy", "There are no processes running for #{process.name}"
else
Expand Down

0 comments on commit 84cc6e8

Please sign in to comment.