-
Notifications
You must be signed in to change notification settings - Fork 125
Description
Every layer from Broker->Scheduler passes a triple of (subscriber, event, event_record)
, but the very last step hides the event object and only passes the serializ(ed/able) record to custom schedulers:
rails_event_store/rails_event_store/lib/rails_event_store/after_commit_async_dispatcher.rb
Lines 9 to 11 in e7ede7d
def call(subscriber, _, record) | |
run { @scheduler.call(subscriber, record) } | |
end |
This is a problem for me because I'd like to run a predicate on the event in my custom scheduler before enqueueing a job. My specific use case involves a fairly frequent event, where only a tiny percentage are actually relevant to a given subscriber.
How I'm working around this
Monkey patch AfterCommitAsyncDispatcher in an initializer:
class RailsEventStore::AfterCommitAsyncDispatcher
def call(subscriber, event, record)
run { @scheduler.call(subscriber, event, record) }
end
end
Suggested patch
The existing API contract is obviously for 2 arguments only. I know arity checking is usually frowned upon, but I feel like it's an acceptable trade-off here:
class AfterCommitAsyncDispatcher
def initialize(scheduler:)
@scheduler = scheduler
@scheduler_arity = scheduler.method(:call).arity
end
def call(subscriber, event, record)
run { @scheduler_arity === 3 ? @scheduler.call(subscriber, event, record) : @scheduler.call(subscriber, record) }
end
end
What do you think? Should this be changed? Would the change be breaking or something that could happen in the 2.x series?