invoker 1.5.1 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35e208abbd4ff8979f1d1ecc0c5896ef3b460799
4
- data.tar.gz: 6e2e65d581a9705f5358bf8076654a9b34185683
3
+ metadata.gz: e1da2ee349b145013878352cca28cc1de9ed13c5
4
+ data.tar.gz: 066597992a678fa848f9d6d9e36798272141ff7b
5
5
  SHA512:
6
- metadata.gz: 44eecb467482053d584410fbc279c192e1dc25b7c97f245bf058f20e7bac0a12d9c0c73487d0ab0652d632030ef3f39741449dd5d30391104ef4ec9cc165091f
7
- data.tar.gz: a4108aab6742c8b02886423a341c2d59c47deba5645d73b671686aff4cac4f7af668677645bb5444b8d37fe260afa8e05631ca249ba9d41f6bc9396426534a30
6
+ metadata.gz: 51bd2c4294e3d7b97dfe909f1289b4d62b170db3171c4cee96c1d0848df98d0ab286835f7d8de9a321c2da3e4695aea3e1010a25b308228071f981c2f4dc51ad
7
+ data.tar.gz: e265b1e4452c688517aa5a648a5fd81fc34c3a6a395061e7c486723318d6031018778fe3adcf76219dc8771c0b4f73168491ef86b4229d63b3fd8d26d3058f82
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.require_paths = ["lib"]
27
27
  s.summary = %q{Something small for Process management}
28
28
  s.add_dependency("thor", "~> 0.19")
29
- s.add_dependency("rainbow", "~> 2.0")
29
+ s.add_dependency("rainbow", "~> 2.1.0")
30
30
  s.add_dependency("iniparse", "~> 1.1")
31
31
  s.add_dependency("formatador", "~> 0.2")
32
32
  s.add_dependency("eventmachine", "~> 1.0.4")
@@ -65,6 +65,11 @@ module Invoker
65
65
  tailer.run
66
66
  end
67
67
 
68
+ desc "log process1", "Get log of particular process"
69
+ def log(process_name)
70
+ system("egrep -a '^#{process_name}' #{Invoker.daemon.log_file}")
71
+ end
72
+
68
73
  desc "reload process", "Reload a process managed by Invoker"
69
74
  option :signal,
70
75
  banner: "Signal to send for killing the process, default is SIGINT",
@@ -26,13 +26,13 @@ module Invoker
26
26
  def receive_line(line)
27
27
  tail_watchers = Invoker.tail_watchers[@command_label]
28
28
  color_line = "#{@command_label.color(color)} : #{line}"
29
+ plain_line = "#{@command_label} : #{line}"
30
+ Invoker::Logger.puts plain_line
29
31
  if tail_watchers && !tail_watchers.empty?
30
32
  json_encoded_tail_response = tail_response(color_line)
31
33
  if json_encoded_tail_response
32
34
  tail_watchers.each { |tail_socket| send_data(tail_socket, json_encoded_tail_response) }
33
35
  end
34
- else
35
- Invoker::Logger.puts color_line
36
36
  end
37
37
  end
38
38
 
@@ -37,7 +37,11 @@ module Invoker
37
37
  unix_server_thread = Thread.new { Invoker::IPC::Server.new }
38
38
  @thread_group.add(unix_server_thread)
39
39
  process_manager.run_power_server
40
- Invoker.config.autorunnable_processes.each { |process_info| process_manager.start_process(process_info) }
40
+ Invoker.config.autorunnable_processes.each do |process_info|
41
+ process_manager.start_process(process_info)
42
+ Logger.puts("Starting process - #{process_info.label} waiting for #{process_info.sleep_duration} seconds...")
43
+ sleep(process_info.sleep_duration)
44
+ end
41
45
  at_exit { process_manager.kill_workers }
42
46
  start_event_loop
43
47
  end
@@ -42,7 +42,8 @@ module Invoker
42
42
  end
43
43
 
44
44
  def autorunnable_processes
45
- processes.reject(&:disable_autorun)
45
+ process_to_run = processes.reject(&:disable_autorun)
46
+ process_to_run.sort_by { |process| process.index }
46
47
  end
47
48
 
48
49
  def process(label)
@@ -52,7 +53,7 @@ module Invoker
52
53
  private
53
54
 
54
55
  def autodetect_config_file
