Class: RiderServer::Services::CaptureExceptions

Inherits:
RiderServer::Service show all
Defined in:
lib/rider_server/services/capture_exceptions.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RiderServer::Service

service_name

Constructor Details

#initialize(session) ⇒ CaptureExceptions

Returns a new instance of CaptureExceptions.



54
55
56
# File 'lib/rider_server/services/capture_exceptions.rb', line 54

def initialize(session)
  @session = session
end

Class Method Details

.create_exception_wrapper(exception, metadata) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/rider_server/services/capture_exceptions.rb', line 31

def self.create_exception_wrapper(exception, )
  id = SecureRandom.uuid
  {
    "id" => id,
    "created_at" => DateTime.now,
    "exception" => exception,
    "metadata" => 
  }
end

.create_response(id, exception) ⇒ Object

Take an exception object created by the session and create a response to send back to the client



23
24
25
26
27
28
29
# File 'lib/rider_server/services/capture_exceptions.rb', line 23

def self.create_response(id, exception)
  {
    "id" => id,
    "rider/exception-id" => exception.id,
    "time-stamp" => Time.now.strftime("%Y-%m-%d %H:%M:%S")
  }
end

.handle_exception(exception, metadata: {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rider_server/services/capture_exceptions.rb', line 41

def self.handle_exception(exception, metadata: {})
  wrapped_ex = create_exception_wrapper(exception, )
  # Firstly this needs to generate wrapper for the exception
  # This needs to use push exception

  @sessions.each do |session, stream_id|
    ex = session.add_wrapped_exception(wrapped_ex)
    session.response_queue.push(create_response(stream_id, ex))
  end

  wrapped_ex
end

.sessionsObject



17
18
19
# File 'lib/rider_server/services/capture_exceptions.rb', line 17

def self.sessions
  @sessions
end

Instance Method Details

#start(stream_id) ⇒ Object



58
59
60
61
62
# File 'lib/rider_server/services/capture_exceptions.rb', line 58

def start(stream_id)
  @stream_id = stream_id
  self.class.sessions.push([@session, @stream_id])
  :running
end

#statusObject



69
70
71
72
73
74
75
# File 'lib/rider_server/services/capture_exceptions.rb', line 69

def status
  if self.class.sessions.find { |s| s[0] == @session }
    :running
  else
    :stopped
  end
end

#stopObject



64
65
66
67
# File 'lib/rider_server/services/capture_exceptions.rb', line 64

def stop
  self.class.sessions.delete_if { |s| s[0] == @session }
  :stopped
end