public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup v3] fix #4343: updated `view_task_result` to bail on task failure
@ 2023-09-08 13:32 Gabriel Goller
  2023-09-11  6:56 ` Maximiliano Sandoval
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Gabriel Goller @ 2023-09-08 13:32 UTC (permalink / raw)
  To: pbs-devel

Now we make an additional request on `api2/json/.../tasks/{upid}/status` to
get the `exitstatus` of the task. This allows us to `bail` and thus
get a non-zero exit code in the cli.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---

changes v2:
 - removed unrelated cleanup

changes v1:
 - check on each iteration if the task is finished, then bubble up the 
   original error of the task. This was inpractical though, so we print
   the error and return a generic error.

 pbs-client/src/task_log.rs | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/pbs-client/src/task_log.rs b/pbs-client/src/task_log.rs
index 0bbb928d..709d0d08 100644
--- a/pbs-client/src/task_log.rs
+++ b/pbs-client/src/task_log.rs
@@ -96,6 +96,14 @@ pub async fn display_task_log(
             }
         }
 
+        let status_path = format!("api2/json/nodes/localhost/tasks/{upid_encoded}/status");
+        let status_result = client.get(&status_path, None).await?;
+        if status_result["data"]["status"].as_str() == Some("stopped")
+            && status_result["data"]["exitstatus"].as_str() != Some("OK")
+        {
+            bail!("task failed");
+        }
+
         Ok(())
     };
 
-- 
2.39.2





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup v3] fix #4343: updated `view_task_result` to bail on task failure
  2023-09-08 13:32 [pbs-devel] [PATCH proxmox-backup v3] fix #4343: updated `view_task_result` to bail on task failure Gabriel Goller
@ 2023-09-11  6:56 ` Maximiliano Sandoval
  2023-09-11  8:36   ` Gabriel Goller
  2023-09-18 14:40 ` [pbs-devel] applied: " Thomas Lamprecht
  2023-09-27 14:38 ` [pbs-devel] " Thomas Lamprecht
  2 siblings, 1 reply; 6+ messages in thread
From: Maximiliano Sandoval @ 2023-09-11  6:56 UTC (permalink / raw)
  To: pbs-devel


On 9/8/23 15:32, Gabriel Goller wrote:
> Now we make an additional request on `api2/json/.../tasks/{upid}/status` to
> get the `exitstatus` of the task. This allows us to `bail` and thus
> get a non-zero exit code in the cli.
>
> Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
> ---
>
> changes v2:
>   - removed unrelated cleanup
>
> changes v1:
>   - check on each iteration if the task is finished, then bubble up the
>     original error of the task. This was inpractical though, so we print
>     the error and return a generic error.
>
>   pbs-client/src/task_log.rs | 8 ++++++++
>   1 file changed, 8 insertions(+)
>
> diff --git a/pbs-client/src/task_log.rs b/pbs-client/src/task_log.rs
> index 0bbb928d..709d0d08 100644
> --- a/pbs-client/src/task_log.rs
> +++ b/pbs-client/src/task_log.rs
> @@ -96,6 +96,14 @@ pub async fn display_task_log(
>               }
>           }
>   
> +        let status_path = format!("api2/json/nodes/localhost/tasks/{upid_encoded}/status");
> +        let status_result = client.get(&status_path, None).await?;
> +        if status_result["data"]["status"].as_str() == Some("stopped")
> +            && status_result["data"]["exitstatus"].as_str() != Some("OK")
> +        {
> +            bail!("task failed");
The info about the exit status is not propagated, maybe one could display it too?
> +        }
> +
>           Ok(())
>       };
>   




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup v3] fix #4343: updated `view_task_result` to bail on task failure
  2023-09-11  6:56 ` Maximiliano Sandoval
