Class: Bolt::Rerun
- Inherits:
-
Object
- Object
- Bolt::Rerun
- Defined in:
- lib/bolt/rerun.rb
Instance Method Summary collapse
- #data ⇒ Object
- #get_targets(filter) ⇒ Object
-
#initialize(path, save_failures) ⇒ Rerun
constructor
A new instance of Rerun.
- #update(result_set) ⇒ Object
Constructor Details
Instance Method Details
#data ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/bolt/rerun.rb', line 14 def data @data ||= Bolt::Util.read_json_file(@path, 'rerun') unless @data.is_a?(Array) && @data.all? { |r| r['target'] && r['status'] } raise Bolt::FileError.new("Missing data in rerun file: #{@path}", @path) end @data end |
#get_targets(filter) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bolt/rerun.rb', line 22 def get_targets(filter) filtered = case filter when 'all' data when 'failure' data.select { |result| result['status'] == 'failure' } when 'success' data.select { |result| result['status'] == 'success' } else raise Bolt::CLIError, "Unexpected option #{filter} for '--retry'" end filtered.map { |result| result['target'] } end |
#update(result_set) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bolt/rerun.rb', line 36 def update(result_set) unless @save_failures == false if result_set.is_a?(Bolt::PlanResult) result_set = result_set.value result_set = result_set.result_set if result_set.is_a?(Bolt::RunFailure) end if result_set.is_a?(Bolt::ResultSet) data = result_set.map { |res| { target: res.target.name, status: res.status } } FileUtils.mkdir_p(File.dirname(@path)) File.write(@path, data.to_json) elsif File.exist?(@path) FileUtils.rm(@path) end end rescue StandardError => e Bolt::Logger.warn_once("unwriteable_file", "Failed to save result to #{@path}: #{e.}") end |