Class: ErrorStalker::Store::InMemory
- Inherits:
-
Base
- Object
- Base
- 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)
-
- (Object) applications
readonly
All the applications that have seen exceptions.
-
- (Object) exception_groups
readonly
A hash of exceptions indexed by digest.
-
- (Object) exceptions
readonly
The list of exceptions reported so far.
-
- (Object) machines
readonly
All the machines that have seen exceptions.
Instance Method Summary (collapse)
-
- (Object) clear
Empty this exception store.
-
- (Boolean) empty?
Have we logged any exceptions?.
-
- (Object) find(id)
Find an exception report with the given id.
-
- (Object) group(digest)
returns the exception group matching digest.
-
- (InMemory) initialize
constructor
Creates a new instance of this store.
-
- (Object) recent
Return recent exceptions grouped by digest.
-
- (Object) reports_in_group(digest)
Returns a list of exceptions whose digest is digest.
-
- (Object) search(params = {})
Searches for exception reports maching params.
-
- (Object) store(exception_report)
Store exception_report in the exception list.
- - (Object) total
- - (Object) total_since(timestamp)
Methods inherited from Base
Constructor Details
- (InMemory) initialize
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
- (Object) applications (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 |
- (Object) exception_groups (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 |
- (Object) exceptions (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 |
- (Object) machines (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
- (Object) clear
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 |
- (Boolean) empty?
Have we logged any exceptions?
75 76 77 |
# File 'lib/error_stalker/store/in_memory.rb', line 75 def empty? exceptions.empty? end |
- (Object) find(id)
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 |
- (Object) group(digest)
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 |
- (Object) recent
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 |
- (Object) reports_in_group(digest)
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 |
- (Object) search(params = {})
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 |
- (Object) store(exception_report)
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 |
- (Object) total
89 90 91 |
# File 'lib/error_stalker/store/in_memory.rb', line 89 def total @exceptions.count end |
- (Object) total_since(timestamp)
93 94 95 |
# File 'lib/error_stalker/store/in_memory.rb', line 93 def total_since() @exceptions.select { |e| e. >= .to_s }.length end |