Class: RiderServer::Operations
- Includes:
- Logger
- Defined in:
- lib/rider_server/operations.rb
Instance Attribute Summary collapse
-
#response_queue ⇒ Object
readonly
Returns the value of attribute response_queue.
-
#sessions ⇒ Object
readonly
Returns the value of attribute sessions.
Instance Method Summary collapse
- #add_session(session) ⇒ Object
- #delete_session(session_id) ⇒ Object
- #get_session(id) ⇒ Object
- #handle(request) ⇒ Object
-
#initialize(config, response_queue) ⇒ Operations
constructor
A new instance of Operations.
-
#new_session ⇒ Object
Sessions.
- #send_response(response) ⇒ Object
-
#toggle_capture_exceptions ⇒ Object
Exceptions.
Methods included from Logger
Constructor Details
#initialize(config, response_queue) ⇒ Operations
Returns a new instance of Operations.
41 42 43 44 45 |
# File 'lib/rider_server/operations.rb', line 41 def initialize(config, response_queue) @config = config @sessions = {} @response_queue = response_queue end |
Instance Attribute Details
#response_queue ⇒ Object (readonly)
Returns the value of attribute response_queue.
39 40 41 |
# File 'lib/rider_server/operations.rb', line 39 def response_queue @response_queue end |
#sessions ⇒ Object (readonly)
Returns the value of attribute sessions.
38 39 40 |
# File 'lib/rider_server/operations.rb', line 38 def sessions @sessions end |
Instance Method Details
#add_session(session) ⇒ Object
94 95 96 |
# File 'lib/rider_server/operations.rb', line 94 def add_session(session) @sessions[session.id] = session end |
#delete_session(session_id) ⇒ Object
98 99 100 |
# File 'lib/rider_server/operations.rb', line 98 def delete_session(session_id) @sessions.delete(session_id) end |
#get_session(id) ⇒ Object
89 90 91 92 |
# File 'lib/rider_server/operations.rb', line 89 def get_session(id) return nil unless id @sessions[id] end |
#handle(request) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rider_server/operations.rb', line 53 def handle(request) op = request.op log.info("Handling operation '#{request.inspect}'") session = get_session(request.session) if Operation.handles?(request) send_response(Operation.handle(self, request)) elsif !session.nil? && SessionOperation.handles?(request) send_response(SessionOperation.handle(session, request)) else log.warn("Unknown operation '#{op}' requested") response = Response.new(request) response.status "unknown-op", "done" send_response(response) end rescue ScriptError, StandardError => e response = Response.new(request) response.set("ex", e.inspect) response.set("out", e.) response.status("eval-error", "done") log.error "Error handling request: #{e}\n #{e.backtrace.join("\n")}" if session exception = session.add_exception(request.id, e) response.set("rider/exception-id", exception["id"]) end RiderServer::Services::CaptureExceptions.handle_exception(e) send_response(response) end |
#new_session ⇒ Object
Sessions
85 86 87 |
# File 'lib/rider_server/operations.rb', line 85 def new_session RiderServer.create_session(@config, @response_queue) end |
#send_response(response) ⇒ Object
47 48 49 50 51 |
# File 'lib/rider_server/operations.rb', line 47 def send_response(response) if response @response_queue.push(response) end end |
#toggle_capture_exceptions ⇒ Object
Exceptions
106 107 108 |
# File 'lib/rider_server/operations.rb', line 106 def toggle_capture_exceptions @config.capture_exceptions(!@config.capture_exceptions) end |