Class: Textus::Hooks::ErrorLog

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/hooks/error_log.rb

Overview

Bounded in-memory ring buffer of recent hook failures (errored and timed_out). Each row carries the audit ‘seq` observed at the time of failure so pulse can filter “errors since cursor”.

Constant Summary collapse

DEFAULT_CAPACITY =
256

Instance Method Summary collapse

Constructor Details

#initialize(capacity: DEFAULT_CAPACITY) ⇒ ErrorLog

Returns a new instance of ErrorLog.



9
10
11
12
13
# File 'lib/textus/hooks/error_log.rb', line 9

def initialize(capacity: DEFAULT_CAPACITY)
  @capacity = capacity
  @rows = []
  @mutex = Mutex.new
end

Instance Method Details

#record(seq:, event:, hook:, key:, error_class:, error_message:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/textus/hooks/error_log.rb', line 15

def record(seq:, event:, hook:, key:, error_class:, error_message:)
  row = {
    seq: seq, event: event, hook: hook, key: key,
    error_class: error_class, error_message: error_message,
    at: Time.now.utc.iso8601
  }
  @mutex.synchronize do
    @rows << row
    @rows.shift while @rows.size > @capacity
  end
end

#since(seq) ⇒ Object



27
28
29
# File 'lib/textus/hooks/error_log.rb', line 27

def since(seq)
  @mutex.synchronize { @rows.select { |r| r[:seq] > seq }.dup }
end