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
from zenaton.abstracts.event import Event class AddressUpdatedEvent(Event): def initialize(self, address): self.address = address
You can easily send an event to a workflow:
WelcomeFlow().where_id(email).send_event(AddressUpdatedEvent('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(self, event): if isinstance(event, AddressUpdatedEvent): self.address = event.address
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.)