invoker 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.rubocop.yml +30 -0
  4. data/.travis.yml +1 -0
  5. data/Gemfile +1 -0
  6. data/bin/invoker +4 -8
  7. data/invoker.gemspec +10 -11
  8. data/lib/invoker.rb +95 -21
  9. data/lib/invoker/cli.rb +126 -0
  10. data/lib/invoker/cli/pinger.rb +23 -0
  11. data/lib/invoker/cli/question.rb +15 -0
  12. data/lib/invoker/cli/tail.rb +34 -0
  13. data/lib/invoker/cli/tail_watcher.rb +34 -0
  14. data/lib/invoker/command_worker.rb +28 -2
  15. data/lib/invoker/commander.rb +34 -236
  16. data/lib/invoker/config.rb +5 -0
  17. data/lib/invoker/daemon.rb +126 -0
  18. data/lib/invoker/dns_cache.rb +23 -0
  19. data/lib/invoker/errors.rb +1 -0
  20. data/lib/invoker/ipc.rb +45 -0
  21. data/lib/invoker/ipc/add_command.rb +12 -0
  22. data/lib/invoker/ipc/add_http_command.rb +10 -0
  23. data/lib/invoker/ipc/base_command.rb +24 -0
  24. data/lib/invoker/ipc/client_handler.rb +26 -0
  25. data/lib/invoker/ipc/dns_check_command.rb +16 -0
  26. data/lib/invoker/ipc/list_command.rb +11 -0
  27. data/lib/invoker/ipc/message.rb +170 -0
  28. data/lib/invoker/ipc/message/list_response.rb +33 -0
  29. data/lib/invoker/ipc/message/tail_response.rb +10 -0
  30. data/lib/invoker/ipc/ping_command.rb +10 -0
  31. data/lib/invoker/ipc/reload_command.rb +12 -0
  32. data/lib/invoker/ipc/remove_command.rb +12 -0
  33. data/lib/invoker/{command_listener → ipc}/server.rb +6 -11
  34. data/lib/invoker/ipc/tail_command.rb +11 -0
  35. data/lib/invoker/ipc/unix_client.rb +60 -0
  36. data/lib/invoker/parsers/config.rb +1 -0
  37. data/lib/invoker/power/balancer.rb +17 -7
  38. data/lib/invoker/power/config.rb +6 -3
  39. data/lib/invoker/power/dns.rb +22 -21
  40. data/lib/invoker/power/http_response.rb +1 -1
  41. data/lib/invoker/power/power.rb +3 -0
  42. data/lib/invoker/power/powerup.rb +3 -2
  43. data/lib/invoker/power/setup.rb +6 -4
  44. data/lib/invoker/process_manager.rb +187 -0
  45. data/lib/invoker/process_printer.rb +27 -38
  46. data/lib/invoker/reactor.rb +19 -38
  47. data/lib/invoker/reactor/reader.rb +53 -0
  48. data/lib/invoker/version.rb +1 -1
  49. data/readme.md +1 -1
  50. data/spec/invoker/cli/pinger_spec.rb +22 -0
  51. data/spec/invoker/cli/tail_watcher_spec.rb +39 -0
  52. data/spec/invoker/cli_spec.rb +27 -0
  53. data/spec/invoker/command_worker_spec.rb +30 -0
  54. data/spec/invoker/commander_spec.rb +57 -127
  55. data/spec/invoker/config_spec.rb +21 -0
  56. data/spec/invoker/daemon_spec.rb +34 -0
  57. data/spec/invoker/invoker_spec.rb +31 -0
  58. data/spec/invoker/ipc/client_handler_spec.rb +44 -0
  59. data/spec/invoker/ipc/dns_check_command_spec.rb +32 -0
  60. data/spec/invoker/ipc/message/list_response_spec.rb +22 -0
  61. data/spec/invoker/ipc/message_spec.rb +45 -0
  62. data/spec/invoker/ipc/unix_client_spec.rb +29 -0
  63. data/spec/invoker/power/setup_spec.rb +1 -1
  64. data/spec/invoker/process_manager_spec.rb +98 -0
  65. data/spec/invoker/reactor_spec.rb +6 -0
  66. data/spec/spec_helper.rb +15 -24
  67. metadata +107 -77
  68. data/lib/invoker/command_listener/client.rb +0 -45
  69. data/lib/invoker/parsers/option_parser.rb +0 -106
  70. data/lib/invoker/power.rb +0 -7
  71. data/lib/invoker/runner.rb +0 -98
  72. data/spec/invoker/command_listener/client_spec.rb +0 -52
