Module: Dionysus::Producer::Outbox::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/dionysus/producer/outbox/model.rb
Class Method Summary collapse
Instance Method Summary collapse
- #created_event? ⇒ Boolean
- #error ⇒ Object
- #failed? ⇒ Boolean
- #handle_error(raised_error, clock: Time) ⇒ Object
- #observer? ⇒ Boolean
- #published? ⇒ Boolean
- #publishing_latency ⇒ Object
- #resource_created_at ⇒ Object
- #transformed_changeset ⇒ Object
- #updated_event? ⇒ Boolean
Class Method Details
.observer_topic ⇒ Object
10 11 12 |
# File 'lib/dionysus/producer/outbox/model.rb', line 10 def self.observer_topic OBSERVER_TOPIC end |
Instance Method Details
#created_event? ⇒ Boolean
100 101 102 |
# File 'lib/dionysus/producer/outbox/model.rb', line 100 def created_event? event_name.to_s.end_with?("created") end |
#error ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/dionysus/producer/outbox/model.rb', line 80 def error if error_class_arity == 1 || error_class_arity == -1 error_class.constantize.new() else StandardError.new("#{error_class_constant}: #{}") end end |
#failed? ⇒ Boolean
65 66 67 |
# File 'lib/dionysus/producer/outbox/model.rb', line 65 def failed? failed_at.present? end |
#handle_error(raised_error, clock: Time) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/dionysus/producer/outbox/model.rb', line 69 def handle_error(raised_error, clock: Time) @error = raised_error self.error_class = raised_error.class self. = raised_error. self.failed_at = clock.current self.attempts ||= 0 self.attempts += 1 self.retry_at = clock.current.advance(seconds: Dionysus::Utils::ExponentialBackoff.backoff_for(5, attempts)) end |
#observer? ⇒ Boolean
47 48 49 |
# File 'lib/dionysus/producer/outbox/model.rb', line 47 def observer? topic == Dionysus::Producer::Outbox::Model.observer_topic end |
#published? ⇒ Boolean
61 62 63 |
# File 'lib/dionysus/producer/outbox/model.rb', line 61 def published? published_at.present? end |
#publishing_latency ⇒ Object
94 95 96 97 98 |
# File 'lib/dionysus/producer/outbox/model.rb', line 94 def publishing_latency return unless published? published_at - created_at end |
#resource_created_at ⇒ Object
88 89 90 91 92 |
# File 'lib/dionysus/producer/outbox/model.rb', line 88 def resource_created_at return created_at if resource.nil? resource.created_at end |
#transformed_changeset ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/dionysus/producer/outbox/model.rb', line 51 def transformed_changeset return {} unless self.class.handles_changeset? if changeset.respond_to?(:to_hash) changeset.symbolize_keys else JSON.parse(changeset).symbolize_keys end end |
#updated_event? ⇒ Boolean
104 105 106 |
# File 'lib/dionysus/producer/outbox/model.rb', line 104 def updated_event? event_name.to_s.end_with?("updated") end |