Class: Kitchen::Instance::ActionRunner
- Inherits:
-
Object
- Object
- Kitchen::Instance::ActionRunner
- Defined in:
- lib/kitchen/instance.rb
Overview
Coordinates one instance action, including state persistence, plugin serialization, and failure wrapping.
Instance Method Summary collapse
-
#call(what) { ... } ⇒ void
private
Runs one instance action, wrapping it in structured logging metadata and benchmarking, and serializing it when the action is registered as non-concurrent.
-
#initialize(instance, state_file) ⇒ ActionRunner
constructor
A new instance of ActionRunner.
Constructor Details
#initialize(instance, state_file) ⇒ ActionRunner
Returns a new instance of ActionRunner.
654 655 656 657 |
# File 'lib/kitchen/instance.rb', line 654 def initialize(instance, state_file) @instance = instance @state_file = state_file end |
Instance Method Details
#call(what) { ... } ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Runs one instance action, wrapping it in structured logging metadata and benchmarking, and serializing it when the action is registered as non-concurrent.
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 |
# File 'lib/kitchen/instance.rb', line 669 def call(what, &block) state = nil begin state = state_file.read rescue ::StandardError => e log_failure(what, e) raise ActionFailed, "Failed to complete ##{what} action: [#{e.}]", e.backtrace end action_id = new_id session_id = state[:instance_session_id] || new_id instance.logger.( action: what.to_s, action_id:, instance_session_id: session_id, kitchen_run_id: Kitchen.run_id ) do elapsed = Benchmark.measure do synchronize_or_call(what, state, &block) end record_attempt(state, what, action_id, session_id) state[:last_action] = what.to_s state[:last_error] = nil elapsed rescue ActionFailed => e log_failure(what, e) record_attempt(state, what, action_id, session_id) state[:last_error] = e.class.name raise(InstanceFailure, (what) + " Please see .kitchen/logs/#{instance.name}.log for more details", e.backtrace) rescue ::StandardError => e log_failure(what, e) record_attempt(state, what, action_id, session_id) state[:last_error] = e.class.name raise ActionFailed, "Failed to complete ##{what} action: [#{e.}]", e.backtrace ensure state_file.write(state) end end |