Skip to content

Commit

Permalink
Merge branch 'add_source_typer'
Browse files Browse the repository at this point in the history
  • Loading branch information
zw963 committed Nov 14, 2024
2 parents d2088ff + 3bb7ba5 commit 572dc28
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 18 deletions.
12 changes: 12 additions & 0 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,15 @@ shards:
git: https://github.com/crystal-ameba/ameba.git
version: 1.6.3

markd:
git: https://github.com/icyleaf/markd.git
version: 0.5.0

reply:
git: https://github.com/i3oris/reply.git
version: 0.3.1+git.commit.db423dae3dd34c6ba5e36174653a0c109117a167

source-typer:
git: https://github.com/vici37/cr-source-typer.git
version: 0.2.2+git.commit.33369e56d975a5a92de302b6727c3aceffea48c0

2 changes: 2 additions & 0 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ targets:
development_dependencies:
ameba:
github: crystal-ameba/ameba
source-typer:
github: Vici37/cr-source-typer

crystal: 1.14.0

Expand Down
11 changes: 8 additions & 3 deletions src/procodile/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,19 @@ module Procodile
end
end

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

struct Command
getter name : String, description : String?, options : Proc(OptionParser, Procodile::CLI, Nil)?, callable : Proc(Nil)
getter name, description, options, callable

def initialize(@name, @description, @options, @callable)
def initialize(
@name : String,
@description : String,
@options : Proc(OptionParser, Procodile::CLI, Nil),
@callable : Proc(Nil)
)
end
end

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

private def run(command : String? = nil)
private def run(command : String? = nil) : Nil
exec(command)
end
end
Expand Down
6 changes: 3 additions & 3 deletions src/procodile/control_server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ require "./control_session"

module Procodile
class ControlServer
@supervisor : Procodile::Supervisor
@supervisor : Supervisor

def self.start(supervisor : Procodile::Supervisor) : Nil
def self.start(supervisor : Supervisor) : Nil
spawn do
socket = self.new(supervisor)
socket.listen
end
end

def initialize(@supervisor)
def initialize(@supervisor : Supervisor)
end

def listen : Nil
Expand Down
2 changes: 1 addition & 1 deletion src/procodile/control_session.cr
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module Procodile
"200 " + instances.map { |a| a.map { |i| i ? i.to_struct : nil } }.to_json
end

private def reload_config(options) : String
private def reload_config(options : Options) : String
@supervisor.reload_config

"200 []"
Expand Down
4 changes: 2 additions & 2 deletions src/procodile/process.cr
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ module Procodile
#
# Return a struct
#
def to_struct
def to_struct : ControlClient::ProcessStatus
ControlClient::ProcessStatus.new(
name: self.name,
log_color: self.log_color,
Expand All @@ -174,7 +174,7 @@ module Procodile
#
# Is the given quantity suitable for this process?
#
def correct_quantity?(quantity : Int32)
def correct_quantity?(quantity : Int32) : Bool
if self.restart_mode == "start-term"
quantity >= self.quantity
else
Expand Down
4 changes: 2 additions & 2 deletions src/procodile/supervisor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ module Procodile
result
end

def to_hash
def to_hash : NamedTuple(started_at: Int64?, pid: Int64)
started_at = @started_at

{
Expand Down Expand Up @@ -443,7 +443,7 @@ module Procodile
)
end

def to_s(io : IO)
def to_s(io : IO) : Nil
case type
in .not_running?
io.print "#{instance} is not running (#{status})"
Expand Down
11 changes: 5 additions & 6 deletions src/procodile/tcp_proxy.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Procodile
class TCPProxy
def self.start(supervisor) : TCPProxy
def self.start(supervisor : Supervisor) : TCPProxy
proxy = new(supervisor)
proxy.start

Expand All @@ -13,15 +13,15 @@ module Procodile
@sp_reader, @sp_writer = IO.pipe
end

def start
def start : Thread
@supervisor.config.processes.each { |_, p| add_process(p) }
Thread.new do
listen
Procodile.log nil, "proxy", "Stopped listening on all ports"
end
end

def add_process(process)
def add_process(process : Process) : Nil
if process.proxy?
@listeners[TCPServer.new(process.proxy_address.not_nil!, process.proxy_port.not_nil!)] = process
Procodile.log nil, "proxy", "Proxying traffic on #{process.proxy_address}:#{process.proxy_port} to #{process.name}".colorize.green.to_s
Expand All @@ -32,13 +32,12 @@ module Procodile
Procodile.log nil, "proxy", e.backtrace[0, 5].join("\n")
end

def remove_process(process)
def remove_process(process : Process) : Nil
@stopped_processes << process
@sp_writer.puts(".")
end

def listen
# loop do
def listen : Nil # loop do
# io = IO.select([@sp_reader] + @listeners.keys, nil, nil, 30)
# if io && io.first
# io.first.each do |io|
Expand Down

0 comments on commit 572dc28

Please sign in to comment.