Module: Actions::ObservableAction
- Extended by:
- ApipieDSL::Module
- Defined in:
- app/lib/actions/observable_action.rb
Overview
# Action B which emits an event when it successfully finishes or fails. class B
include ::Actions::ObservableAction
execution_plan_hooks.use :emit_event_failure, :on => [:failure]
def self.event_names
super + [event_name_base + '_' + event_name_suffix(:failure)]
end
def emit_event_failure(plan)
emit_event(plan, :failure)
end
# ... rest ...
end
Defined Under Namespace
Modules: ClassMethods Classes: Jail
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
51 52 53 54 55 |
# File 'app/lib/actions/observable_action.rb', line 51 def self.included(base) base.extend ClassMethods base.include ::Foreman::Observable base.execution_plan_hooks.use :emit_event, :on => :success end |
Instance Method Details
#emit_event(execution_plan, hook = :success) ⇒ Object
57 58 59 60 61 62 |
# File 'app/lib/actions/observable_action.rb', line 57 def emit_event(execution_plan, hook = :success) return unless root_action? trigger_hook "#{self.class.event_name_base}_#{self.class.event_name_suffix(hook)}", payload: event_payload(execution_plan) end |
#event_payload(_execution_plan) ⇒ Object
64 65 66 |
# File 'app/lib/actions/observable_action.rb', line 64 def event_payload(_execution_plan) { object: self } end |