55
- Dir.glob("{invoker.ini,Procfile}").first
56
+ Dir.glob("{invoker.ini,Procfile.dev,Procfile}").first
56
57
  end
57
58
 
58
59
  def invalid_config_file?
@@ -123,6 +124,20 @@ module Invoker
123
124
  }
124
125
  pconfig['port'] = section['port'] if section['port']
125
126
  pconfig['disable_autorun'] = section['disable_autorun'] if section['disable_autorun']
127
+ pconfig['index'] = section['index'].to_i if section['index']
128
+ section_index = pconfig['index'].to_i
129
+ if section_index
130
+ pconfig['index'] = section_index
131
+ else
132
+ pconfig['index'] = 0
133
+ end
134
+
135
+ sleep_duration = section['sleep'].to_i
136
+ if sleep_duration > 0
137
+ pconfig['sleep_duration'] = sleep_duration
138
+ else
139
+ pconfig['sleep_duration'] = 1
140
+ end
126
141
 
127
142
  OpenStruct.new(pconfig)
128
143
  end
@@ -41,7 +41,7 @@ module Invoker
41
41
 
42
42
  def initialize
43
43
  @header = {}
44
- header['Server'] = "Invoker 1.1"
44
+ header['Server'] = "Invoker #{Invoker::VERSION}"
45
45
  header['Date'] = Time.now.httpdate
46
46
  @status = 200
47
47
  @body = ""
@@ -88,6 +88,11 @@ module Invoker
88
88
 
89
89
  def load_env(directory = nil)
90
90
  directory ||= ENV['PWD']
91
+
92
+ if !directory || directory.empty? || !Dir.exist?(directory)
93
+ return {}
94
+ end
95
+
91
96
  default_env = File.join(directory, '.env')
92
97
  local_env = File.join(directory, '.env.local')
93
98
  env = {}
@@ -43,5 +43,5 @@ module Invoker
43
43
  Version.new(next_splits.join('.'))
44
44
  end
45
45
  end
46
- VERSION = "1.5.1"
46
+ VERSION = "1.5.3"
47
47
  end
@@ -27,7 +27,7 @@ describe "Invoker::Commander" do
27
27
  describe "#start_process" do
28
28
  describe "when not daemonized" do
29
29
  before do
30
- processes = [OpenStruct.new(:label => "foobar", :cmd => "foobar_command", :dir => ENV['HOME'])]
30
+ processes = [OpenStruct.new(:label => "foobar", :cmd => "foobar_command", :dir => ENV['HOME'], :sleep_duration => 2)]
31
31
  Invoker.config.stubs(:processes).returns(processes)
32
32
  Invoker.config.stubs(:autorunnable_processes).returns(processes)
33
33
  Invoker.stubs(:can_run_balancer?).returns(false)
@@ -61,7 +61,7 @@ describe "Invoker::Commander" do
61
61
 
62
62
  describe "when daemonized" do
63
63
  before do
64
- processes = [OpenStruct.new(:label => "foobar", :cmd => "foobar_command", :dir => ENV['HOME'])]
64
+ processes = [OpenStruct.new(:label => "foobar", :cmd => "foobar_command", :dir => ENV['HOME'], :sleep_duration => 2)]
65
65
  Invoker.config.stubs(:processes).returns(processes)
66
66
  Invoker.config.stubs(:autorunnable_processes).returns(processes)
67
67
  Invoker.stubs(:can_run_balancer?).returns(false)
@@ -102,8 +102,8 @@ describe "Invoker::Commander" do
102
102
  context 'autorun is disabled for a process' do
103
103
  before do
104
104
  @processes = [
105
- OpenStruct.new(:label => "foobar", :cmd => "foobar_command", :dir => ENV['HOME']),
106
- OpenStruct.new(:label => "panda", :cmd => "panda_command", :dir => ENV['HOME'], :disable_autorun => true)
105
+ OpenStruct.new(:label => "foobar", :cmd => "foobar_command", :dir => ENV['HOME'], :sleep_duration => 2),
106
+ OpenStruct.new(:label => "panda", :cmd => "panda_command", :dir => ENV['HOME'], :disable_autorun => true, :sleep_duration => 2)
107
107
  ]
108
108
  Invoker.config.stubs(:processes).returns(@processes)
109
109
  Invoker.config.stubs(:autorunnable_processes).returns([@processes.first])
