[pbs-devel] [PATCH proxmox-backup v3] fix #4343: updated `view_task_result` to bail on task failure

Gabriel Goller g.goller at proxmox.com
Mon Sep 11 10:36:50 CEST 2023


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 at 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 at 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 at debian:~#
```
>> +        }
>> +
>>           Ok(())
>>       };
>
>
> _______________________________________________
> pbs-devel mailing list
> pbs-devel at lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
>
>





More information about the pbs-devel mailing list