@ 2023-09-11  8:36   ` Gabriel Goller
  0 siblings, 0 replies; 6+ messages in thread
From: Gabriel Goller @ 2023-09-11  8:36 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Maximiliano Sandoval

On 9/11/23 08:56, Maximiliano Sandoval wrote:

>
> On 9/8/23 15:32, Gabriel Goller wrote:
>> Now we make an additional request on 
>> `api2/json/.../tasks/{upid}/status` to
>> get the `exitstatus` of the task. This allows us to `bail` and thus
>> get a non-zero exit code in the cli.
>>
>> Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
>> ---
>>
>> changes v2:
>>   - removed unrelated cleanup
>>
>> changes v1:
>>   - check on each iteration if the task is finished, then bubble up the
>>     original error of the task. This was inpractical though, so we print
>>     the error and return a generic error.
>>
>>   pbs-client/src/task_log.rs | 8 ++++++++
>>   1 file changed, 8 insertions(+)
>>
>> diff --git a/pbs-client/src/task_log.rs b/pbs-client/src/task_log.rs
>> index 0bbb928d..709d0d08 100644
>> --- a/pbs-client/src/task_log.rs
>> +++ b/pbs-client/src/task_log.rs
>> @@ -96,6 +96,14 @@ pub async fn display_task_log(
>>               }
>>           }
>>   +        let status_path = 
>> format!("api2/json/nodes/localhost/tasks/{upid_encoded}/status");
>> +        let status_result = client.get(&status_path, None).await?;
>> +        if status_result["data"]["status"].as_str() == Some("stopped")
>> +            && status_result["data"]["exitstatus"].as_str() != 
>> Some("OK")
>> +        {
>> +            bail!("task failed");
> The info about the exit status is not propagated, maybe one could 
> display it too?
Then the error would be duplicated on the console. We already print the 
whole task log,
which includes the error. Including the error in `bail` would produce an 
output simillar to this:
```
root@debian:~# PBS_LOG=info proxmox-backup-manager pull 18.201 test1 test1
pull datastore 'test1' from '18.201/test1'
TASK ERROR: Querying namespaces failed - HTTP error 400 Bad Request - no 
such datastore 'test1'
Error: Querying namespaces failed - HTTP error 400 Bad Request - no such 
datastore 'test1'
root@debian:~#
```
>> +        }
>> +
>>           Ok(())
>>       };
>
>
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
>
>




^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pbs-devel] applied: [PATCH proxmox-backup v3] fix #4343: updated `view_task_result` to bail on task failure
  2023-09-08 13:32 [pbs-devel] [PATCH proxmox-backup v3] fix #4343: updated `view_task_result` to bail on task failure Gabriel Goller
  2023-09-11  6:56 ` Maximiliano Sandoval
@ 2023-09-18 14:40 ` Thomas Lamprecht
  2023-09-27 14:38 ` [pbs-devel] " Thomas Lamprecht
  2 siblings, 0 replies; 6+ messages in thread
From: Thomas Lamprecht @ 2023-09-18 14:40 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Gabriel Goller

Am 08/09/2023 um 15:32 schrieb Gabriel Goller:
> Now we make an additional request on `api2/json/.../tasks/{upid}/status` to
> get the `exitstatus` of the task. This allows us to `bail` and thus
> get a non-zero exit code in the cli.
> 
> Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
> ---
> 
> changes v2:
>  - removed unrelated cleanup
> 
> changes v1:
>  - check on each iteration if the task is finished, then bubble up the 
>    original error of the task. This was inpractical though, so we print
>    the error and return a generic error.
> 
>  pbs-client/src/task_log.rs | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
>

applied, thanks!




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup v3] fix #4343: updated `view_task_result` to bail on task failure
  2023-09-08 13:32 [pbs-devel] [PATCH proxmox-backup v3] fix #4343: updated `view_task_result` to bail on task failure Gabriel Goller
  2023-09-11  6:56 ` Maximiliano Sandoval
  2023-09-18 14:40 ` [pbs-devel] applied: " Thomas Lamprecht
@ 2023-09-27 14:38 ` Thomas Lamprecht
  2023-09-27 15:32   ` Gabriel Goller
  2 siblings, 1 reply; 6+ messages in thread
From: Thomas Lamprecht @ 2023-09-27 14:38 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Gabriel Goller

