Sha256: 8e704e40fde12b4ca3a63f1550067705e410a25ba4c32df6f0e33066210e5cb8

Contents?: true

Size: 1.3 KB

Versions: 31

Compression:

Stored size: 1.3 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.
  # @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.
  # @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

31 entries across 31 versions & 1 rubygems

Version Path
bolt-3.7.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.6.1 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.6.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.5.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.4.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.3.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.1.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.0.1 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-3.0.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.44.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.42.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.40.2 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.40.1 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.38.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.37.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.36.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.35.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.34.0 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.33.2 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb
bolt-2.33.1 bolt-modules/ctrl/lib/puppet/functions/ctrl/do_until.rb