Events enable you to inject information into a running workflow instance. For example, if your e-commerce customer wants to change her delivery address it should be possible to do it even after the beginning of the delivery workflow.
An event must inherit from the
require 'zenaton' class AddressUpdatedEvent < Zenaton::Interfaces::Event attr_reader :address def initialize(address) @address = address end end
You can easily send an event to a workflow:
WelcomeFlow.where_id(email).send_event(AddressUpdatedEvent.new('One Infinite Loop Cupertino, CA 95014'))
Then the workflow instance will handle the event through an
on_event method that will receive the event object as a parameter. For example:
def on_event(event) @address = event.address if event.is_a?(AddressUpdatedEvent) end
on_eventmethod is called as soon the event is sent and an Agent is available to execute it.
Remember the workflow implementation MUST be idempotent. So the constraints on the
on_eventmethod are the same as the
handlemethod (it must implement a logical flow and NOT the tasks themselves.)