@@ -216,6 +216,47 @@ command = bundle exec rails s -p $PORT
216
216
  file.unlink()
217
217
  end
218
218
  end
219
+
220
+ it "returns a list of processes that can by index" do
221
+ begin
222
+ file = Tempfile.new(["config", ".ini"])
223
+ config_data =<<-EOD
224
+ [postgres]
225
+ command = postgres -D /usr/local/var/postgres
226
+ index = 2
227
+ sleep = 5
228
+
229
+ [redis]
230
+ command = redis-server /usr/local/etc/redis.conf
231
+ disable_autorun = true
232
+ index = 3
233
+
234
+ [memcached]
235
+ command = /usr/local/opt/memcached/bin/memcached
236
+ disable_autorun = false
237
+ index = 5
238
+
239
+ [panda-api]
240
+ command = bundle exec rails s
241
+ disable_autorun = true
242
+ index = 4
243
+
244
+ [panda-auth]
245
+ command = bundle exec rails s -p $PORT
246
+ index = 1
247
+ EOD
248
+ file.write(config_data)
249
+ file.close
250
+
251
+ config = Invoker::Parsers::Config.new(file.path, 9000)
252
+ processes = config.autorunnable_processes
253
+ expect(processes.map(&:label)).to eq(['panda-auth', 'postgres', 'memcached'])
254
+ expect(processes[0].sleep_duration).to eq(1)
255
+ expect(processes[1].sleep_duration).to eq(5)
256
+ ensure
257
+ file.unlink()
258
+ end
259
+ end
219
260
  end
220
261
 
221
262
  describe "global config file" do
@@ -299,6 +340,10 @@ some_other_process: some_other_command
299
340
 
300
341
  config = Invoker::Parsers::Config.new(nil, 9000)
301
342
  expect(config.process("some_process").cmd).to eq("some_command")
343
+ processes = config.autorunnable_processes
344
+ process_1 = processes[0]
345
+ expect(process_1.sleep_duration).to eq(1)
346
+ expect(process_1.index).to eq(0)
302
347
  ensure
303
348
  File.delete(invoker_ini)
304
349
  File.delete(procfile)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invoker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hemant Kumar
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-08-07 00:00:00.000000000 Z
12
+ date: 2017-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '2.0'
34
+ version: 2.1.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '2.0'
41
+ version: 2.1.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: iniparse
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -358,4 +358,32 @@ rubygems_version: 2.5.1
358
358
  signing_key:
359
359
  specification_version: 4
360
360
  summary: Something small for Process management
361
- test_files: []
361
+ test_files:
362
+ - spec/invoker/cli/pinger_spec.rb
363
+ - spec/invoker/cli/tail_watcher_spec.rb
364
+ - spec/invoker/cli_spec.rb
365
+ - spec/invoker/command_worker_spec.rb
366
+ - spec/invoker/commander_spec.rb
367
+ - spec/invoker/config_spec.rb
368
+ - spec/invoker/daemon_spec.rb
369
+ - spec/invoker/event/manager_spec.rb
370
+ - spec/invoker/invoker_spec.rb
371
+ - spec/invoker/ipc/client_handler_spec.rb
372
+ - spec/invoker/ipc/dns_check_command_spec.rb
373
+ - spec/invoker/ipc/message/list_response_spec.rb
374
+ - spec/invoker/ipc/message_spec.rb
375
+ - spec/invoker/ipc/unix_client_spec.rb
376
+ - spec/invoker/power/balancer_spec.rb
377
+ - spec/invoker/power/config_spec.rb
378
+ - spec/invoker/power/http_parser_spec.rb
379
+ - spec/invoker/power/http_response_spec.rb
380
+ - spec/invoker/power/pf_migrate_spec.rb
381
+ - spec/invoker/power/port_finder_spec.rb
382
+ - spec/invoker/power/setup/linux_setup_spec.rb
383
+ - spec/invoker/power/setup/osx_setup_spec.rb
384
+ - spec/invoker/power/setup_spec.rb
385
+ - spec/invoker/power/url_rewriter_spec.rb
386
+ - spec/invoker/power/web_sockets_spec.rb
387
+ - spec/invoker/process_manager_spec.rb
388
+ - spec/invoker/reactor_spec.rb
389
+ - spec/spec_helper.rb