Class: RiderServer::Operations

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/rider_server/operations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

configure_logger, log, #log

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_queueObject (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

#sessionsObject (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.full_message)
  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_sessionObject

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_exceptionsObject

Exceptions



106
107
108
# File 'lib/rider_server/operations.rb', line 106

def toggle_capture_exceptions
  @config.capture_exceptions(!@config.capture_exceptions)
end