Class: Omnitrack::Audit::Recorder
- Inherits:
-
Object
- Object
- Omnitrack::Audit::Recorder
- Defined in:
- lib/omnitrack/audit/recorder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #fail!(error) ⇒ Object
- #finish(result) ⇒ Object
-
#initialize(operation, args) ⇒ Recorder
constructor
A new instance of Recorder.
Constructor Details
#initialize(operation, args) ⇒ Recorder
Returns a new instance of Recorder.
23 24 25 26 27 |
# File 'lib/omnitrack/audit/recorder.rb', line 23 def initialize(operation, args) @operation = operation.to_s @args = args @event = create_event! end |
Class Method Details
.available? ⇒ Boolean
16 17 18 19 20 21 |
# File 'lib/omnitrack/audit/recorder.rb', line 16 def self.available? return false unless defined?(ActiveRecord::Base) return false unless Omnitrack.config.dashboard_enabled Omnitrack::VisitEvent.table_exists? && Omnitrack::DeliveryStatus.table_exists? end |
.start(operation, args) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/omnitrack/audit/recorder.rb', line 8 def self.start(operation, args) return NullRecorder.new unless available? new(operation, args) rescue StandardError NullRecorder.new end |
Instance Method Details
#fail!(error) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/omnitrack/audit/recorder.rb', line 50 def fail!(error) @event&.update!( overall_status: "failure", completed_at: Time.current, context_json: safe_json(base_context.merge(dispatch_error: error.)) ) rescue StandardError # no-op end |
#finish(result) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/omnitrack/audit/recorder.rb', line 29 def finish(result) Array(result&.results).each do |adapter_result| Omnitrack::DeliveryStatus.create!( visit_event_id: @event.id, adapter_name: adapter_result.adapter.to_s.presence || "queue", status: adapter_result.status.to_s, error_message: adapter_result.error&., response_json: safe_json(adapter_result.data), metadata_json: safe_json(adapter_result.), sent_at: Time.current ) end @event.update!( overall_status: overall_status_from(result), completed_at: Time.current ) rescue StandardError # Never interrupt app flow because of dashboard persistence. end |