Class: Zebra::ProxyWorker
- Inherits:
-
Object
- Object
- Zebra::ProxyWorker
- Defined in:
- lib/zebra/proxy_worker.rb
Instance Attribute Summary collapse
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#log ⇒ Object
Returns the value of attribute log.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#workers ⇒ Object
Returns the value of attribute workers.
Instance Method Summary collapse
- #dispatch ⇒ Object
-
#initialize(config = {}) ⇒ ProxyWorker
constructor
A new instance of ProxyWorker.
Constructor Details
#initialize(config = {}) ⇒ ProxyWorker
Returns a new instance of ProxyWorker.
94 95 96 97 98 99 |
# File 'lib/zebra/proxy_worker.rb', line 94 def initialize(config = {}) @log = config[:logger] || Logger.new(STDERR) @workers = config[:workers] || 10 @timeout = config[:timeout] || 3600 @app_name = config[:app_name] || File.basename($0.split(/ /)[0], '.rb') end |
Instance Attribute Details
#app_name ⇒ Object
Returns the value of attribute app_name.
92 93 94 |
# File 'lib/zebra/proxy_worker.rb', line 92 def app_name @app_name end |
#log ⇒ Object
Returns the value of attribute log.
92 93 94 |
# File 'lib/zebra/proxy_worker.rb', line 92 def log @log end |
#timeout ⇒ Object
Returns the value of attribute timeout.
92 93 94 |
# File 'lib/zebra/proxy_worker.rb', line 92 def timeout @timeout end |
#workers ⇒ Object
Returns the value of attribute workers.
92 93 94 |
# File 'lib/zebra/proxy_worker.rb', line 92 def workers @workers end |
Instance Method Details
#dispatch ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/zebra/proxy_worker.rb', line 101 def dispatch params = { :workers => @workers, :app_name => @app_name, :logger => @log, :timeout => @timeout } params[:stdout_path] = Zebra.config.log_file if Zebra.config.log_file? params[:stderr_path] = Zebra.config.log_file if Zebra.config.log_file? workers = Preforker.new(params) do |master| config = {:logger => @log} handler = ProxyWorkerReceiveMessageHandler.new(config) while master.wants_me_alive? do EM.synchrony do master.logger.info "Server started..." timer = EventMachine::PeriodicTimer.new(5) do master.logger.info "ping #{Process.pid}" end context = EM::ZeroMQ::Context.new(1) # connection_pool = EM::Synchrony::ConnectionPool.new(:size => 1) do socket = context.socket(ZMQ::REP, handler) socket.connect(Zebra.config.worker[:backend_uri]) # end end end end workers.run end |