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
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
56
|
# 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_success, :on => :success
base.execution_plan_hooks.use :emit_event_failure, :on => :failure
end
|
Instance Method Details
#emit_event(execution_plan, hook = :success) ⇒ Object
66
67
68
69
70
71
|
# File 'app/lib/actions/observable_action.rb', line 66
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
|
#emit_event_failure(execution_plan) ⇒ Object
62
63
64
|
# File 'app/lib/actions/observable_action.rb', line 62
def emit_event_failure(execution_plan)
emit_event(execution_plan, :failure)
end
|
#emit_event_success(execution_plan) ⇒ Object
58
59
60
|
# File 'app/lib/actions/observable_action.rb', line 58
def emit_event_success(execution_plan)
emit_event(execution_plan, :success)
end
|
#event_payload(_execution_plan) ⇒ Object
73
74
75
|
# File 'app/lib/actions/observable_action.rb', line 73
def event_payload(_execution_plan)
{ object: self }
end
|