Skip to content

Commit 3b67e95

Browse files
committed
Merge pull request #147 from code-mancers/start-at-specified-port
start invoker at a port specified from cli
2 parents c295b31 + 2aa913f commit 3b67e95

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

lib/invoker/parsers/config.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ class Config
77
attr_accessor :processes, :power_config
88
attr_reader :filename
99

10+
# initialize takes a port form cli and decrements it by 1 and sets the
11+
# instance variable @port. This port value is used as the environment
12+
# variable $PORT mentioned inside invoker.ini. When method pick_port gets
13+
# fired it increments the value of port by 1, subsequently when pick_port
14+
# again gets fired, for another command, it will again increment port
15+
# value by 1, that way generating different ports for different commands.
1016
def initialize(filename, port)
1117
@filename = filename
12-
@port = port
18+
@port = port - 1
1319
@processes = load_config
1420
if Invoker.can_run_balancer?
1521
@power_config = Invoker::Power::Config.load_config()

spec/invoker/config_spec.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@
7979
config = Invoker::Parsers::Config.new(file.path, 9000)
8080
command1 = config.processes.first
8181

82-
expect(command1.port).to eq(9001)
83-
expect(command1.cmd).to match(/9001/)
82+
expect(command1.port).to eq(9000)
83+
expect(command1.cmd).to match(/9000/)
8484

8585
command2 = config.processes[1]
8686

87-
expect(command2.port).to eq(9002)
88-
expect(command2.cmd).to match(/9002/)
87+
expect(command2.port).to eq(9001)
88+
expect(command2.cmd).to match(/9001/)
8989

9090
command2 = config.processes[2]
9191

@@ -118,8 +118,8 @@
118118
config = Invoker::Parsers::Config.new(file.path, 9000)
119119
command1 = config.processes.first
120120

121-
expect(command1.port).to eq(9001)
122-
expect(command1.cmd).to match(/9001/)
121+
expect(command1.port).to eq(9000)
122+
expect(command1.cmd).to match(/9000/)
123123

124124
command2 = config.processes[1]
125125

@@ -162,7 +162,7 @@
162162
config = Invoker::Parsers::Config.new("/tmp/Procfile", 9000)
163163
command1 = config.processes.first
164164

165-
expect(command1.port).to eq(9001)
165+
expect(command1.port).to eq(9000)
166166
expect(command1.cmd).to match(/bundle exec rails/)
167167
ensure
168168
File.delete("/tmp/Procfile")
@@ -183,7 +183,7 @@
183183

184184
expect(dns_cache.dns_data).to_not be_empty
185185
expect(dns_cache.dns_data['web']).to_not be_empty
186-
expect(dns_cache.dns_data['web']['port']).to eql 9001
186+
expect(dns_cache.dns_data['web']['port']).to eql 9000
187187
ensure
188188
File.delete("/tmp/Procfile")
189189
end

0 commit comments

Comments
 (0)