Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-cli/pkg/supervisor/status-tasks.go
2500 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package supervisor
6
7
import (
8
"context"
9
10
"github.com/gitpod-io/gitpod/supervisor/api"
11
"golang.org/x/xerrors"
12
)
13
14
func (client *SupervisorClient) GetTasksList(ctx context.Context) ([]*api.TaskStatus, error) {
15
respClient, err := client.Status.TasksStatus(ctx, &api.TasksStatusRequest{Observe: false})
16
if err != nil {
17
return nil, xerrors.Errorf("failed get tasks status client: %w", err)
18
}
19
resp, err := respClient.Recv()
20
if err != nil {
21
return nil, xerrors.Errorf("failed receive data: %w", err)
22
}
23
return resp.GetTasks(), nil
24
}
25
26
func (client *SupervisorClient) GetTasksListByState(ctx context.Context, filterState api.TaskState) ([]*api.TaskStatus, error) {
27
tasks, err := client.GetTasksList(ctx)
28
if err != nil {
29
return nil, err
30
}
31
var filteredTasks []*api.TaskStatus
32
for _, task := range tasks {
33
if task.State == filterState {
34
filteredTasks = append(filteredTasks, task)
35
}
36
}
37
return filteredTasks, nil
38
}
39
40