Module: Isono::Runner::RpcServer::EndpointBuilder::BuildMethods
- Defined in:
- lib/isono/runner/rpc_server.rb
Instance Method Summary collapse
- #concurrency(num) ⇒ Object
-
#job(command, run_cb = nil, fail_cb = nil, &blk) ⇒ Object
job ‘command1’, proc { # do somthing. }, proc { # do somthing on job failure. } job ‘command1’ do response.fail_cb { # do somthing on job failure. } sleep 10 end.
- #job_thread_pool(thread_pool) ⇒ Object
- #rpc(command, &blk) ⇒ Object
- #setup(endpoint_name, builder) ⇒ Object
Instance Method Details
#concurrency(num) ⇒ Object
83 84 85 86 |
# File 'lib/isono/runner/rpc_server.rb', line 83 def concurrency(num) raise ArgumentError unless num.is_a?(Fixnum) @concurrency = num end |
#job(command, run_cb = nil, fail_cb = nil, &blk) ⇒ Object
job ‘command1’, proc {
# do somthing.
}, proc {
# do somthing on job failure.
}
job ‘command1’ do
response.fail_cb {
# do somthing on job failure.
}
sleep 10
end
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/isono/runner/rpc_server.rb', line 60 def job(command, run_cb=nil, fail_cb=nil, &blk) app = if run_cb.is_a?(Proc) proc { if fail_cb.is_a?(Proc) response.fail_cb do self.instance_eval(&fail_cb) end end self.instance_eval(&run_cb) } elsif blk blk else raise ArgumentError, "callbacks were not set propery" end add(:job, command, &app) end |
#job_thread_pool(thread_pool) ⇒ Object
88 89 90 91 |
# File 'lib/isono/runner/rpc_server.rb', line 88 def job_thread_pool(thread_pool) raise ArgumentError unless thread_pool.is_a?(Isono::ThreadPool) @job_thread_pool = thread_pool end |
#rpc(command, &blk) ⇒ Object
79 80 81 |
# File 'lib/isono/runner/rpc_server.rb', line 79 def rpc(command, &blk) add(:rpc, command, &blk) end |
#setup(endpoint_name, builder) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/isono/runner/rpc_server.rb', line 93 def setup(endpoint_name, builder) app_builder = lambda { |builder_hooks| return nil if builder_hooks.empty? map_app = Rack::Map.new builder_hooks.each { |b| b.call(map_app, builder) } map_app } app = app_builder.call(@builders[:job]) if app builder.job_channel.register_endpoint(endpoint_name, Rack.build do run app end, {:concurrency=>@concurrency, :thread_pool=>@job_thread_pool}) end app = app_builder.call(@builders[:rpc]) if app builder.rpc_channel.register_endpoint(endpoint, Rack.build do run app end, {:prefetch=>@concurrency}) end end |