Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ActiveJob adapters with pre-deserialized events and NULL serializer #1335

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 22 additions & 11 deletions rails_event_store/lib/rails_event_store/async_handler_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,32 @@

module RailsEventStore
module AsyncHandler
def self.with_defaults
with
end
class << self
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this was necessary change. Changing to class << self over self. made it harder to notice what really changed. A separate commit with only this change would be helpful in the future.

def with_defaults
with
end

def self.with(event_store: Rails.configuration.event_store, event_store_locator: nil, serializer: RubyEventStore::Serializers::YAML)
Module.new do
define_method :perform do |payload|
event_store = event_store_locator.call if event_store_locator
super(event_store.deserialize(serializer: serializer, **payload.symbolize_keys))
def with(event_store: Rails.configuration.event_store, event_store_locator: nil, serializer: RubyEventStore::Serializers::YAML)
Module.new do
define_method :perform do |payload|
event_store = event_store_locator.call if event_store_locator
record = AsyncHandler.event_from_payload(payload, event_store, serializer)
super(record)
end
end
end
end

def self.prepended(host_class)
host_class.prepend with_defaults
def prepended(host_class)
host_class.prepend with_defaults
end

# @return [Event] an event as deserialized from the payload
def event_from_payload(payload, event_store, serializer)
return payload if payload.kind_of?(RailsEventStore::Event)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't require Event objects in RES to be of this kind. It's likely they are but we accept anything that has the same interface as RES::Event.


payload_hash = payload.to_h.symbolize_keys
event_store.deserialize(serializer: serializer, **payload_hash)
end
end
end

Expand Down