Class: ErrorStalker::Store::InMemory
- Defined in:
- lib/error_stalker/store/in_memory.rb
Overview
The simplest exception store. This just stores each reported exception in a list held in memory. This, of course, means that the exception list will disappear when the server goes down, the server might take up tons of memory, and searching will probably be slow. In other words, this is a terrible choice for production. On the other hand, this store is especially useful for tests.
Instance Attribute Summary collapse
-
#applications ⇒ Object
readonly
All the applications that have seen exceptions.
-
#exception_groups ⇒ Object
readonly
A hash of exceptions indexed by digest.
-
#exceptions ⇒ Object
readonly
The list of exceptions reported so far.
-
#machines ⇒ Object
readonly
All the machines that have seen exceptions.
Instance Method Summary collapse
-
#clear ⇒ Object
Empty this exception store.
-
#empty? ⇒ Boolean
Have we logged any exceptions?.
-
#find(id) ⇒ Object
Find an exception report with the given id.
-
#group(digest) ⇒ Object
returns the exception group matching
digest
. -
#initialize ⇒ InMemory
constructor
Creates a new instance of this store.
-
#recent ⇒ Object
Return recent exceptions grouped by digest.
-
#reports_in_group(digest) ⇒ Object
Returns a list of exceptions whose digest is
digest
. -
#search(params = {}) ⇒ Object
Searches for exception reports maching
params
. -
#store(exception_report) ⇒ Object
Store
exception_report
in the exception list. - #total ⇒ Object
- #total_since(timestamp) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize ⇒ InMemory
Creates a new instance of this store.
26 27 28 |
# File 'lib/error_stalker/store/in_memory.rb', line 26 def initialize clear end |
Instance Attribute Details
#applications ⇒ Object (readonly)
All the applications that have seen exceptions
23 24 25 |
# File 'lib/error_stalker/store/in_memory.rb', line 23 def applications @applications end |
#exception_groups ⇒ Object (readonly)
A hash of exceptions indexed by digest.
17 18 19 |
# File 'lib/error_stalker/store/in_memory.rb', line 17 def exception_groups @exception_groups end |
#exceptions ⇒ Object (readonly)
The list of exceptions reported so far.
14 15 16 |
# File 'lib/error_stalker/store/in_memory.rb', line 14 def exceptions @exceptions end |
#machines ⇒ Object (readonly)
All the machines that have seen exceptions
20 21 22 |
# File 'lib/error_stalker/store/in_memory.rb', line 20 def machines @machines end |
Instance Method Details
#clear ⇒ Object
Empty this exception store. Useful for tests!
53 54 55 56 57 58 |
# File 'lib/error_stalker/store/in_memory.rb', line 53 def clear @exceptions = [] @exception_groups = {} @machines = Set.new @applications = Set.new end |
#empty? ⇒ Boolean
Have we logged any exceptions?
76 77 78 |
# File 'lib/error_stalker/store/in_memory.rb', line 76 def empty? exceptions.empty? end |
#find(id) ⇒ Object
Find an exception report with the given id.
71 72 73 |
# File 'lib/error_stalker/store/in_memory.rb', line 71 def find(id) exceptions[id.to_i] end |
#group(digest) ⇒ Object
returns the exception group matching digest
48 49 50 |
# File 'lib/error_stalker/store/in_memory.rb', line 48 def group(digest) build_group_for_exceptions(reports_in_group(digest)) end |
#recent ⇒ Object
Return recent exceptions grouped by digest.
81 82 83 84 85 86 87 88 |
# File 'lib/error_stalker/store/in_memory.rb', line 81 def recent data = [] exception_groups.map do |digest, group| data << build_group_for_exceptions(group) end data.reverse end |
#reports_in_group(digest) ⇒ Object
Returns a list of exceptions whose digest is digest
.
43 44 45 |
# File 'lib/error_stalker/store/in_memory.rb', line 43 def reports_in_group(digest) exception_groups[digest] end |
#search(params = {}) ⇒ Object
Searches for exception reports maching params
.
61 62 63 64 65 66 67 68 |
# File 'lib/error_stalker/store/in_memory.rb', line 61 def search(params = {}) results = exceptions results = results.select {|e| e.machine == params[:machine]} if params[:machine] && !params[:machine].empty? results = results.select {|e| e.application == params[:application]} if params[:application] && !params[:application].empty? results = results.select {|e| e.exception.to_s =~ /#{params[:exception]}/} if params[:exception] && !params[:exception].empty? results = results.select {|e| e.type.to_s =~ /#{params[:type]}/} if params[:type] && !params[:type].empty? results.reverse end |
#store(exception_report) ⇒ Object
Store exception_report
in the exception list. This also indexes the exception into the appropriate exception group.
32 33 34 35 36 37 38 39 40 |
# File 'lib/error_stalker/store/in_memory.rb', line 32 def store(exception_report) @exceptions << exception_report self.machines << exception_report.machine self.applications << exception_report.application exception_report.id = exceptions.length - 1 exception_groups[exception_report.digest] ||= [] exception_groups[exception_report.digest] << exception_report exception_report.id end |
#total ⇒ Object
90 91 92 |
# File 'lib/error_stalker/store/in_memory.rb', line 90 def total @exceptions.count end |
#total_since(timestamp) ⇒ Object
94 95 96 |
# File 'lib/error_stalker/store/in_memory.rb', line 94 def total_since() @exceptions.select { |e| e. >= .to_s }.length end |