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 ?
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",
}
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': }
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.