Class: Journaled::Writer

Inherits:
Object
  • Object
show all
Defined in:
app/models/journaled/writer.rb

Constant Summary collapse

EVENT_METHOD_NAMES =
i(
  journaled_schema_name
  journaled_partition_key
  journaled_attributes
  journaled_app_name
).freeze

Instance Method Summary collapse

Constructor Details

#initialize(journaled_event:, priority: Journaled::JobPriority::EVENTUAL) ⇒ Writer

Returns a new instance of Writer.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/journaled/writer.rb', line 9

def initialize(journaled_event:, priority: Journaled::JobPriority::EVENTUAL)
  raise "An enqueued event must respond to: #{EVENT_METHOD_NAMES.to_sentence}" unless respond_to_all?(journaled_event, EVENT_METHOD_NAMES)

  unless journaled_event.journaled_schema_name.present? &&
      journaled_event.journaled_partition_key.present? &&
      journaled_event.journaled_attributes.present?
    raise "      An enqueued event must have a non-nil response to:\n        #json_schema_name,\n        #partition_key, and\n        #journaled_attributes\n    ERROR\n  end\n\n  @journaled_event = journaled_event\n  @priority = priority\nend\n"

Instance Method Details

#journal!Object



27
28
29
30
31
# File 'app/models/journaled/writer.rb', line 27

def journal!
  base_event_json_schema_validator.validate! serialized_event
  json_schema_validator.validate! serialized_event
  Delayed::Job.enqueue journaled_delivery, priority: priority
end