Module: Mixins::InstanceMethods

Defined in:
lib/puppet/type/wait_for.rb

Instance Method Summary collapse

Instance Method Details

#retrieveObject

Defining a retrieve method seems to stop Puppet looking for an getter method in the provider.

The idea is copied from the Exec type.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/puppet/type/wait_for.rb', line 16

def retrieve

  # See comments about how this works by Daniel Pittman in the Exec
  # Puppet source code.
  #
  if @resource.check_all_attributes
    return :notrun
  else
    return self.should
  end
end

#syncObject

Defining a sync method seems to stop Puppet looking for an setter method in the provider.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/puppet/type/wait_for.rb', line 31

def sync
  tries = self.resource[:max_retries]
  polling_frequency = self.resource[:polling_frequency]

  begin
    tries.times do |try|

      # Only add debug messages for tries > 1 to reduce log spam.
      #
      debug("Wait_for try #{try+1}/#{tries}") if tries > 1
      @output = provider.run(self.resource[:query])

      if self.class == Puppet::Type::Wait_for::Exit_code
        break if self.should.include?(@output.exitstatus.to_i)
      elsif self.class == Puppet::Type::Wait_for::Regex
        break if @output =~ /#{self.should}/
      end

      if polling_frequency > 0 and tries > 1
        debug("Sleeping for #{polling_frequency} seconds between tries")
        sleep polling_frequency
      end
    end
  rescue Timeout::Error
    self.fail Puppet::Error, "Query exceeded timeout", $!
  end
end