Module: Isono::Runner::RpcServer::EndpointBuilder::BuildMethods

Defined in:
lib/isono/runner/rpc_server.rb

Instance Method Summary collapse

Instance Method Details

#build(endpoint, node) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/isono/runner/rpc_server.rb', line 77

def build(endpoint, node)
  helper_context = self.new(node)
  
  app_builder = lambda { |builders|
    unless builders.empty?
      map_app = Rack::Map.new
      builders.each { |b|
        b.call(map_app, helper_context)
      }
      map_app
    end
  }

  app = app_builder.call(@builders[:job])
  if app
    NodeModules::JobChannel.new(node).register_endpoint(endpoint, Rack.build do
                                                          run app
                                                        end)
  end
  
  app = app_builder.call(@builders[:rpc])
  if app
    NodeModules::RpcChannel.new(node).register_endpoint(endpoint, Rack.build do
                                                          use Rack::ThreadPass
                                                          run app
                                                        end
                                                        )
  end
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



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/isono/runner/rpc_server.rb', line 54

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

#rpc(command, &blk) ⇒ Object



73
74
75
# File 'lib/isono/runner/rpc_server.rb', line 73

def rpc(command, &blk)
  add(:rpc, command, &blk)
end