[pve-devel] [PATCH common] add upid_wait method
Thomas Lamprecht
t.lamprecht at proxmox.com
Wed Jan 27 13:15:05 CET 2016
Waits for a process identified by a UPID to end by busy waiting
and is intended for long running workers.
waitfunc gets called every wait cycle after min $sleep_interval
seconds and can be used for outputting/logging something or timing
out the wait.
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
changes:
* move to ProcFSTools to avoid cyclic dependencies
src/PVE/ProcFSTools.pm | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/src/PVE/ProcFSTools.pm b/src/PVE/ProcFSTools.pm
index 99f767a..516c0e8 100644
--- a/src/PVE/ProcFSTools.pm
+++ b/src/PVE/ProcFSTools.pm
@@ -352,4 +352,24 @@ sub read_proc_net_ipv6_route {
return $res;
}
+sub upid_wait {
+ my ($upid, $waitfunc, $sleep_intervall) = @_;
+
+ my $task = PVE::Tools::upid_decode($upid);
+
+ $sleep_intervall = $sleep_intervall ? $sleep_intervall : 1;
+
+ my $next_time = time + $sleep_intervall;
+
+ while (check_process_running($task->{pid}, $task->{pstart})) {
+
+ if (time >= $next_time && $waitfunc && ref($waitfunc) eq 'CODE'){
+ &$waitfunc($task);
+ $next_time = time + $sleep_intervall;
+ }
+
+ CORE::sleep(1);
+ }
+}
+
1;
--
2.1.4
More information about the pve-devel
mailing list