mirror of
https://git.proxmox.com/git/pve-common
synced 2025-05-03 12:04:26 +00:00
allow workers to count warnings and finish tasks in a WARNINGS state
as is already supported by the UI (and PBS). A nice bonus is that warn() can be used by both workers and non-workers. For workers, the output is redirected/duplicated as set up by {fork,tee}_worker(), and non-erroring workers that issued a warning will end in a WARNINGS state. Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
parent
6b00e70cd1
commit
ff79ee6596
@ -115,7 +115,10 @@ sub init {
|
|||||||
# priv ... access from private server (pvedaemon)
|
# priv ... access from private server (pvedaemon)
|
||||||
# ha ... access from HA resource manager agent (pve-ha-manager)
|
# ha ... access from HA resource manager agent (pve-ha-manager)
|
||||||
|
|
||||||
my $self = { type => $type };
|
my $self = {
|
||||||
|
type => $type,
|
||||||
|
warning_count => 0,
|
||||||
|
};
|
||||||
|
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
@ -448,7 +451,6 @@ my $tee_worker = sub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# get status (error or OK)
|
|
||||||
POSIX::read($ctrlfd, $readbuf, 4096);
|
POSIX::read($ctrlfd, $readbuf, 4096);
|
||||||
if ($readbuf =~ m/^TASK OK\n?$/) {
|
if ($readbuf =~ m/^TASK OK\n?$/) {
|
||||||
# skip printing to stdout
|
# skip printing to stdout
|
||||||
@ -456,6 +458,9 @@ my $tee_worker = sub {
|
|||||||
} elsif ($readbuf =~ m/^TASK ERROR: (.*)\n?$/) {
|
} elsif ($readbuf =~ m/^TASK ERROR: (.*)\n?$/) {
|
||||||
print STDERR "$1\n";
|
print STDERR "$1\n";
|
||||||
print $taskfh "\n$readbuf"; # ensure start on new line for webUI
|
print $taskfh "\n$readbuf"; # ensure start on new line for webUI
|
||||||
|
} elsif ($readbuf =~ m/^TASK WARNINGS: (\d+)\n?$/) {
|
||||||
|
print STDERR "Task finished with $1 warning(s)!\n";
|
||||||
|
print $taskfh "\n$readbuf"; # ensure start on new line for webUI
|
||||||
} else {
|
} else {
|
||||||
die "got unexpected control message: $readbuf\n";
|
die "got unexpected control message: $readbuf\n";
|
||||||
}
|
}
|
||||||
@ -617,6 +622,9 @@ sub fork_worker {
|
|||||||
syslog('err', $err);
|
syslog('err', $err);
|
||||||
$msg = "TASK ERROR: $err\n";
|
$msg = "TASK ERROR: $err\n";
|
||||||
$exitcode = -1;
|
$exitcode = -1;
|
||||||
|
} elsif (my $warnings = $self->{warning_count}) {
|
||||||
|
$msg = "TASK WARNINGS: $warnings\n";
|
||||||
|
$exitcode = 0;
|
||||||
} else {
|
} else {
|
||||||
$msg = "TASK OK\n";
|
$msg = "TASK OK\n";
|
||||||
$exitcode = 0;
|
$exitcode = 0;
|
||||||
@ -703,6 +711,16 @@ sub fork_worker {
|
|||||||
return wantarray ? ($upid, $res) : $upid;
|
return wantarray ? ($upid, $res) : $upid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub warn {
|
||||||
|
my ($self, $message) = @_;
|
||||||
|
|
||||||
|
chomp($message);
|
||||||
|
|
||||||
|
print STDERR "WARN: $message\n";
|
||||||
|
|
||||||
|
$self->{warning_count}++;
|
||||||
|
}
|
||||||
|
|
||||||
# Abstract function
|
# Abstract function
|
||||||
|
|
||||||
sub log_cluster_msg {
|
sub log_cluster_msg {
|
||||||
|
@ -1156,6 +1156,8 @@ sub upid_read_status {
|
|||||||
return 'OK';
|
return 'OK';
|
||||||
} elsif ($line =~ m/^TASK ERROR: (.+)$/) {
|
} elsif ($line =~ m/^TASK ERROR: (.+)$/) {
|
||||||
return $1;
|
return $1;
|
||||||
|
} elsif ($line =~ m/^TASK (WARNINGS: \d+)$/) {
|
||||||
|
return $1;
|
||||||
} else {
|
} else {
|
||||||
return "unexpected status";
|
return "unexpected status";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user