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.
25 26 27 |
# File 'lib/error_stalker/store/in_memory.rb', line 25 def initialize clear end |
Instance Attribute Details
#applications ⇒ Object (readonly)
All the applications that have seen exceptions
22 23 24 |
# File 'lib/error_stalker/store/in_memory.rb', line 22 def applications @applications end |
#exception_groups ⇒ Object (readonly)
A hash of exceptions indexed by digest.
16 17 18 |
# File 'lib/error_stalker/store/in_memory.rb', line 16 def exception_groups @exception_groups end |
#exceptions ⇒ Object (readonly)
The list of exceptions reported so far.
13 14 15 |
# File 'lib/error_stalker/store/in_memory.rb', line 13 def exceptions @exceptions end |
#machines ⇒ Object (readonly)
All the machines that have seen exceptions
19 20 21 |
# File 'lib/error_stalker/store/in_memory.rb', line 19 def machines @machines end |
Instance Method Details
#clear ⇒ Object
Empty this exception store. Useful for tests!
52 53 54 55 56 57 |
# File 'lib/error_stalker/store/in_memory.rb', line 52 def clear @exceptions = [] @exception_groups = {} @machines = Set.new @applications = Set.new end |
#empty? ⇒ Boolean
Have we logged any exceptions?
75 76 77 |
# File 'lib/error_stalker/store/in_memory.rb', line 75 def empty? exceptions.empty? end |
#find(id) ⇒ Object
Find an exception report with the given id.
70 71 72 |
# File 'lib/error_stalker/store/in_memory.rb', line 70 def find(id) exceptions[id.to_i] end |
#group(digest) ⇒ Object
returns the exception group matching digest
47 48 49 |
# File 'lib/error_stalker/store/in_memory.rb', line 47 def group(digest) build_group_for_exceptions(reports_in_group(digest)) end |
#recent ⇒ Object
Return recent exceptions grouped by digest.
80 81 82 83 84 85 86 87 |
# File 'lib/error_stalker/store/in_memory.rb', line 80 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
.
42 43 44 |
# File 'lib/error_stalker/store/in_memory.rb', line 42 def reports_in_group(digest) exception_groups[digest] end |
#search(params = {}) ⇒ Object
Searches for exception reports maching params
.
60 61 62 63 64 65 66 67 |
# File 'lib/error_stalker/store/in_memory.rb', line 60 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.
31 32 33 34 35 36 37 38 39 |
# File 'lib/error_stalker/store/in_memory.rb', line 31 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
89 90 91 |
# File 'lib/error_stalker/store/in_memory.rb', line 89 def total @exceptions.count end |
#total_since(timestamp) ⇒ Object
93 94 95 |
# File 'lib/error_stalker/store/in_memory.rb', line 93 def total_since() @exceptions.select { |e| e. >= .to_s }.length end |