Sha256: 699dd9fa3d278b5f55be7615e4eefd16971c980c093ff66779e12a638d106b07

Contents?: true

Size: 1.36 KB

Versions: 32

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

# Repeat the block until it returns a truthy value. Returns the value.
Puppet::Functions.create_function(:'ctrl::do_until') do
  # @param options A hash of additional options.
  # @param block The code block to repeat.
  # @option options [Numeric] limit The number of times to repeat the block.
  # @option options [Numeric] interval The number of seconds to wait before repeating the block.
  # @return [nil]
  # @example Run a task until it succeeds
  #   ctrl::do_until() || {
  #     run_task('test', $target, '_catch_errors' => true).ok()
  #   }
  # @example Run a task until it succeeds or fails 10 times
  #   ctrl::do_until('limit' => 10) || {
  #     run_task('test', $target, '_catch_errors' => true).ok()
  #   }
  # @example Run a task and wait 10 seconds before running it again
  #   ctrl::do_until('interval' => 10) || {
  #     run_task('test', $target, '_catch_errors' => true).ok()
  #   }
  dispatch :do_until do
    optional_param 'Hash[String[1], Any]', :options
    block_param
  end

  def do_until(options = {})
    # Send Analytics Report
    Puppet.lookup(:bolt_executor) {}&.report_function_call(self.class.name)

    limit = options['limit'] || 0
    interval = options['interval']

    i = 0
    until (x = yield)
      i += 1
      break if limit != 0 && i >= limit
      Kernel.sleep(interval) if interval
    end
    x
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
bolt-3.29.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.28.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.27.4 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.27.2 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.27.1 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.26.2 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.26.1 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.25.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.24.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.23.1 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.23.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.22.1 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.22.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.21.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.20.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.19.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.18.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.17.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.16.1 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.16.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb