From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com
Cc: Thomas Lamprecht <t.lamprecht@proxmox.com>
Subject: [pve-devel] [PATCH/RFC common 5/6] allow workers to count warnings and finish tasks in a WARNINGS state
Date: Fri, 12 Mar 2021 13:53:28 +0100 [thread overview]
Message-ID: <20210312125329.20918-6-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210312125329.20918-1-f.ebner@proxmox.com>
as is already supported by the UI (and PBS).
A nice bonus is that warn() can be used by both workers and non-workers, while
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.
Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
@Thomas: Hope this isn't too far from what you had in mind.
I'm not too familiar with task status related code, so hopefully I haven't
missed something important.
Also not sure if the newline should be included or not within warn().
src/PVE/RESTEnvironment.pm | 20 ++++++++++++++++++--
src/PVE/Tools.pm | 2 ++
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/PVE/RESTEnvironment.pm b/src/PVE/RESTEnvironment.pm
index d5b84d0..1bdcc34 100644
--- a/src/PVE/RESTEnvironment.pm
+++ b/src/PVE/RESTEnvironment.pm
@@ -115,7 +115,10 @@ sub init {
# priv ... access from private server (pvedaemon)
# ha ... access from HA resource manager agent (pve-ha-manager)
- my $self = { type => $type };
+ my $self = {
+ type => $type,
+ warning_count => 0,
+ };
bless $self, $class;
@@ -448,7 +451,6 @@ my $tee_worker = sub {
}
}
- # get status (error or OK)
POSIX::read($ctrlfd, $readbuf, 4096);
if ($readbuf =~ m/^TASK OK\n?$/) {
# skip printing to stdout
@@ -456,6 +458,9 @@ my $tee_worker = sub {
} elsif ($readbuf =~ m/^TASK ERROR: (.*)\n?$/) {
print STDERR "$1\n";
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 {
die "got unexpected control message: $readbuf\n";
}
@@ -617,6 +622,9 @@ sub fork_worker {
syslog('err', $err);
$msg = "TASK ERROR: $err\n";
$exitcode = -1;
+ } elsif (my $warnings = $self->{warning_count}) {
+ $msg = "TASK WARNINGS: $warnings\n";
+ $exitcode = 0;
} else {
$msg = "TASK OK\n";
$exitcode = 0;
@@ -703,6 +711,14 @@ sub fork_worker {
return wantarray ? ($upid, $res) : $upid;
}
+sub warn {
+ my ($self, $message) = @_;
+
+ print STDERR "WARN: $message\n";
+
+ $self->{warning_count}++;
+}
+
# Abstract function
sub log_cluster_msg {
diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index fc4a367..b087c39 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -1156,6 +1156,8 @@ sub upid_read_status {
return 'OK';
} elsif ($line =~ m/^TASK ERROR: (.+)$/) {
return $1;
+ } elsif ($line =~ m/^TASK (WARNINGS: \d+)$/) {
+ return $1;
} else {
return "unexpected status";
}
--
2.20.1
WARNING: multiple messages have this Message-ID
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com
Cc: Thomas Lamprecht <t.lamprecht@proxmox.com>
Subject: [pbs-devel] [PATCH/RFC common 5/6] allow workers to count warnings and finish tasks in a WARNINGS state
Date: Fri, 12 Mar 2021 13:53:28 +0100 [thread overview]
Message-ID: <20210312125329.20918-6-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210312125329.20918-1-f.ebner@proxmox.com>
as is already supported by the UI (and PBS).
A nice bonus is that warn() can be used by both workers and non-workers, while
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.
Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
@Thomas: Hope this isn't too far from what you had in mind.
I'm not too familiar with task status related code, so hopefully I haven't
missed something important.
Also not sure if the newline should be included or not within warn().
src/PVE/RESTEnvironment.pm | 20 ++++++++++++++++++--
src/PVE/Tools.pm | 2 ++
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/PVE/RESTEnvironment.pm b/src/PVE/RESTEnvironment.pm
index d5b84d0..1bdcc34 100644
--- a/src/PVE/RESTEnvironment.pm
+++ b/src/PVE/RESTEnvironment.pm
@@ -115,7 +115,10 @@ sub init {
# priv ... access from private server (pvedaemon)
# ha ... access from HA resource manager agent (pve-ha-manager)
- my $self = { type => $type };
+ my $self = {
+ type => $type,
+ warning_count => 0,
+ };
bless $self, $class;
@@ -448,7 +451,6 @@ my $tee_worker = sub {
}
}
- # get status (error or OK)
POSIX::read($ctrlfd, $readbuf, 4096);
if ($readbuf =~ m/^TASK OK\n?$/) {
# skip printing to stdout
@@ -456,6 +458,9 @@ my $tee_worker = sub {
} elsif ($readbuf =~ m/^TASK ERROR: (.*)\n?$/) {
print STDERR "$1\n";
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 {
die "got unexpected control message: $readbuf\n";
}
@@ -617,6 +622,9 @@ sub fork_worker {
syslog('err', $err);
$msg = "TASK ERROR: $err\n";
$exitcode = -1;
+ } elsif (my $warnings = $self->{warning_count}) {
+ $msg = "TASK WARNINGS: $warnings\n";
+ $exitcode = 0;
} else {
$msg = "TASK OK\n";
$exitcode = 0;
@@ -703,6 +711,14 @@ sub fork_worker {
return wantarray ? ($upid, $res) : $upid;
}
+sub warn {
+ my ($self, $message) = @_;
+
+ print STDERR "WARN: $message\n";
+
+ $self->{warning_count}++;
+}
+
# Abstract function
sub log_cluster_msg {
diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index fc4a367..b087c39 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -1156,6 +1156,8 @@ sub upid_read_status {
return 'OK';
} elsif ($line =~ m/^TASK ERROR: (.+)$/) {
return $1;
+ } elsif ($line =~ m/^TASK (WARNINGS: \d+)$/) {
+ return $1;
} else {
return "unexpected status";
}
--
2.20.1
next prev parent reply other threads:[~2021-03-12 12:54 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-12 12:53 [pve-devel] [PATCH-SERIES] improve warnings handling in UI and add to PVE Fabian Ebner
2021-03-12 12:53 ` [pbs-devel] " Fabian Ebner
2021-03-12 12:53 ` [pve-devel] [PATCH widget-toolkit 1/6] tasks: add warningsText Fabian Ebner
2021-03-12 12:53 ` [pbs-devel] " Fabian Ebner
2021-03-12 12:53 ` [pve-devel] [PATCH proxmox-backup 2/6] ui: tasks: use warningsText Fabian Ebner
2021-03-12 12:53 ` [pbs-devel] " Fabian Ebner
2021-03-12 12:53 ` [pve-devel] [PATCH manager 3/6] ui: cluster task log: eslint fixes Fabian Ebner
2021-03-12 12:53 ` [pbs-devel] " Fabian Ebner
2021-03-16 13:53 ` [pve-devel] applied: " Dominik Csapak
2021-03-16 13:53 ` [pbs-devel] " Dominik Csapak
2021-03-12 12:53 ` [pve-devel] [PATCH manager 4/6] ui: cluster task log: handle warnings like the node task log does Fabian Ebner
2021-03-12 12:53 ` [pbs-devel] " Fabian Ebner
2021-03-12 12:53 ` Fabian Ebner [this message]
2021-03-12 12:53 ` [pbs-devel] [PATCH/RFC common 5/6] allow workers to count warnings and finish tasks in a WARNINGS state Fabian Ebner
2021-03-12 12:53 ` [pve-devel] [PATCH/RFC container 6/6] restore: sanitize config: use new warn() function Fabian Ebner
2021-03-12 12:53 ` [pbs-devel] " Fabian Ebner
2021-03-16 14:02 ` [pve-devel] [pbs-devel] [PATCH-SERIES] improve warnings handling in UI and add to PVE Dominik Csapak
2021-03-16 14:02 ` Dominik Csapak
2021-03-17 8:33 ` [pve-devel] " Fabian Ebner
2021-03-17 8:33 ` Fabian Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210312125329.20918-6-f.ebner@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
--cc=pve-devel@lists.proxmox.com \
--cc=t.lamprecht@proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal