working on tests

This commit is contained in:
David Dollar
2010-05-20 00:04:48 -04:00
parent 0221c2305c
commit 53eb08be4f
14 changed files with 244 additions and 19 deletions
+8 -17
View File
@@ -9,18 +9,18 @@ class Foreman::CLI < Thor
desc "start [PROCFILE]", "Run the app described in PROCFILE"
def start(procfile="Procfile")
error "#{procfile} does not exist." unless File.exist?(procfile)
error "#{procfile} does not exist." unless procfile_exists?(procfile)
Foreman::Engine.new(procfile).start
end
desc "export APP [PROCFILE] [FORMAT]", "Export the app described in PROCFILE as APP to another FORMAT"
def export(app, procfile="Procfile", format="upstart")
error "#{procfile} does not exist." unless File.exist?(procfile)
error "#{procfile} does not exist." unless procfile_exists?(procfile)
formatter = case format
when "upstart" then Foreman::Export::Upstart
else error "Unknown export format: #{format}"
else error "Unknown export format: #{format}."
end
formatter.new(Foreman::Engine.new(procfile)).export(app)
@@ -29,20 +29,7 @@ class Foreman::CLI < Thor
desc "scale APP PROCESS AMOUNT", "Change the concurrency of a given process type"
def scale(app, process, amount)
config = Foreman::Configuration.new(app)
amount = amount.to_i
old_amount = config.processes[process]
config.scale(process, amount)
if (old_amount < amount)
((old_amount+1)..amount).each { |num| system "start #{app}-#{process} NUM=#{num}" }
elsif (amount < old_amount)
((amount+1)..old_amount).each { |num| system "stop #{app}-#{process} NUM=#{num}" }
end
config.write
Foreman::Configuration.new(app).scale(process, amount)
end
private ######################################################################
@@ -52,4 +39,8 @@ private ######################################################################
exit 1
end
def procfile_exists?(procfile)
File.exist?(procfile)
end
end
+15 -1
View File
@@ -12,7 +12,17 @@ class Foreman::Configuration
end
def scale(process, amount)
old_amount = processes[process]
processes[process] = amount.to_i
amount = amount.to_i
if (old_amount < amount)
((old_amount + 1) .. amount).each { |num| run "start #{app}-#{process} NUM=#{num}" }
elsif (amount < old_amount)
((amount + 1) .. old_amount).each { |num| run "stop #{app}-#{process} NUM=#{num}" }
end
write
end
def write
@@ -31,10 +41,14 @@ private ######################################################################
accum.update(key => value)
end
config["#{app}_processes"].split(" ").each do |process|
scale(process, config["#{app}_#{process}"])
processes[process] = config["#{app}_#{process}"].to_i
end
end
def run(command)
system command
end
def write_file(filename, contents)
File.open(filename, "w") do |file|
file.puts contents
+5 -1
View File
@@ -7,7 +7,7 @@ class Foreman::Engine
attr_reader :directory
def initialize(procfile)
@procfile = File.read(procfile)
@procfile = read_procfile(procfile)
@directory = File.expand_path(File.dirname(procfile))
end
@@ -76,6 +76,10 @@ private ######################################################################
end
end
def read_procfile(procfile)
File.read(procfile)
end
def running_processes
@running_processes ||= {}
end