Module: RailsTransactionalOutbox::OutboxModel

Extended by:
ActiveSupport::Concern
Defined in:
lib/rails_transactional_outbox/outbox_model.rb

Instance Method Summary collapse

Instance Method Details

#errorObject



88
89
90
# File 'lib/rails_transactional_outbox/outbox_model.rb', line 88

def error
  @error || error_class.constantize.new(error_message)
end

#event_typeObject



92
93
94
# File 'lib/rails_transactional_outbox/outbox_model.rb', line 92

def event_type
  RailsTransactionalOutbox::EventType.resolve_from_event_name(event_name).to_sym
end

#failed?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/rails_transactional_outbox/outbox_model.rb', line 72

def failed?
  failed_at.present?
end

#handle_error(raised_error, clock: Time, backoff_multiplier: 5) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rails_transactional_outbox/outbox_model.rb', line 76

def handle_error(raised_error, clock: Time, backoff_multiplier: 5)
  @error = raised_error
  self.error_class = raised_error.class
  self.error_message = raised_error.message
  self.failed_at = clock.current
  self.attempts ||= 0
  self.attempts += 1
  self.retry_at = clock.current.advance(
    seconds: RailsTransactionalOutbox::ExponentialBackoff.backoff_for(backoff_multiplier, attempts)
  )
end

#infer_modelObject



96
97
98
99
100
101
# File 'lib/rails_transactional_outbox/outbox_model.rb', line 96

def infer_model
  model_klass = resource_class.constantize
  model_klass.find(resource_id)
rescue ActiveRecord::RecordNotFound
  model_klass.new(id: resource_id) if RailsTransactionalOutbox::EventType.new(event_type).destroy?
end

#processed?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/rails_transactional_outbox/outbox_model.rb', line 68

def processed?
  processed_at.present?
end

#processing_latencyObject



103
104
105
106
107
# File 'lib/rails_transactional_outbox/outbox_model.rb', line 103

def processing_latency
  return unless processed?

  processed_at - created_at
end

#transformed_argumentsObject



60
61
62
# File 'lib/rails_transactional_outbox/outbox_model.rb', line 60

def transformed_arguments
  arguments.to_h.symbolize_keys
end

#transformed_changesetObject



64
65
66
# File 'lib/rails_transactional_outbox/outbox_model.rb', line 64

def transformed_changeset
  changeset.to_h.symbolize_keys
end