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

Method GetTaskStatus

pkg/api/cluster.go:524–565  ·  view source on GitHub ↗

GetTaskStatus retrieves the status of a specific task.

(node, upid string)

Source from the content-addressed store, hash-verified

522
523// GetTaskStatus retrieves the status of a specific task.
524func (c *Client) GetTaskStatus(node, upid string) (*TaskStatus, error) {
525 // Escape the UPID as it contains special characters
526 path := fmt.Sprintf("/nodes/%s/tasks/%s/status", node, url.PathEscape(upid))
527
528 var result map[string]interface{}
529 if err := c.Get(path, &result); err != nil {
530 return nil, fmt.Errorf("failed to get task status: %w", err)
531 }
532
533 data, ok := result["data"].(map[string]interface{})
534 if !ok {
535 return nil, fmt.Errorf("unexpected format for task status data")
536 }
537
538 task := &TaskStatus{
539 Status: getString(data, "status"),
540 ExitStatus: getString(data, "exitstatus"),
541 Node: node,
542 UPID: upid,
543 Type: getString(data, "type"),
544 User: getString(data, "user"),
545 ID: getString(data, "id"),
546 }
547
548 if startTime, ok := data["starttime"].(float64); ok {
549 task.StartTime = int64(startTime)
550 }
551
552 if endTime, ok := data["endtime"].(float64); ok {
553 task.EndTime = int64(endTime)
554 }
555
556 if pstart, ok := data["pstart"].(float64); ok {
557 task.PStart = int64(pstart)
558 }
559
560 if pid, ok := data["pid"].(float64); ok {
561 task.PID = int(pid)
562 }
563
564 return task, nil
565}
566
567// StopTask attempts to stop/cancel a running task.
568func (c *Client) StopTask(node, upid string) error {

Callers 3

waitForTaskFunction · 0.80
monitorMethod · 0.80
runTaskMethod · 0.80

Calls 2

GetMethod · 0.95
getStringFunction · 0.85

Tested by

no test coverage detected