MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / waitForTask

Function waitForTask

internal/cli/cli_helpers.go:603–627  ·  view source on GitHub ↗

waitForTask polls a Proxmox task to completion using the existing WaitForTaskCompletion method and returns the final exit status string. It respects ctx cancellation (e.g. Ctrl-C).

(ctx context.Context, client *api.Client, node, upid, operationName string)

Source from the content-addressed store, hash-verified

601// WaitForTaskCompletion method and returns the final exit status string.
602// It respects ctx cancellation (e.g. Ctrl-C).
603func waitForTask(ctx context.Context, client *api.Client, node, upid, operationName string) (exitStatus string, err error) {
604 const defaultTimeout = 10 * time.Minute
605
606 done := make(chan error, 1)
607 go func() {
608 done <- client.WaitForTaskCompletion(upid, operationName, defaultTimeout)
609 }()
610
611 select {
612 case <-ctx.Done():
613 return "", fmt.Errorf("%s cancelled", operationName)
614 case err = <-done:
615 if err != nil {
616 return "ERROR", err
617 }
618 }
619
620 // Fetch final status for structured output.
621 status, fetchErr := client.GetTaskStatus(node, upid)
622 if fetchErr != nil || status == nil {
623 return "OK", nil
624 }
625
626 return status.ExitStatus, nil
627}
628
629// inferGuestTypeFromVolID returns "qemu" or "lxc" based on the vzdump volid prefix.
630func inferGuestTypeFromVolID(volID string) (string, error) {

Callers 12

runStorageContentDeleteFunction · 0.85
runStorageDownloadURLFunction · 0.85
runStorageDownloadOCIFunction · 0.85
runStorageRestoreFunction · 0.85
TestWaitForTaskSuccessFunction · 0.85
TestWaitForTaskFailureFunction · 0.85
TestWaitForTaskCancelledFunction · 0.85
runGuestsDeleteFunction · 0.85
runGuestsCreateVMFunction · 0.85
runGuestsCreateLXCFunction · 0.85
runGuestsMigrateFunction · 0.85

Calls 2

WaitForTaskCompletionMethod · 0.80
GetTaskStatusMethod · 0.80

Tested by 3

TestWaitForTaskSuccessFunction · 0.68
TestWaitForTaskFailureFunction · 0.68
TestWaitForTaskCancelledFunction · 0.68