Module: Easyop::Plugins::EventHandlers
- Defined in:
- lib/easyop/plugins/event_handlers.rb
Overview
Subscribes an operation class to handle domain events.
The handler operation receives the event payload merged into ctx, plus ctx.event (the Easyop::Events::Event object itself for sync dispatch).
Basic usage:
class SendOrderConfirmation < ApplicationOperation
plugin Easyop::Plugins::EventHandlers
on "order.placed"
def call
event = ctx.event # Easyop::Events::Event
order_id = ctx.order_id # payload keys merged into ctx
OrderMailer.confirm(order_id).deliver_later
end
end
Async dispatch (requires Easyop::Plugins::Async also installed):
class IndexOrder < ApplicationOperation
plugin Easyop::Plugins::Async, queue: "indexing"
plugin Easyop::Plugins::EventHandlers
on "order.*", async: true
on "inventory.**", async: true, queue: "low"
def call
# For async dispatch ctx.event_data is a Hash (serialized for ActiveJob).
# Reconstruct if needed: Easyop::Events::Event.new(**ctx.event_data)
SearchIndex.reindex(ctx.order_id)
end
end
Wildcard patterns:
"order.*" — matches order.placed, order.shipped (not order.payment.failed)
"warehouse.**" — matches warehouse.stock.updated, warehouse.zone.moved, etc.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Class Method Details
.install(base, **_options) ⇒ Object
44 45 46 |
# File 'lib/easyop/plugins/event_handlers.rb', line 44 def self.install(base, **) base.extend(ClassMethods) end |