11

I would like to run a webservice and wait for a few seconds after to get the result.

What is the best way to achieve a wait in puppet ?

icn
  • 17,126
  • 39
  • 105
  • 141

3 Answers3

17

You could use the linux sleep command with exec and stage it to run after the web-service. something like :

exec { 'wait_for_my_web_service' :
  require => Service["my_web_service"],
  command => "sleep 10 && /run/my/command/to/get/results/from/the/web/service",
  path => "/usr/bin:/bin",
}
iamauser
  • 11,119
  • 5
  • 34
  • 52
0

My take on a local-only wait + configurable retry.

define wait_for_port ( $protocol = 'tcp', $retry = 10 ) {
  $port = $title
  exec { "wait-for-port${port}":
    command  => "until fuser ${port}/${protocol}; do i=\$[i+1]; [ \$i -gt ${retry} ] && break || sleep 1; done",
    provider => 'shell',
  }
}

wait_for_port { '3000': }
h0tw1r3
  • 6,618
  • 1
  • 28
  • 34
0

I have a class that executes a DSC resource, but required to wait for 20 seconds, before it executes it. Hence, I used an exec resource, relying on Powershell, just before the dsc resource:

$command = 'Start-Sleep -Seconds 20'
exec { 'wait_time':
    command   => $command,
    provider  => powershell,
    timeout   => 0,
    tries     => 3,
    try_sleep => 10
}

Of course you can either omit or change the tries and the try_sleep parameters.

silverbackbg
  • 183
  • 2
  • 15