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

Method GetGroupTasks

pkg/api/grouped-cluster.go:459–505  ·  view source on GitHub ↗

GetGroupTasks retrieves tasks from all connected profiles in the group. Each task's SourceProfile field is set to identify which profile it came from. Returns a combined list of all tasks across all profiles.

(ctx context.Context)

Source from the content-addressed store, hash-verified

457// Each task's SourceProfile field is set to identify which profile it came from.
458// Returns a combined list of all tasks across all profiles.
459func (m *GroupClientManager) GetGroupTasks(ctx context.Context) ([]*ClusterTask, error) {
460 operation := func(profileName string, client *Client) (interface{}, error) {
461 tasks, err := client.GetClusterTasks()
462 if err != nil {
463 return nil, fmt.Errorf("failed to get cluster tasks: %w", err)
464 }
465
466 // Set SourceProfile for each task
467 for _, task := range tasks {
468 task.SourceProfile = profileName
469 }
470
471 return tasks, nil
472 }
473
474 groupFunc := func(results []ProfileResult) (interface{}, error) {
475 var allTasks []*ClusterTask
476
477 for _, result := range results {
478 if tasks, ok := result.Data.([]*ClusterTask); ok {
479 allTasks = append(allTasks, tasks...)
480 }
481 }
482
483 // Sort tasks by StartTime desc
484 sort.Slice(allTasks, func(i, j int) bool {
485 if allTasks[i] == nil || allTasks[j] == nil {
486 return allTasks[i] != nil
487 }
488 return allTasks[i].StartTime > allTasks[j].StartTime
489 })
490
491 return allTasks, nil
492 }
493
494 data, err := m.GetGroupData(ctx, operation, groupFunc)
495 if err != nil {
496 return nil, err
497 }
498
499 tasks, ok := data.([]*ClusterTask)
500 if !ok {
501 return nil, fmt.Errorf("unexpected data type returned from grouping")
502 }
503
504 return tasks, nil
505}

Callers 3

getTasksMethod · 0.80
loadTasksDataMethod · 0.80
autoRefreshDataMethod · 0.80

Calls 2

GetGroupDataMethod · 0.95
GetClusterTasksMethod · 0.80

Tested by

no test coverage detected