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

Class Method Details

.observer_topicObject



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

Returns:

  • (Boolean)


100
101
102
# File 'lib/dionysus/producer/outbox/model.rb', line 100

def created_event?
  event_name.to_s.end_with?("created")
end

#errorObject



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(error_message)
  else
    StandardError.new("#{error_class_constant}: #{error_message}")
  end
end

#failed?Boolean

Returns:

  • (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.error_message = raised_error.message
  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

Returns:

  • (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

Returns:

  • (Boolean)


61
62
63
# File 'lib/dionysus/producer/outbox/model.rb', line 61

def published?
  published_at.present?
end

#publishing_latencyObject



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_atObject



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_changesetObject



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

Returns:

  • (Boolean)


104
105
106
# File 'lib/dionysus/producer/outbox/model.rb', line 104

def updated_event?
  event_name.to_s.end_with?("updated")
end