class ChefApply::Action::Base
Derive new Actions from Action::Base
“target_host” is a TargetHost
that the action is being applied to. May be nil
if the action does not require a target.
“config” is hash containing any options that your command may need
Implement perform_action
to perform whatever action your class is intended to do. Run time will be captured via telemetry and categorized under “:action” with the unqualified class name of your Action
.
Attributes
config[R]
target_host[R]
Public Class Methods
new(config = {})
click to toggle source
# File lib/chef_apply/action/base.rb, line 34 def initialize(config = {}) c = config.dup @target_host = c.delete :target_host # Remaining options are for child classes to make use of. @config = c end
Public Instance Methods
name()
click to toggle source
# File lib/chef_apply/action/base.rb, line 58 def name self.class.name.split("::").last end
notify(action, *args)
click to toggle source
# File lib/chef_apply/action/base.rb, line 66 def notify(action, *args) return if @notification_handler.nil? ChefApply::Log.debug("[#{self.class.name}] Action: #{action}, Action Data: #{args}") @notification_handler.call(action, args) if @notification_handler end
perform_action()
click to toggle source
# File lib/chef_apply/action/base.rb, line 62 def perform_action raise NotImplemented end
run(&block)
click to toggle source
# File lib/chef_apply/action/base.rb, line 41 def run(&block) @notification_handler = block Telemeter.timed_action_capture(self) do perform_action rescue StandardError => e # Give the caller a chance to clean up - if an exception is # raised it'll otherwise get routed through the executing thread, # providing no means of feedback for the caller's current task. notify(:error, e) @error = e end # Raise outside the block to ensure that the telemetry cpature completes raise @error unless @error.nil? end