Am 08/09/2023 um 15:32 schrieb Gabriel Goller:
> Now we make an additional request on `api2/json/.../tasks/{upid}/status` to
> get the `exitstatus` of the task. This allows us to `bail` and thus
> get a non-zero exit code in the cli.

> index 0bbb928d..709d0d08 100644
> --- a/pbs-client/src/task_log.rs
> +++ b/pbs-client/src/task_log.rs
> @@ -96,6 +96,14 @@ pub async fn display_task_log(
>              }
>          }
>  
> +        let status_path = format!("api2/json/nodes/localhost/tasks/{upid_encoded}/status");
> +        let status_result = client.get(&status_path, None).await?;
> +        if status_result["data"]["status"].as_str() == Some("stopped")
> +            && status_result["data"]["exitstatus"].as_str() != Some("OK")
> +        {
> +            bail!("task failed");

Hmm, while writing the changelog for a next bump I noticed that this
will now also exit with a failure-code when there are "only" warnings.

Did you think about that case?

Should we at least exit with different codes? I.e., so that tooling can
differentiate between error, meaning complete failure, and warnings,
meaning task probably did its main job, but something (recoverable) was
off.

IMO one could also argue that it would be sensible to exit with SUCCESS
(0) even on warnings, as after all warnings should be only returned if
the main job of the task was still successful, but, e.g., some
deprecated config option was set or the like.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup v3] fix #4343: updated `view_task_result` to bail on task failure
  2023-09-27 14:38 ` [pbs-devel] " Thomas Lamprecht
@ 2023-09-27 15:32   ` Gabriel Goller
  0 siblings, 0 replies; 6+ messages in thread
From: Gabriel Goller @ 2023-09-27 15:32 UTC (permalink / raw)
  To: Thomas Lamprecht, Proxmox Backup Server development discussion


On 9/27/23 16:38, Thomas Lamprecht wrote:
> Am 08/09/2023 um 15:32 schrieb Gabriel Goller:
>> Now we make an additional request on `api2/json/.../tasks/{upid}/status` to
>> get the `exitstatus` of the task. This allows us to `bail` and thus
>> get a non-zero exit code in the cli.
>> index 0bbb928d..709d0d08 100644
>> --- a/pbs-client/src/task_log.rs
>> +++ b/pbs-client/src/task_log.rs
>> @@ -96,6 +96,14 @@ pub async fn display_task_log(
>>               }
>>           }
>>   
>> +        let status_path = format!("api2/json/nodes/localhost/tasks/{upid_encoded}/status");
>> +        let status_result = client.get(&status_path, None).await?;
>> +        if status_result["data"]["status"].as_str() == Some("stopped")
>> +            && status_result["data"]["exitstatus"].as_str() != Some("OK")
>> +        {
>> +            bail!("task failed");
> Hmm, while writing the changelog for a next bump I noticed that this
> will now also exit with a failure-code when there are "only" warnings.
>
> Did you think about that case?
>
> Should we at least exit with different codes? I.e., so that tooling can
> differentiate between error, meaning complete failure, and warnings,
> meaning task probably did its main job, but something (recoverable) was
> off.
>
> IMO one could also argue that it would be sensible to exit with SUCCESS
> (0) even on warnings, as after all warnings should be only returned if
> the main job of the task was still successful, but, e.g., some
> deprecated config option was set or the like.
Yes, submitting a new patch. Now we use exit code 0 (SUCCESS)
on warnings as well.




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-09-27 15:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-08 13:32 [pbs-devel] [PATCH proxmox-backup v3] fix #4343: updated `view_task_result` to bail on task failure Gabriel Goller
2023-09-11  6:56 ` Maximiliano Sandoval
2023-09-11  8:36   ` Gabriel Goller
2023-09-18 14:40 ` [pbs-devel] applied: " Thomas Lamprecht
2023-09-27 14:38 ` [pbs-devel] " Thomas Lamprecht
2023-09-27 15:32   ` Gabriel Goller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal