Class: Controller
- Inherits:
-
Object
- Object
- Controller
- Defined in:
- bin/magent
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #channel ⇒ Object
-
#initialize(opts) ⇒ Controller
constructor
A new instance of Controller.
- #restart ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(opts) ⇒ Controller
Returns a new instance of Controller.
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'bin/magent', line 77 def initialize(opts) = opts @queue = [:queue] [:log_path] ||= Dir.getwd @identity = [:identifier] || Magent::Utils.underscore([:queue].to_s) @identity << "-#{Socket.gethostname.split('.')[0]}" $stderr.puts ">> Starting magent in #{@options[:type]} model" end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
75 76 77 |
# File 'bin/magent', line 75 def end |
Instance Method Details
#channel ⇒ Object
122 123 124 |
# File 'bin/magent', line 122 def channel @channel ||= ([:type] == :async) ? Magent::AsyncChannel.new(@queue) : Magent::ActorChannel.new(@queue) end |
#restart ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'bin/magent', line 113 def restart begin stop rescue => e $stderr.puts "Warning: #{e}" end start end |
#start ⇒ Object
90 91 92 93 94 95 96 |
# File 'bin/magent', line 90 def start if [:daemonize] && [:piddir] run_as_daemon else Magent::Processor.new(self.channel, @identity).run! end end |
#stop ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'bin/magent', line 98 def stop begin pid = File.read(pid_file).to_i Process.kill("TERM", pid) Process.kill(0, pid) Process.wait rescue Errno::ECHILD, Errno::ESRCH => e $stdout.puts "Process #{pid} has stopped" rescue Errno::ENOENT => e $stdout.puts "Warning: #{e}" ensure File.unlink(pid_file) if File.exist?(pid_file) end end |