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) @options = opts @queue = @options[:queue] @options[:log_path] ||= Dir.getwd @identity = @options[:identifier] || Magent::Utils.underscore(@options[: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 @options end |
Instance Method Details
#channel ⇒ Object
120 121 122 |
# File 'bin/magent', line 120 def channel @channel ||= (@options[:type] == :async) ? Magent::AsyncChannel.new(@queue) : Magent::ActorChannel.new(@queue) end |
#restart ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'bin/magent', line 111 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 @options[:daemonize] && @options[: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 |
# File 'bin/magent', line 98 def stop begin pid = File.read(pid_file).to_i Process.kill("QUIT", pid) 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 |