@@ -1,7 +0,0 @@
1
- require "invoker/power/config"
2
- require "invoker/power/port_finder"
3
- require "invoker/power/setup"
4
- require "invoker/power/http_response"
5
- require "invoker/power/dns"
6
- require "invoker/power/balancer"
7
- require "invoker/power/powerup"
@@ -1,98 +0,0 @@
1
- require "slop"
2
- require "ostruct"
3
- require "socket"
4
-
5
- module Invoker
6
- class Runner
7
- def self.run(args)
8
- selected_command = Invoker::Parsers::OptionParser.parse(args)
9
- if selected_command
10
- run_command(selected_command)
11
- end
12
- end
13
-
14
- def self.run_command(selected_command)
15
- return unless selected_command
16
- case selected_command.command
17
- when 'version'
18
- emit_version
19
- when 'setup'
20
- setup_pow(selected_command)
21
- when 'uninstall'
22
- uninstall_pow(selected_command)
23
- when 'start'
24
- start_server(selected_command)
25
- when 'add'
26
- add_command(selected_command)
27
- when 'reload'
28
- refresh_command(selected_command)
29
- when 'list'
30
- list_commands(selected_command)
31
- when 'remove'
32
- remove_command(selected_command)
33
- else
34
- Invoker::Logger.puts "Invalid command"
35
- end
36
- end
37
-
38
- def self.emit_version
39
- Invoker::Logger.puts Invoker::VERSION
40
- end
41
-
42
- def self.setup_pow(selected_command)
43
- Invoker::Power::Setup.install()
44
- end
45
-
46
- def self.uninstall_pow(selected_command)
47
- Invoker::Power::Setup.uninstall()
48
- end
49
-
50
- def self.start_server(selected_command)
51
- config = Invoker::Parsers::Config.new(selected_command.file, selected_command.port)
52
- Invoker.const_set(:CONFIG, config)
53
- warn_about_terminal_notifier()
54
- commander = Invoker::Commander.new()
55
- Invoker.const_set(:COMMANDER, commander)
56
- commander.start_manager()
57
- end
58
-
59
- def self.add_command(selected_command)
60
- Socket.unix(Invoker::CommandListener::Server::SOCKET_PATH) do |socket|
61
- socket.puts("add #{selected_command.command_key}")
62
- socket.flush()
63
- end
64
- end
65
-
66
- def self.remove_command(selected_command)
67
- Socket.unix(Invoker::CommandListener::Server::SOCKET_PATH) do |socket|
68
- socket.puts("remove #{selected_command.command_key} #{selected_command.signal}")
69
- socket.flush()
70
- end
71
- end
72
-
73
- def self.refresh_command(selected_command)
74
- Socket.unix(Invoker::CommandListener::Server::SOCKET_PATH) do |socket|
75
- socket.puts("reload #{selected_command.command_key} #{selected_command.signal}")
76
- socket.flush()
77
- end
78
- end
79
-
80
- def self.list_commands(selected_command)
81
- Socket.unix(Invoker::CommandListener::Server::SOCKET_PATH) {|sock|
82
- sock.puts("list")
83
- data = sock.gets()
84
- Invoker::ProcessPrinter.print_table(data)
85
- }
86
- end
87
-
88
- def self.warn_about_terminal_notifier
89
- if RUBY_PLATFORM.downcase.include?("darwin")
90
- command_path = `which terminal-notifier`
91
- if !command_path || command_path.empty?
92
- Invoker::Logger.puts("You can enable OSX notification for processes by installing terminal-notifier gem".color(:red))
93
- end
94
- end
95
- end
96
-
97
- end
98
- end
@@ -1,52 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Invoker::CommandListener::Client do
4
- describe "add command" do
5
- before do
6
- @client_socket = mock()
7
- @client = Invoker::CommandListener::Client.new(@client_socket)
8
- end
9
-
10
- it "should run if read from socket" do
11
- invoker_commander.expects(:on_next_tick).with("foo")
12
- @client_socket.expects(:gets).returns("add foo\n")
13
-
14
- @client.read_and_execute()
15
- end
16
- end
17
-
18
- describe "remove command" do
19
- before do
20
- @client_socket = mock()
21
- @client = Invoker::CommandListener::Client.new(@client_socket)
22
- end
23
-
24
- it "with specific signal" do
25
- invoker_commander.expects(:on_next_tick).with("foo", "9")
26
- @client_socket.expects(:gets).returns("remove foo 9\n")
27
-
28
- @client.read_and_execute()
29
- end
30
-
31
- it "with default signal" do
32
- invoker_commander.expects(:on_next_tick).with("foo",nil)
33
- @client_socket.expects(:gets).returns("remove foo\n")
34
-
35
- @client.read_and_execute()
36
- end
37
- end
38
-
39
- describe "invalid command" do
40
- before do
41
- @client_socket = mock()
42
- @client = Invoker::CommandListener::Client.new(@client_socket)
43
- end
44
-
45
- it "should print error if read from socket" do
46
- invoker_commander.expects(:on_next_tick).never()
47
- @client_socket.expects(:gets).returns("eugh foo\n")
48
-
49
- @client.read_and_execute
50
- end
51
- end
52
- end